Hacker News new | ask | show | jobs
by tomjakubowski 784 days ago
Strict adherence to formatting rules can impair readability, yes.

Before back-tick strings in JS, it was useful to employ both single/double quotes for strings -- you'd use one most of the time, and then if you needed to embed a bunch of that quotation mark in a string literal, you'd switch to the other one.

    'my string'
    'my other string'
    "insert values ('foo', 'bar', 'baaz')"
A formatter with naive "single quotes only" rule would obliterate the last one to:

    'insert values (\'foo\', \'bar\', \'baz\')'
unless you remember, before you hit save, to add a directive like:

    // linter pwease preserve my qwotes
I still use linters and formatters every day, and on balance I think they're good to have, but it's ridiculous to pretend they don't have downsides, or that there isn't room for the occasional dash of human intervention in the automation; hence, the linters which have // linter pwease directives.
1 comments

The key point here is that the formatter has to be sufficiently advanced to know to do the right thing the vast majority of the time. Once it gets there, and once you've gotten used to the code it produces, it's better. Note that the "prettier" formatter will do the right thing in JS here, at least with the default config. It will even switch "\"string\"" to '"string"' for you.

Linting is a bit of a different beast, because linting includes changes to the code behavior itself, not just syntax. In JS there are so many footguns, that linting can often be pretty involved/strict. I think most of the people who don't like linting in JS either aren't aware of the footguns, or don't do very much code review and haven't worried themselves much with "what sort of bizare and unusual ways can this fail" sort of a thing.