
RuboCop – A Ruby static code analyzer - matugm
http://batsov.com/rubocop/
======
hmsimha
Rubocop is an absolute pleasure to work with, but it also helps that the ruby
community seems to have a more widely-agreed upon style guide than other
communities (Javascript comes to mind). There are similar tools for
Javascript, and I imagine many of them are configurable as well to cover most
use cases. But with the diversity of Javascript style guides and the lack of
cohesiveness in the js community, it seems unlikely that many of these would
be as useful as rubocop 'out-of-the-box'.

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.

~~~
twerquie
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](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.

~~~
savanaly
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.

~~~
lowboy
Apparently it will catch the edge cases for you.

[https://github.com/feross/standard/issues/5#issuecomment-716...](https://github.com/feross/standard/issues/5#issuecomment-71600661)

------
xytop
Is not it a standard yet? That's a well known tool used by thousands of
projects..

------
serghei
Working link to the real thing
[http://batsov.com/rubocop/](http://batsov.com/rubocop/)

~~~
dang
Thanks. URL changed from [http://www.blackbytes.info/2015/03/rubocop-
guide/](http://www.blackbytes.info/2015/03/rubocop-guide/).

Submitters: HN prefers original sources.
[https://news.ycombinator.com/newsguidelines.html](https://news.ycombinator.com/newsguidelines.html)

------
JD557
I'm a casual ruby programmer (I only use it to write "powerful bash scripts")
and have been using rubocop with vim/syntastic.

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.

------
pdkl95
Is "static code analyzer" the new spelling for lint(1)?

[https://www.freebsd.org/cgi/man.cgi?query=lint&sektion=1](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.

------
sergiotapia
Is there a way to have RuboCop automatically clean up things it detects?
Obviously I would run this one file at a time, and git diff it before
committing it.

~~~
nevinera
Rubocop organizes violations into a set of distinct 'cops', each of which is
responsible for checking for a single type of style violation - about half of
them can be autocorrected (--auto-correct argument from the command line).

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).

------
sytse
At GitLab we recently implemented this in our tests. After this all the
reminders and comments about style are no longer needed. You just need to have
green tests as you always should. We think having it in CI is a much better
experience than a HoundCI that makes line comments in the merge request, that
gets quite noisy for people following the MR.

~~~
ericb
Do you have some code to make it a spec by chance? I've been thinking about
doing that.

~~~
sytse
A link to the settings we use is here [https://gitlab.com/gitlab-org/gitlab-
ce/blob/master/.rubocop...](https://gitlab.com/gitlab-org/gitlab-
ce/blob/master/.rubocop.yml) it is pretty loose since we recently implemented
it and didn't want to have to fix 1600 files :)

------
sidraval
For more than just Ruby, as well: [https://houndci.com/](https://houndci.com/)

~~~
bigtunacan
For Ruby Hound is using RuboCop under the hood, but still it is interesting
the way it automatically integrates with GitHub to check pull requests.

------
dankohn1
I highly recommend it's use with pronto. We run Rubocop, Rails Best Practice
and Brakeman against every commit by calling pronto from CircleCI.

[https://github.com/mmozuras/pronto](https://github.com/mmozuras/pronto)

------
PascalW
Absolutely amazing tool, always part of my CI build for Ruby projects.

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.

------
sanemat
Integrate with GitHub review comment not only RuboCop but also eslint, jscs,
and any lint. [https://github.com/packsaddle/ruby-
saddler](https://github.com/packsaddle/ruby-saddler)

------
mtarnovan
RuboCop is amazing. I use it in Sublime via
[https://github.com/pderichs/sublime_rubocop](https://github.com/pderichs/sublime_rubocop)

------
nopcode
I love how it integrates with text editors (textmate, atom) so well. There's
no need to wait for your CI to tell you you're doing something wrong.

~~~
mathgeek
Was not aware of this. Many thanks!

------
stevewilhelm
We are big fans. Use it on our projects in conjunction with Rspec, Capybara,
and Jasmine to test CircleCI-based deploys.

------
gnuvince
So what is it, a static code analyzer or a style checker?

~~~
riffraff
AFAIR it's more of a linter ("unreachable code after an end" or "assignment in
condition") than a static analyzer a-la findbugs ("X might be null here" or
"access to a field before initialization").

~~~
bozhidar
Yeah, that's right. Unfortunately different people put different meaning into
"static analyzer". Obviously linting is also done via static analysis of the
code.

------
zsombor
A great tool to create a healthy debate about nothing, while the world changes
unnoticed beneath you.

------
bozhidar
RuboCop's author here. If I knew someone would ever link to the homepage I
would have put some useful info in it. :-)

Thanks for the kind words!

P.S. There's a lot more info here
[https://github.com/bbatsov/rubocop](https://github.com/bbatsov/rubocop)

~~~
escherize
bozhidar also is the maintainer of CIDER [1] for Emacs + Clojure. It's the
most popular way to use Clojure.

[1] [https://github.com/clojure-emacs/cider](https://github.com/clojure-
emacs/cider)

~~~
bozhidar
Guilty as charged. :-)

