Showing 1,009 of 1,009 total issues
Use the new Ruby 1.9 hash syntax. Open
gem 'sqlite3', '~> 1.3.8', :platforms => :ruby
- 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}
Line is too long. [104/80] Open
# Supports getting and setting style properties with hash notation to ensure backwards-compatibility
- Exclude checks
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Open
require 'active_support/core_ext/module/delegation'
- 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"
Unused method argument - style_name
. If it's necessary, use _
or _style_name
as an argument name to indicate that it won't be used. You can also write as rails_env(*)
if you want the method to accept any arguments but don't care about them. Open
def rails_env attachment, style_name
- Read upRead up
- Exclude checks
This cop checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
Example:
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end
Line is too long. [114/80] Open
[ basename(attachment, style_name), extension(attachment, style_name) ].delete_if(&:empty?).join(".".freeze)
- Exclude checks
Line is too long. [83/80] Open
attachment.instance_read(:updated_at).in_time_zone(attachment.time_zone).to_s
- Exclude checks
Use def with parentheses when there are parameters. Open
def rails_env attachment, style_name
- Read upRead up
- Exclude checks
This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.
Example: EnforcedStyle: require_parentheses (default)
# The `require_parentheses` style requires method definitions
# to always use parentheses
# bad
def bar num1, num2
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
# good
def bar(num1, num2)
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
Example: EnforcedStyle: requirenoparentheses
# The `require_no_parentheses` style requires method definitions
# to never use parentheses
# bad
def bar(num1, num2)
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
# good
def bar num1, num2
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
Example: EnforcedStyle: requirenoparenthesesexceptmultiline
# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.
# bad
def bar(num1, num2)
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
# good
def bar num1, num2
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
Do not use space inside array brackets. Open
[ attr_name, base_attr_name ].each do |error_attr_name|
- 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 ]]
Use the new Ruby 1.9 hash syntax. Open
:count => human_size(option_value)
- 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}
Line is too long. [88/80] Open
record.errors.add attribute, :invalid, options.merge(:types => types.join(', '))
- Exclude checks
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Open
require 'active_support/core_ext/string/inflections'
- 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"
Space inside { missing. Open
args = {:style => name}
- Read upRead up
- Exclude checks
Checks that braces used for hash literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that hash literals have
# surrounding space.
# bad
h = {a: 1, b: 2}
# good
h = { a: 1, b: 2 }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that hash literals have
# no surrounding space.
# bad
h = { a: 1, b: 2 }
# good
h = {a: 1, b: 2}
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.
# bad
h = { a: { b: 2 } }
# good
h = { a: { b: 2 }}
Line is too long. [96/80] Open
@source_file_options.respond_to?(:call) ? @source_file_options.call(attachment.instance) :
- Exclude checks
Line is too long. [87/80] Open
(@source_file_options || attachment.send(:extra_source_file_options_for, name))
- Exclude checks
Indent when
as deep as case
. Open
when Paperclip::Style
- Read upRead up
- Exclude checks
This cop checks how the whens of a case expression are indented in relation to its case or end keyword.
It will register a separate offense for each misaligned when.
Example:
# If Layout/EndAlignment is set to keyword style (default)
# *case* and *end* should always be aligned to same depth,
# and therefore *when* should always be aligned to both -
# regardless of configuration.
# bad for all styles
case n
when 0
x * 2
else
y / 3
end
# good for all styles
case n
when 0
x * 2
else
y / 3
end
Example: EnforcedStyle: case (default)
# if EndAlignment is set to other style such as
# start_of_line (as shown below), then *when* alignment
# configuration does have an effect.
# bad
a = case n
when 0
x * 2
else
y / 3
end
# good
a = case n
when 0
x * 2
else
y / 3
end
Example: EnforcedStyle: end
# bad
a = case n
when 0
x * 2
else
y / 3
end
# good
a = case n
when 0
x * 2
else
y / 3
end
Do not use space inside array brackets. Open
[ basename(attachment, style_name), extension(attachment, style_name) ].delete_if(&:empty?).join(".".freeze)
- 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 ]]
Use def with parentheses when there are parameters. Open
def basename attachment, style_name
- Read upRead up
- Exclude checks
This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.
Example: EnforcedStyle: require_parentheses (default)
# The `require_parentheses` style requires method definitions
# to always use parentheses
# bad
def bar num1, num2
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
# good
def bar(num1, num2)
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
Example: EnforcedStyle: requirenoparentheses
# The `require_no_parentheses` style requires method definitions
# to never use parentheses
# bad
def bar(num1, num2)
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
# good
def bar num1, num2
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
Example: EnforcedStyle: requirenoparenthesesexceptmultiline
# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.
# bad
def bar(num1, num2)
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
# good
def bar num1, num2
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
Use def with parentheses when there are parameters. Open
def attachment attachment, style_name
- Read upRead up
- Exclude checks
This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.
Example: EnforcedStyle: require_parentheses (default)
# The `require_parentheses` style requires method definitions
# to always use parentheses
# bad
def bar num1, num2
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
# good
def bar(num1, num2)
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
Example: EnforcedStyle: requirenoparentheses
# The `require_no_parentheses` style requires method definitions
# to never use parentheses
# bad
def bar(num1, num2)
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
# good
def bar num1, num2
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
Example: EnforcedStyle: requirenoparenthesesexceptmultiline
# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.
# bad
def bar(num1, num2)
num1 + num2
end
def foo descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name
do_something
end
# good
def bar num1, num2
num1 + num2
end
def foo(descriptive_var_name,
another_descriptive_var_name,
last_descriptive_var_name)
do_something
end
Line is too long. [81/80] Open
# * +unless+: Same as +if+ but validates if lambda or method returns false.
- Exclude checks
Line is too long. [82/80] Open
# You'll still need to have a virtual attribute (created by +attr_accessor+)
- Exclude checks