After 3 Months Of JavaScript Linting, It's Pretty Much All Pain And No Gain

Up until about 3 months ago, I had never used a linter. When we started InVision App, we played around with a coding style-guide; but, we quickly found out that no one stuck to it; and, frankly, we didn't have time to worry about it - we were just trying to get product out the door. Three months ago, I joined an internal team that uses the JavaScript linting library, Standard.js. After three months of trying to adjust to it, linting feels very much like it's all pain and no gain - a negative-sum scenario. And, the more code that I read through, the more I realize that the goal of consistency is a complete charade.

I want to say right up front that static-analysis of code is a good thing. It can help find bugs before you deploy code, through features like unused variable and dead code detection. That stuff is awesome, no doubt. When I talk about "linting", I am not talking about those features - I am talking solely about stylistic rules. Tabs vs. Spaces. Const vs. Let. Single quotes vs. Double quotes - that sort of thing.

That said, my approach to code formatting is the best. If it weren't, I wouldn't use it. Formatting is part of my being - an extension of my genetic makeup. And, when I write code, my formatting is the fingerprint that I leave behind. When I'm asked to change my style, I am - quite literally - asked to deny a fundamental Truth of my being.























My coding style wasn't perfect on day one. And, twenty years later, it's still not perfect. But, today does represent the best that I've been able to come up with so far. And, as time goes on and I collect more evidence and experiment with new choices, my approach to code formatting will continue to evolve and become more refined.

Hopefully, you feel as passionately as I do about your own stylistic choices. My approach works best for me; but, it's not for everyone. And, clearly, other people's choices don't thrill me. It's a completely subjective matter.

NOTE: Years ago, I was naive enough to try and make an objective case for my design choices - I even used science. But, today, I now realize that, while there is some validity to my argument, personal preference is ultimately the source of Truth on such topics.

Trying to get people to leave their own approach - to give-up their own identity - and adhere to an arbitrary standard is painful. And, from everything that I can see, there's no real value in it. Because, the choices that can be controlled by a linter are, ultimately, not the choices that matter. The architecture of an application and the structure of its algorithms are what make an application readable, maintainable, and extensible. And, even on a team that uses linting, you will find wildly different choices being made by every engineer on this front.























The reality is, linting doesn't make it easier to read and understand other people's code because code is so much more than indentation and quotation choices. It is art. And it is science. And, it's already hard enough. There's no need to make it harder by adding an additional layer of friction to the landscape of problem solving. Engineers are peacocks - you have to let them fly!























Epilogue On Auto-Fixing Features

I am sure that many linting libraries, including Standard.js, come with utilities that allow you to auto-fix code. Meaning, convert your personal coding style to the one enforced by the team linter. This is not a solution. If anything, this is just more evidence of the absurdity of linting - that we have to create tooling so that our engineers don't have to feel the pain of linting as they work. If you're using an auto-fixing utility, I strongly urge you to step back and question what value you think it's adding to your project.

Epilogue On Copy-Pasta

I once heard the argument that linters make it easier to copy-and-paste code from one file into another. This argument defeats itself. Not only is copying-and-pasting a potential indication that said code should be factored out into a new concept; but, if you copy-and-paste code and you don't take the time to test it and assimilate it, that's not a linting problem, that's an awareness problem.

Tweet This Interesting post by @BenNadel - After 3 Months Of JavaScript Linting, It's Pretty Much All Pain And No Gain Woot woot — you rock the party that rocks the body!







