Style: check coding style ● White spaces ○ Indentation width ○ White spaces around brackets ● Syntax vs Method call ○ alias vs alias_method ○ for vs each
Style checks based on one of the style guides. ● https://github.com/bbatsov/ruby- style-gudie ○ If your coding style has differences, you can configure RuboCop.
How does RuboCop check code? ● RuboCop analyzes each file individually. ● RuboCop does not execute code. See “Writing Lint for Ruby” in RubyKaigi 2017.
Analyzing each file individually ● RuboCop does not check relations between files. ○ e.g. db/schema.rb and models. ● For simplicity and performance. ○ RuboCop can analyze parallelly.
Do not execute code ● RuboCop doesn’t execute your code. ○ Pros: If your code has system('rm -rf /'), it does not remove. ○ Cons: RuboCop cannot understand application completely. ■ e.g. eval, method call
How does RuboCop review ● rubocop $(git diff --name-only) before human review. ● I recommend using CI to run RuboCop. ○ e.g. SideCI, CodeClimate and Reviewdog.
Reduce human reviews ● Layout and style reviews by human are no longer necessary. ○ e.g. “Remove the spaces”, “Use each method instead of for”. ○ It’s a RuboCop job, not a human job.
Action for Style Review ● Check your coding style. ○ If the review does not match with your coding style, you should configure or ignore the review. ○ http://rubocop.readthedocs.io/en/stabl e/
Action for Lint Review ● Lint reviews has false positives. ○ In other words, Lint review has a mistake sometimes. ○ Because RuboCop does not know your application completely. ■ See the slides above. ● It is not a bug, it is a restriction.
Start and/or continue to use RuboCop ● You can get knowledges from WEB+DB PRESS vol.102. ○ “RuboCopできれいで安全なコード” written by me. ○ http://amzn.asia/fZ9cgZO
Conclusion ● RuboCop is not a “Silver Bullet”. ○ In many cases, the default coding style doesn't match your coding style. ○ RuboCop has false positives. ○ So when RuboCop reviews your code, you should review RuboCop Review.