Showing 255 of 255 total issues
Do not place comments on the same line as the end
keyword. Open
end # TRANSACTION N.B ActiveRecord::Rollback does not propagate outside of the containing transaction block
- Read upRead up
- Exclude checks
This cop checks for comments put on the same line as some keywords.
These keywords are: begin
, class
, def
, end
, module
.
Note that some comments (such as :nodoc:
and rubocop:disable
) are
allowed.
Example:
# bad
if condition
statement
end # end if
# bad
class X # comment
statement
end
# bad
def x; end # comment
# good
if condition
statement
end
# good
class X # :nodoc:
y
end
Use numrows.zero?
instead of numrows == 0
. Open
if numrows == 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Use uppercase heredoc delimiters. Open
end_eval
- Read upRead up
- Exclude checks
This cop checks that your heredocs are using the configured case. By default it is configured to enforce uppercase heredocs.
Example: EnforcedStyle: uppercase (default)
# bad
<<-sql
SELECT * FROM foo
sql
# good
<<-SQL
SELECT * FROM foo
SQL
Example: EnforcedStyle: lowercase
# bad
<<-SQL
SELECT * FROM foo
SQL
# good
<<-sql
SELECT * FROM foo
sql
Use uppercase heredoc delimiters. Open
end_eval
- Read upRead up
- Exclude checks
This cop checks that your heredocs are using the configured case. By default it is configured to enforce uppercase heredocs.
Example: EnforcedStyle: uppercase (default)
# bad
<<-sql
SELECT * FROM foo
sql
# good
<<-SQL
SELECT * FROM foo
SQL
Example: EnforcedStyle: lowercase
# bad
<<-SQL
SELECT * FROM foo
SQL
# good
<<-sql
SELECT * FROM foo
sql
Pass __FILE__
and __LINE__
to eval
method, as they are used by backtraces. Open
class_eval <<-end_eval
- Read upRead up
- Exclude checks
This cop checks eval
method usage. eval
can receive source location
metadata, that are filename and line number. The metadata is used by
backtraces. This cop recommends to pass the metadata to eval
method.
Example:
# bad
eval <<-RUBY
def do_something
end
RUBY
# bad
C.class_eval <<-RUBY
def do_something
end
RUBY
# good
eval <<-RUBY, binding, __FILE__, __LINE__ + 1
def do_something
end
RUBY
# good
C.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def do_something
end
RUBY
Use uppercase heredoc delimiters. Open
end_eval
- Read upRead up
- Exclude checks
This cop checks that your heredocs are using the configured case. By default it is configured to enforce uppercase heredocs.
Example: EnforcedStyle: uppercase (default)
# bad
<<-sql
SELECT * FROM foo
sql
# good
<<-SQL
SELECT * FROM foo
SQL
Example: EnforcedStyle: lowercase
# bad
<<-SQL
SELECT * FROM foo
SQL
# good
<<-sql
SELECT * FROM foo
sql
Interpolation in single quoted string detected. Use double quoted strings if you need interpolation. Open
raise MappingDefinitionError, 'Failed to map #{attach_to_field} to database operator'
- Read upRead up
- Exclude checks
This cop checks for interpolation in a single quoted string.
Example:
# bad
foo = 'something with #{interpolation} inside'
Example:
# good
foo = "something with #{interpolation} inside"
Shadowing outer local variable - i
. Open
@binder.bindings.each_with_index do |method_binding, i|
- Read upRead up
- Exclude checks
This cop looks for use of the same name as outer local variables
for block arguments or block local variables.
This is a mimic of the warning
"shadowing outer local variable - foo" from ruby -cw
.
Example:
# bad
def some_method
foo = 1
2.times do |foo| # shadowing outer `foo`
do_something(foo)
end
end
Example:
# good
def some_method
foo = 1
2.times do |bar|
do_something(bar)
end
end
Use ext.casecmp('.xlsx').zero?
instead of ext.casecmp('.xlsx') == 0
. Open
if ext.casecmp('.xls') == 0 || ext.casecmp('.xlsx') == 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Put empty method definitions on a single line. Open
def initialize
end
- Read upRead up
- Exclude checks
This cop checks for the formatting of empty method definitions.
By default it enforces empty method definitions to go on a single
line (compact style), but it can be configured to enforce the end
to go on its own line (expanded style).
Note: A method definition is not considered empty if it contains comments.
Example: EnforcedStyle: compact (default)
# bad
def foo(bar)
end
def self.foo(bar)
end
# good
def foo(bar); end
def foo(bar)
# baz
end
def self.foo(bar); end
Example: EnforcedStyle: expanded
# bad
def foo(bar); end
def self.foo(bar); end
# good
def foo(bar)
end
def self.foo(bar)
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if collection
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
When using method_missing
, define respond_to_missing?
. Open
def method_missing(method, *args, &block)
# puts @excel.class, method, args.inspect
if @excel.respond_to?(method)
@excel.send(method, *args, &block)
- Read upRead up
- Exclude checks
This cop checks for the presence of method_missing
without also
defining respond_to_missing?
and falling back on super
.
Example:
#bad
def method_missing(name, *args)
# ...
end
#good
def respond_to_missing?(name, include_private)
# ...
end
def method_missing(name, *args)
# ...
super
end
Use uppercase heredoc delimiters. Open
end_eval
- Read upRead up
- Exclude checks
This cop checks that your heredocs are using the configured case. By default it is configured to enforce uppercase heredocs.
Example: EnforcedStyle: uppercase (default)
# bad
<<-sql
SELECT * FROM foo
sql
# good
<<-SQL
SELECT * FROM foo
SQL
Example: EnforcedStyle: lowercase
# bad
<<-SQL
SELECT * FROM foo
SQL
# good
<<-sql
SELECT * FROM foo
sql
Pass __FILE__
and __LINE__
to eval
method, as they are used by backtraces. Open
class_eval <<-end_eval
- Read upRead up
- Exclude checks
This cop checks eval
method usage. eval
can receive source location
metadata, that are filename and line number. The metadata is used by
backtraces. This cop recommends to pass the metadata to eval
method.
Example:
# bad
eval <<-RUBY
def do_something
end
RUBY
# bad
C.class_eval <<-RUBY
def do_something
end
RUBY
# good
eval <<-RUBY, binding, __FILE__, __LINE__ + 1
def do_something
end
RUBY
# good
C.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def do_something
end
RUBY
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if load_object
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Do not place comments on the same line as the end
keyword. Open
end # all rows processed
- Read upRead up
- Exclude checks
This cop checks for comments put on the same line as some keywords.
These keywords are: begin
, class
, def
, end
, module
.
Note that some comments (such as :nodoc:
and rubocop:disable
) are
allowed.
Example:
# bad
if condition
statement
end # end if
# bad
class X # comment
statement
end
# bad
def x; end # comment
# good
if condition
statement
end
# good
class X # :nodoc:
y
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if ext.casecmp('.xls') == 0 || ext.casecmp('.xlsx') == 0
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Use meaningful heredoc delimiters. Open
EOS
- Read upRead up
- Exclude checks
This cop checks that your heredocs are using meaningful delimiters.
By default it disallows END
and EO*
, and can be configured through
blacklisting additional delimiters.
Example:
# good
<<-SQL
SELECT * FROM foo
SQL
# bad
<<-END
SELECT * FROM foo
END
# bad
<<-EOS
SELECT * FROM foo
EOS
Do not place comments on the same line as the end
keyword. Open
end # ExcelGenerator
- Read upRead up
- Exclude checks
This cop checks for comments put on the same line as some keywords.
These keywords are: begin
, class
, def
, end
, module
.
Note that some comments (such as :nodoc:
and rubocop:disable
) are
allowed.
Example:
# bad
if condition
statement
end # end if
# bad
class X # comment
statement
end
# bad
def x; end # comment
# good
if condition
statement
end
# good
class X # :nodoc:
y
end
Extra blank line detected. Open
def self.parse_yaml( yaml_file )
- Read upRead up
- Exclude checks
This cops checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method