RuboCop – A Ruby static code analyzer
batsov.com
batsov.com
It would be amazing if a similar static code analysis tool existed with settings to conform to the most popular javascript style guides: npm, idiomatic, jQuery, etc. But even within these style guides there is a lot of 'undefined behavior', or situations that aren't explicitly described in the guides.
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.
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.
If you want more control, use ESlint or jslint or jshint and define your own rules.
https://github.com/feross/standard/issues/5#issuecomment-716...
Submitters: HN prefers original sources. https://news.ycombinator.com/newsguidelines.html
The attention to detail is incredible, which I'm not sure if I like or not, since it usually feels like I have someone nitpicking about the style of my quick scripts.
I've been learning a lot about ruby standards though.
https://www.freebsd.org/cgi/man.cgi?query=lint&sektion=1
I've always been a big fan of code linters. They may not be perfect, but any bug you can catch at compile-time (or earlier) could be saving you hours of trying to track down runtime problems. In languages with a managed runtime such as ruby where you don't really have the same kind of compile-time checking, a good linter is even more important.
It was a pretty crazy day when I first found RuboCop. I immediately used it on the large amount of ruby I've written over the last ~decade.
Rather than running it one file at a time, I found that I got an easier to inspect diff by running it one cop at a time. Rubocop simplifies this approach by allowing you to auto-generate a '.rubocop_todo.yml' file that specifies settings for every 'cop' that would allow your project to produce no warnings. Then you just remove one section of config at a time, autocorrect or manually correct all the errors that pop up, and make a commit describing what style change it introduced across the project. In the process, you also gain a full understanding of really what is required by the cops - there are a couple that I have tuned to be more relaxed than the default, because the defaults seem silly (like cyclomatic complexity, and method length).
Even though in a lot of cases I don't care as much about the style used per se, it's a treat to have a consistent coding style in projects with multiple team members.
Thanks for the kind words!
P.S. There's a lot more info here https://github.com/bbatsov/rubocop