Summary
Try below Ruby static analysis tools.
- Rubocop: Check Ruby code by Rudy Style Guide.
- Reek: The tool which find bad smell that may (but not necessarily do) indicate a deeper problem.
- Brakeman: A vulnerability scanner for Ruby and Rails applications.
- RailsBestPractices: The tool which is created in Rails community.
Rubocop
bbatsov/rubocop - Ruby - GitHub
Install
$ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin13] $ gem install rubocop $ which rubocop /Users/jun.aruga/.rbenv/shims/rubocop $ rubocop -v 0.36.0
Usage
Check for my ruby codes.
I got many message.
C: Convention
W: Warning
$ cd $SRC_DIR $ rubocop lib/ bin/recommend_sample Inspecting 5 files CCWCC Offenses: lib/recommendation_sample.rb:1:9: C: Prefer single-quoted strings when you don't need string interpolation or special symbols. require "recommendation_sample/version" ... 5 files inspected, 70 offenses detected
Customize project .rubocop file
Disable specified Cop's check.
- D: display cop name.
For example ignore frozen string comment check.
$ rubocop -D lib/recommendation_sample/version.rb Inspecting 1 file C Offenses: lib/recommendation_sample/version.rb:1:1: C: Style/FrozenStringLiteralComment: Missing frozen string literal comment. module RecommendationSample ^
$ vi .rubocop.yml
...
Style/FrozenStringLiteralComment:
Enabled: false
...
$ rubocop -D lib/recommendation_sample/version.rb Inspecting 1 file . 1 file inspected, no offenses detected
Brakeman
RailsBestPractices
GitHub - railsbp/rails_best_practices: a code metric tool for rails projects
Notes
- Rubocop, Reek, Brakeman: Review of Ruby Static Analysis Tools - Codacy | Blog
- Rubocop[Japanese Doc]: 静的解析ツールRuboCopを利用して紳士・淑女Rubyistになろう #rubocop #Ruby|CodeIQ MAGAZINE