Hacker News new | ask | show | jobs
by twerquie 4116 days ago
This is starting to pick up steam in the node community, and represents the coding style of a vast percentage of core and popular npm modules: https://github.com/feross/standard

It's not configurable, is a drop-in executable tool and supports a --format option which will attempt to reformat your code. To me it seems to be inspired by gofmt.

2 comments

Looks pretty cool, but it supports a very limited set of styles. It's not really comparable to rubocop, nor is it able to enforce conformance to any of the popular style guides in full. In fact, at a glance it appears to make decisions about your code that fly in the face of many of the popular style guides (double spaces for indentation and no freaking semicolons [seriously?]).

The auto-formatting option does not clarify which of these it enforces, and one of these isn't even a style rule (always handle the err parameter in node.js).

To really rub it in, it also makes it very clear that there is no configuration! Deal with it in a way that strikes me as uncomfortably smug.

I appreciate you sharing, and I could see this being useful for running over a codebase. I might use it to convert all tabs to double spaces (since that's my preference anyway) and check to make sure there are no unused declared variables, but that might be the extent of it. But to be honest, reading the documentation here has made me really want to see a community-developed tool inspired by Rubocop.

That there is no configuration is kind of the point. Close the door on the bike shed and attempt to popularize a conventional style.

If you want more control, use ESlint or jslint or jshint and define your own rules.

The problem is this is incompatible with the current state of the JS ecosystem. NPM packages need to follow the npm style guide (though standard appears at a glance to be closer to this than anything else). jQuery modules need to follow the jQuery style guide. Many projects may already use another style guide. A large chunk of open-source javascript follows a style guide that standard is incompatible with, and new projects often have to adhere to the style guide of the platform they target as well. It would be much more useful to have a code analysis and correction tool that could enforce the rules of a target style guide.
Looks cool except for the no semi colons thing. The first time I spend fifteen minutes searching for why this weird bug was happening only to realize it was because of ASI, that shit is going in the trash.
Apparently it will catch the edge cases for you.

https://github.com/feross/standard/issues/5#issuecomment-716...

The style is best suited to server-side code where source minification is not an issue and you can enjoy the full language.