StandardJS just turned 10.0.0
standardjs.com
standardjs.com
there are lots of new rules in 10.0.0 designed to help catch bugs and make programmer intent more explicit.
Then in the FAQ it says Can I use a JavaScript language variant, like Flow?
Before using a custom JS language variant, consider whether the added complexity (and effort required to get new contributors up-to-speed) is worth it.
The goal of variants like Flow is to catch bugs and make intent more explicit! We have to consider if it's worth training up new contributors on this, but we don't have to consider the contributor cost to learn all of feross's personal JS style preferences and API opinions?I get the goal of having a uniform style - that's important and valuable, even though StandardJS's decisions don't match the style predominant in the JS community. But it seems like there's been a lot of scope creep here where now there are specific rules for specific APIs and other stuff that is well outside the domain of "Let's all format our code the same".
I find it particularly ironic that there's a reasonably popular fork called semistandard. [1]
In all seriousness though, I'd really love to see the JS community move towards tools like prettier[2] instead of continuously trying to establish "one eslint config to rule them all". I just want each repo I work with to configure my editor for me and reformat stuff automatically (a la gofmt) so I can forget about it. Even if some of the particular style decisions are ones that I personally don't agree with, it doesn't matter — the value of having those decisions abstracted away from me in the first place is significant enough that any minor quibbles fade away pretty quickly. Then I can focus on writing and reading code, not on arguing about whether we should enforce or disallow dangling commas in our lint config.
So... Standard?
I use Prettier and pipe the output my own eslint file. Could do the same but Prettier | Standard. Or Semistandard. Or whatever.
The issue is the community largely values their personal styles (ignoring choice of semicolon omission) too much to standardize on "one style to rule them all". Because everyone (including myself) "I like this except these two little things" and everyone's two little things are different so you end up with 200 different lint configs each mostly similar but with their own little tweaks.
Not that I think golang got it exactly right either, but because the style guide was essentially built into the language from the start, the change process is necessarily slower and more intentional, and I think that's a good thing.
The way I interpret this: some group of developers thought it would be a good idea to hijack the word "standard," and wedge this particular new style into the concept. It just isn't standard. It's as absurd as having a company called "Blue Shine" and selling only green colored cleaning products.
At least be honest about it. Call it something else, like "Colonless," since that's the most obvious thing that sticks out when using this style.
reminds me of the debacle around "Standard Markdown", now called "CommonMark"
The parts that I don't like the most are 2 spaces for indentation (why so small? who else is using such small indentation?) and "no semicolons" rule.
It would be better to adopt some style guide from Java, because JS has similar syntax and because Java has been in use in large projects for a long time.
Beyond that, there are no advantages. It's just a decent eslint config that requires you to omit semicolons wherever possible. If that's important to you, use it. If it's not important, or you'd rather not omit semicolons, or if you do want to omit semicolons but you're happy making a one line change to the airbnb preset, then there's nothing to set this apart from more, if you'll pardon the expression, "standard" options. :)
I think airbnb is a really good base for a project.
Last I used it Prettier it was very opinionated, but I think you can override it with ESLint rules now which you could use StandardJS to do without needing to write your own.
Standard is a linter (ESLint) configuration and frontend. It doesn't correct errors, just checks for them. It goes beyond style to actually check for logical errors (usage of deprecated APIs, invalid regexps, etc).
In theory, you can run the two together. Ideally, you'd use plain ESLint with a config geared around catching programming errors, and leave Prettier for just styling concerns.
Very good reviews, but it doesn't achieve the grandiose things it claims to achieve.
While consistent indentation is important, a coding standard is much more than that. I consider this to be an actual standard:
https://google.github.io/styleguide/jsguide.html
For example Python enforces consistent indentation, but you know that there is still a lot of room to create a mess even with those restrictions.
StandardJS was designed to maximize adoption, not to ensure actual quality:
- Want a 1,000 characters long line of code? StandardJS badge of approval.
- Want a 10,000 lines of code function? StandardJS badge of approval.
- Want a function with a cyclomatic complexity of 10,000? StandardJS badge of approval.
Those are very basic measures of code quality and StandardJS does not have an actual position about them.
Then... StandardJS actually goes against good practices. Omitting semicolons actually has an effect in JavaScript, and there are many examples of that. The Google JavaScript coding standard advises specifically against it for good reasons. Remember that Google created v8, and has a lot more authority in this matter than whoever created StandardJS.
ESLint can enforce a cyclomatic complexity limit, number of statements per function, lines per file, etc.
What I like about StandardJS is that I don't need yet another config file just for a linter. lintrc, babelrc, webpack.config.js, karma.config.js, etc, etc. Having one less thing for people to need to understand is a nice feature in and of itself IMO.
And I actually tended to disagree with some of the StandardJS choices before adopting it. After working with it for a few weeks, I realize it makes absolutely no difference. I just have a linter that works with no config.
An excessively long function, statement or a complex function is a liability because it almost certainly cannot be tested or reasoned about. And all the negative consequences of not being able to test or verify code.
I just gave Standard a try for the first time, kinda surprised I'd never seen it til now. Anyway, it seems to also check for those semi-colon gotchas. If I try to use no-semicolons incorrectly, it catches my mistake. (I tried by putting the return value on the next line)
Usually good standards can be assimilated and make you code in a safer way, even if not enforced by a tool.
You could argue that a script, version control hook or continuous integration script can take care of it, but those are lines of defense that can go away in certain circumstances and you are unnecessarily raising your odds for an incident.
Sometimes people add a block comment to disable linting, and if you were relying on your linter to provide the fix to allow your bad habit of not using semicolons, then you are on your own.
So, it's neat in the config-less way, but I won't be using it. (there is a semicolon version by the way https://github.com/Flet/semistandard )
If StandardJS was a standard for dating, its only filter would be that your potential date is alive and is a mammal. Use that Standard and you will have a lot of potential dates! such a great standard.
I touch on this in my other comment, but it's entirely possible to forget a semicolon and break things no matter which style you prefer. Both semi:always and semi:never+no-unexpected-multiline enforce good standards which can be assimilated; like spaces vs tabs, they're just different standards that people tend to develop very strong opinions about.
ESLint provides--and StandardJS uses--the `no-unexpected-multiline` rule, which will insist that you insert semicolons in places where the meaning would otherwise be unexpected. In practice, with `semi` set to never and `no-unexpected-multiline` enabled, I find that I have never had a problem with semicolons that was not caught by the linter. By contrast, when I was afraid of ASI (since "omitting semicolons actually has an effect", eek!) I would find that I'd occasionally have mysterious issues where arrays were interpreted as indexes and so on. (I switched to semicolonless-style at the same time as I started using a linter, so I can't compare the two independently.)
My standard of car safety relies on that each time you crash your car, a red light will flash telling you that you have crashed your car. It is very effective detecting car crashes, therefore, very safe.
Maybe this makes more sense in a codebase where there's a variety of contributors of differing skill levels. I'm interested to hear about how other people use measures of complexity and function size.
https://en.wikipedia.org/wiki/Sorites_paradox
Eventually you will have to commit to an arbitrary value, and stick to it.
But there are cases in which it's no longer subjective if cyclomatic complexity is bad. If you have a 500 lines of code function with 50 return points and cyclomatic complexity of 100 it is very clear there is no way you can maintain that or write a unit test for it without playing Russian roulette each time you check in a change and therefore you can objectively say that code is not safe and should not be allowed.
Seems like a silly conclusion
Except that 'punctuation' in JavaScript comes in the form of a line break, and adding a semicolon is like adding two periods to the end of every sentence just in case someone missed the first one.
This sort of writing generally leaves off periods on the ends of sentences
sometimes, it even leaves off the capitalization at the beginning, as well
and yet it manages to be entirely readable and generally unambiguous
This is remarkably similar to js's automatic semicolon insertion:
if the sentence makes more sense with a period at the end of the line
then the reader usually inserts one automatically, without thinking about it
JS is not a language like Ruby or Python.
If someone doesn't like typing semicolons why don't they set up their editor so that it would insert them automatically?
JS will add the semicolons. If you're using Babel and the rest you most likely are not going to run into all the weird things to do with semi-colons as long as you follow K&R C style for control statements.
But if you want it to, go ahead. What matters, in the end, is consistency to make it look pretty. The more it looks like a single very smart person wrote it the better.