I want to create a new API/MVC project using a number of tools including Devise, authority, and rolify. One thing I want to establish in this greenfield project is having my codebase be clean, and I figured I want to lint it from day one. I tried doing that and rubocop came back with 228 errors. This is against template code generated by those tools. Can you generate linter-friendly template files and if so how, or am I doomed to fix the errors/put in a ton of exceptions?
Unfortunately, not possible.
Rubocop is going to find issues, even if you bootstrap a new Rails project from scratch. For example some code lines will be detected as offense by the Metrics/LineLength
cop.
You may be wondering why Rails doesn't fix these issues beforehand, so people can get a fresh project without any offenses. The answer is, Rails, as a project is not accepting pull requests related to 'cosmetic' changes. Therefore, no one is fixing these issues. Here is the explanation of this decision. Same situation exists for tools like Devise, Simpleform etc.
On the other hand, Rubocop is a great tool, but not all the developers agree with the default settings. That's why something called .rubocop.yml
exists.
I'm a big fan of code quality, so I really appreciate your intention. You can try to fix many of these offenses by calling rubocop with an -a
flag (rubocop -a
), and fix the rest manually. After this point you will not get similar offense messages.
I'm using Rubocop to prevent ruby code smells, erblint as ERB linter and HTMLHint as HTML linter. I combined all these tools in a rake task called quality
. When I run quality:all
, I'm automatically checking my codebase against errors, typos and offenses. You can see the task here.