%w
-literals should be delimited by [
and ]
. Open
Bundler.require(*Rails.groups(:assets => %w(development test)))
- Read upRead up
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)
Unnecessary spacing detected. Open
config.assets.precompile = [ '*.js', '*.css.scss', 'fullcalendar.print.css', 'fullcalendar.css', 'foundation.css' ]
- Read upRead up
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/bbatsov/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/bbatsov/rubocop"
Line is too long. [82/80] Open
# Use SQL instead of Active Record's schema dumper when creating the database.
- Exclude checks
Operator =
should be surrounded by a single space. Open
config.assets.precompile = [ '*.js', '*.css.scss', 'fullcalendar.print.css', 'fullcalendar.css', 'foundation.css' ]
- Read upRead up
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b
Trailing whitespace detected. Open
- Exclude checks
Do not use space inside array brackets. Open
config.assets.precompile = [ '*.js', '*.css.scss', 'fullcalendar.print.css', 'fullcalendar.css', 'foundation.css' ]
- Read upRead up
- Exclude checks
Checks that brackets used for array literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that array literals have
# surrounding space.
# bad
array = [a, b, c, d]
# good
array = [ a, b, c, d ]
Example: EnforcedStyle: no_space
# The `no_space` style enforces that array literals have
# no surrounding space.
# bad
array = [ a, b, c, d ]
# good
array = [a, b, c, d]
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# array brackets, with the exception that successive left
# or right brackets are collapsed together in nested arrays.
# bad
array = [ a, [ b, c ] ]
# good
array = [ a, [ b, c ]]
Line is too long. [97/80] Open
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
- Exclude checks
Line is too long. [82/80] Open
# Settings in config/environments/* take precedence over those specified here.
- Exclude checks
Line is too long. [83/80] Open
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
- Exclude checks
Line is too long. [120/80] Open
config.assets.precompile = [ '*.js', '*.css.scss', 'fullcalendar.print.css', 'fullcalendar.css', 'foundation.css' ]
- Exclude checks
Unused block argument - instance
. If it's necessary, use _
or _instance
as an argument name to indicate that it won't be used. Open
config.action_view.field_error_proc = Proc.new { |html_tag, instance|
- Read upRead up
- Exclude checks
This cop checks for unused block arguments.
Example:
# bad
do_something do |used, unused|
puts used
end
do_something do |bar|
puts :foo
end
define_method(:foo) do |bar|
puts :baz
end
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Missing top-level class documentation comment. Open
class Application < Rails::Application
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Use proc
instead of Proc.new
. Open
config.action_view.field_error_proc = Proc.new { |html_tag, instance|
- Read upRead up
- Exclude checks
This cops checks for uses of Proc.new where Kernel#proc would be more appropriate.
Example:
# bad
p = Proc.new { |n| puts n }
# good
p = proc { |n| puts n }
Trailing whitespace detected. Open
config.action_view.field_error_proc = Proc.new { |html_tag, instance|
- Exclude checks
Line is too long. [87/80] Open
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- Exclude checks
Line is too long. [87/80] Open
# This is necessary if your schema can't be completely dumped by the schema dumper,
- Exclude checks
Trailing whitespace detected. Open
- Exclude checks
Line is too long. [99/80] Open
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- Exclude checks
Use the new Ruby 1.9 hash syntax. Open
Bundler.require(*Rails.groups(:assets => %w(development test)))
- Read upRead up
- Exclude checks
This cop checks hash literal syntax.
It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).
A separate offense is registered for each problematic pair.
The supported styles are:
- ruby19 - forces use of the 1.9 syntax (e.g.
{a: 1}
) when hashes have all symbols for keys - hash_rockets - forces use of hash rockets for all hashes
- nomixedkeys - simply checks for hashes with mixed syntaxes
- ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes
Example: EnforcedStyle: ruby19 (default)
# bad
{:a => 2}
{b: 1, :c => 2}
# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden
Example: EnforcedStyle: hash_rockets
# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}
# good
{:a => 1, :b => 2}
Example: EnforcedStyle: nomixedkeys
# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}
# good
{:a => 1, :b => 2}
{c: 1, d: 2}
Example: EnforcedStyle: ruby19nomixed_keys
# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets
# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}
Do not use space inside array brackets. Open
config.assets.precompile = [ '*.js', '*.css.scss', 'fullcalendar.print.css', 'fullcalendar.css', 'foundation.css' ]
- Read upRead up
- Exclude checks
Checks that brackets used for array literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that array literals have
# surrounding space.
# bad
array = [a, b, c, d]
# good
array = [ a, b, c, d ]
Example: EnforcedStyle: no_space
# The `no_space` style enforces that array literals have
# no surrounding space.
# bad
array = [ a, b, c, d ]
# good
array = [a, b, c, d]
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# array brackets, with the exception that successive left
# or right brackets are collapsed together in nested arrays.
# bad
array = [ a, [ b, c ] ]
# good
array = [ a, [ b, c ]]
Line is too long. [98/80] Open
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- Exclude checks
Line is too long. [100/80] Open
# This will create an empty whitelist of attributes available for mass-assignment for all models
- Exclude checks
Line is too long. [85/80] Open
# Only load the plugins named here, in the order given (default is alphabetical).
- Exclude checks
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
config.encoding = "utf-8"
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Trailing whitespace detected. Open
- Exclude checks
Line is too long. [89/80] Open
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- Exclude checks