Writing Your Personal Code Guidelines
There comes a time on a challenge when it’s value investing in tooling to guard the codebase. I’m unsure methods to articulate when, but it surely’s someplace after the challenge has confirmed to be one thing long-term and tough edges are beginning to present, and earlier than issues really feel like a whole mess. Keep away from untimely optimization however keep away from, uh, postmature optimization.
A few of this tooling is very easy to implement, it’s typically completed proper up-front. I consider Prettier right here, a code formatter that retains your code in form, often proper as you’re coding. There are entire suites of instruments you’ll be able to put in that “as-you-are-coding” bucket, like accessibility linting, compatibility linting, safety linting, and many others. Webhint bundles a bunch of these collectively and might be value a glance.
Then there’s tooling that protects your code through extra code that you have to jot down. Tests are the large participant right here, which may even be set as much as run as you code. They’re about ensuring your code does what it’s meant to do, and as such, ship a hell of quite a lot of worth.
Defending your code with extra code that you simply write is the place I needed to go together with this, not with conventional exams, however with customized linting guidelines. I thought of it as two completely different posts about customized linting crossed my desk not too long ago:
- “How to write a custom ESLint rule” by Benedict Quinn
- “Custom Stylelint Rules — Writing Your First one” by Omri Lavi
I used to be as a person of each ESLint and Stylelint in my primary codebase. However honest warning, I discovered the method for writing customized guidelines in each of these fairly troublesome. You gotta know you approach round an Summary Syntax Tree. It’s nothing like if (guidelines.discover.selector.startsWith("previous")) throw("Deprecated selector.")
or one thing straightforward like that.
I discovered this all associated to an attention-grabbing query that got here my approach:
I work on a development staff engaged on an previous challenge, and we wish to get of rid a lot of our oldest and buggiest CSS selectors. For instance, one in every of us would possibly open a HTML file and see a component with a category title of
deprecated-selector
, our purpose is to have our IDE actually mark it as a linting error and say like “This can be a deprecated selector, use.ui-fresh__selector
as an alternative”.
The very first thing I considered was a customized Stylelint guidelines that may search for selectors that your staff is aware of to be deprecated and warn you. However sadly, Stylelint is for linting CSS and it seems like the primary problem right here is HTML. I do know html-inspector had a way to write your own rules, but it surely’s getting a bit lengthy within the tooth so I don’t know if there’s success to be discovered there or not.
Checkout extra Articles on Sayed.CYou
Comments
Post a Comment