A Ruby static code analyzer, based on the community Ruby style guide.
Title | Link |
---|---|
Github | https://github.com/rubocop-hq/rubocop |
Docs | http://rubocop.readthedocs.io/en/latest/ |
Ruby Style Guide | https://github.com/rubocop-hq/ruby-style-guide |
Contents:
Add to your Gemfile:
group :development do
gem 'rubocop', '~> 0.57.1', require: false
end
Run bundle install
.
In your project directory, run rubocop
. It will scan all the files at current level and nested below it for any violations of style guide.
Create a file .rubocop.yml at root of project directory.
Metrics cops deal with properties of the source code that can be measured, such as class length, method length, etc.
To set maximum allowed length of a line of code to 70, you can do:
# .rubocop.yml
Metrics/LineLength:
Max: 70
To skip one or more files from being checked by this cop, you can define Exclude
:
Metrics/LineLength:
Exclude:
- 'path/to/file'
- 'path/to/another/file'
To disable a cop completely i.e. for all the files, you can configure it at global level:
Bundler/OrderedGems:
Enabled: false
To disable all cops for a set of files, do:
AllCops:
Exclude:
- 'path/to/file'
- 'path/to/another/file'
# .rubocop.yml
Style/RescueModifier:
Enabled: false
Style/SignalException:
EnforcedStyle: semantic
Style/FileName:
Exclude:
- 'path/to/file'
- 'path/**/*.rb'
Style/Documentation:
Exclude:
- 'path/to/file'
Style/EachWithObject:
Exclude:
- 'path/to/file'
Style/MultilineBlockChain:
Exclude:
- 'path/to/file'
# .rubocop.yml
Lint/HandleExceptions:
Exclude:
- 'path/to/file'
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
As per this, you need to add a comment # frozen_string_literal: true
to every ruby file at the top. You can ask rubocop
to do it for you by running:
$ rubocop --auto-correct --only FrozenStringLiteralComment
Images
Logo