Showing 16,957 of 16,957 total issues
Assignment Branch Condition size for extract_params is too high. [<6, 18, 2> 19.08/17] Open
def extract_params
# Parse/get params from the job first.
job_params = parse_advanced(job.advanced)
# Old jobs from beta releases may not have the advanced key but they
# will have the deprecated advanced_params key.
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.
Interpreting ABC size:
- <= 17 satisfactory
- 18..30 unsatisfactory
- > 30 dangerous
You can have repeated "attributes" calls count as a single "branch".
For this purpose, attributes are any method with no argument; no attempt
is meant to distinguish actual attr_reader
from other methods.
Example: CountRepeatedAttributes: false (default is true)
# `model` and `current_user`, refenced 3 times each,
# are each counted as only 1 branch each if
# `CountRepeatedAttributes` is set to 'false'
def search
@posts = model.active.visible_by(current_user)
.search(params[:q])
@posts = model.some_process(@posts, current_user)
@posts = model.another_process(@posts, current_user)
render 'pages/search/page'
end
This cop also takes into account IgnoredMethods
(defaults to []
)
Add empty line after guard clause. Open
return nil unless id.match(PFAM_ID_PATTERN) or title.match(PFAM_ID_PATTERN)
- Read upRead up
- Exclude checks
This cop enforces empty line after guard clause
Example:
# bad
def foo
return if need_return?
bar
end
# good
def foo
return if need_return?
bar
end
# good
def foo
return if something?
return if something_different?
bar
end
# also good
def foo
if something?
do_something
return if need_return?
end
end
Align the keys of a hash literal if they span more than one line. Open
url: url,
- Read upRead up
- Exclude checks
Check that the keys, separators, and values of a multi-line hash literal are aligned according to configuration. The configuration options are:
- key (left align keys, one space before hash rockets and values)
- separator (align hash rockets and colons, right align keys)
- table (left align keys, hash rockets, and values)
The treatment of hashes passed as the last argument to a method call can also be configured. The options are:
- always_inspect
- always_ignore
- ignore_implicit (without curly braces)
Alternatively you can specify multiple allowed styles. That's done by passing a list of styles to EnforcedStyles.
Example: EnforcedHashRocketStyle: key (default)
# bad
{
:foo => bar,
:ba => baz
}
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedHashRocketStyle: separator
# bad
{
:foo => bar,
:ba => baz
}
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedHashRocketStyle: table
# bad
{
:foo => bar,
:ba => baz
}
# good
{
:foo => bar,
:ba => baz
}
Example: EnforcedColonStyle: key (default)
# bad
{
foo: bar,
ba: baz
}
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedColonStyle: separator
# bad
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedColonStyle: table
# bad
{
foo: bar,
ba: baz
}
# good
{
foo: bar,
ba: baz
}
Example: EnforcedLastArgumentHashStyle: always_inspect (default)
# Inspect both implicit and explicit hashes.
# bad
do_something(foo: 1,
bar: 2)
# bad
do_something({foo: 1,
bar: 2})
# good
do_something(foo: 1,
bar: 2)
# good
do_something(
foo: 1,
bar: 2
)
# good
do_something({foo: 1,
bar: 2})
# good
do_something({
foo: 1,
bar: 2
})
Example: EnforcedLastArgumentHashStyle: always_ignore
# Ignore both implicit and explicit hashes.
# good
do_something(foo: 1,
bar: 2)
# good
do_something({foo: 1,
bar: 2})
Example: EnforcedLastArgumentHashStyle: ignore_implicit
# Ignore only implicit hashes.
# bad
do_something({foo: 1,
bar: 2})
# good
do_something(foo: 1,
bar: 2)
Example: EnforcedLastArgumentHashStyle: ignore_explicit
# Ignore only explicit hashes.
# bad
do_something(foo: 1,
bar: 2)
# good
do_something({foo: 1,
bar: 2})
Use $stdin
instead of STDIN
. Open
response = STDIN.gets.to_s.strip
- Read upRead up
- Exclude checks
This cop enforces the use of $stdout/$stderr/$stdin
instead of STDOUT/STDERR/STDIN
.
STDOUT/STDERR/STDIN
are constants, and while you can actually
reassign (possibly to redirect some stream) constants in Ruby, you'll get
an interpreter warning if you do so.
Safety:
Autocorrection is unsafe because STDOUT
and $stdout
may point to different
objects, for example.
Example:
# bad
STDOUT.puts('hello')
hash = { out: STDOUT, key: value }
def m(out = STDOUT)
out.puts('hello')
end
# good
$stdout.puts('hello')
hash = { out: $stdout, key: value }
def m(out = $stdout)
out.puts('hello')
end
Rename is_compatible
to compatible?
. Open
def is_compatible(given, expected)
- Read upRead up
- Exclude checks
This cop makes sure that predicates are named properly.
Example:
# bad
def is_even(value)
end
def is_even?(value)
end
# good
def even?(value)
end
# bad
def has_value
end
def has_value?
end
# good
def value?
end
Use ||
instead of or
. Open
return nil unless id.match(PFAM_ID_PATTERN) or title.match(PFAM_ID_PATTERN)
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
||
instead. It can be configured to check only in conditions or in
all contexts.
Safety:
Auto-correction is unsafe because there is a different operator precedence
between logical operators (&&
and ||
) and semantic operators (and
and or
),
and that might change the behaviour.
Example: EnforcedStyle: always
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals (default)
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Avoid rescuing without specifying an error class. Open
rescue => e
- Read upRead up
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Avoid using {...}
for multi-line blocks. Open
gaps length qcovhsp qseq sseq midline].inject({}) { |h, k|
- Read upRead up
- Exclude checks
Check for uses of braces or do/end around single line or multi-line blocks.
Methods that can be either procedural or functional and cannot be
categorised from their usage alone is ignored.
lambda
, proc
, and it
are their defaults.
Additional methods can be added to the IgnoredMethods
.
Example: EnforcedStyle: linecountbased (default)
# bad - single line block
items.each do |item| item / 5 end
# good - single line block
items.each { |item| item / 5 }
# bad - multi-line block
things.map { |thing|
something = thing.some_method
process(something)
}
# good - multi-line block
things.map do |thing|
something = thing.some_method
process(something)
end
Example: EnforcedStyle: semantic
# Prefer `do...end` over `{...}` for procedural blocks.
# return value is used/assigned
# bad
foo = map do |x|
x
end
puts (map do |x|
x
end)
# return value is not used out of scope
# good
map do |x|
x
end
# Prefer `{...}` over `do...end` for functional blocks.
# return value is not used out of scope
# bad
each { |x|
x
}
# return value is used/assigned
# good
foo = map { |x|
x
}
map { |x|
x
}.inspect
# The AllowBracesOnProceduralOneLiners option is ignored unless the
# EnforcedStyle is set to `semantic`. If so:
# If the AllowBracesOnProceduralOneLiners option is unspecified, or
# set to `false` or any other falsey value, then semantic purity is
# maintained, so one-line procedural blocks must use do-end, not
# braces.
# bad
collection.each { |element| puts element }
# good
collection.each do |element| puts element end
# If the AllowBracesOnProceduralOneLiners option is set to `true`, or
# any other truthy value, then one-line procedural blocks may use
# either style. (There is no setting for requiring braces on them.)
# good
collection.each { |element| puts element }
# also good
collection.each do |element| puts element end
Example: EnforcedStyle: bracesforchaining
# bad
words.each do |word|
word.flip.flop
end.join("-")
# good
words.each { |word|
word.flip.flop
}.join("-")
Example: EnforcedStyle: always_braces
# bad
words.each do |word|
word.flip.flop
end
# good
words.each { |word|
word.flip.flop
}
Example: BracesRequiredMethods: ['sig']
# Methods listed in the BracesRequiredMethods list, such as 'sig'
# in this example, will require `{...}` braces. This option takes
# precedence over all other configurations except IgnoredMethods.
# bad
sig do
params(
foo: string,
).void
end
def bar(foo)
puts foo
end
# good
sig {
params(
foo: string,
).void
}
def bar(foo)
puts foo
end
Example: IgnoredMethods: ['lambda', 'proc', 'it' ] (default)
# good
foo = lambda do |x|
puts "Hello, #{x}"
end
foo = lambda do |x|
x * 100
end
Call super
to initialize state of the parent class. Open
def initialize(des, ent)
@des = des
@ent = ent
end
- Read upRead up
- Exclude checks
This cop checks for the presence of constructors and lifecycle callbacks
without calls to super
.
This cop does not consider method_missing
(and respond_to_missing?
)
because in some cases it makes sense to overtake what is considered a
missing method. In other cases, the theoretical ideal handling could be
challenging or verbose for no actual gain.
Example:
# bad
class Employee < Person
def initialize(name, salary)
@salary = salary
end
end
# good
class Employee < Person
def initialize(name, salary)
super(name)
@salary = salary
end
end
# bad
class Parent
def self.inherited(base)
do_something
end
end
# good
class Parent
def self.inherited(base)
super
do_something
end
end
Prefer string interpolation to string concatenation. Open
Find.find(database_dir + '/') do |path|
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Two modes are supported:
1. aggressive
style checks and corrects all occurrences of +
where
either the left or right side of +
is a string literal.
2. conservative
style on the other hand, checks and corrects only if
left side (receiver of +
method call) is a string literal.
This is useful when the receiver is some expression that returns string like Pathname
instead of a string literal.
Safety:
This cop is unsafe in aggressive
mode, as it cannot be guaranteed that
the receiver is actually a string, which can result in a false positive.
Example: Mode: aggressive (default)
# bad
email_with_name = user.name + ' <' + user.email + '>'
Pathname.new('/') + 'test'
# good
email_with_name = "#{user.name} <#{user.email}>"
email_with_name = format('%s <%s>', user.name, user.email)
"#{Pathname.new('/')}test"
# accepted, line-end concatenation
name = 'First' +
'Last'
Example: Mode: conservative
# bad
'Hello' + user.name
# good
"Hello #{user.name}"
user.name + '!!'
Pathname.new('/') + 'test'
Incorrect indentation detected (column 4 instead of 7). Open
# on 'doctor',
- Read upRead up
- Exclude checks
This cop checks the indentation of comments.
Example:
# bad
# comment here
def method_name
end
# comment here
a = 'hello'
# yet another comment
if true
true
end
# good
# comment here
def method_name
end
# comment here
a = 'hello'
# yet another comment
if true
true
end
Use 2 spaces for indentation in a heredoc. Open
SequenceServer has scanned your databases directory and will now offer
to convert FASTA files into BLAST databases. It will also offer to
reformat any old-format BLAST databases and those created without
the -parse_seqids option of makeblastdb (-parse_seqids option is
required for sequence retrieval to correctly work).
- Read upRead up
- Exclude checks
This cop checks the indentation of the here document bodies. The bodies are indented one step.
Note: When Layout/LineLength
's AllowHeredoc
is false (not default),
this cop does not add any offenses for long here documents to
avoid Layout/LineLength
's offenses.
Example:
# bad
<<-RUBY
something
RUBY
# good
<<~RUBY
something
RUBY
Favor modifier unless
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
unless File.exist?(config[:bin]) && File.directory?(config[:bin])
- Read upRead up
- Exclude checks
Checks for if
and unless
statements that would fit on one line if
written as modifier if
/unless
. The cop also checks for modifier
if
/unless
lines that exceed the maximum line length.
The maximum line length is configured in the Layout/LineLength
cop. The tab size is configured in the IndentationWidth
of the
Layout/IndentationStyle
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
do_something_with_a_long_name(arg) if long_condition_that_prevents_code_fit_on_single_line
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
if long_condition_that_prevents_code_fit_on_single_line
do_something_with_a_long_name(arg)
end
if short_condition # a long comment that makes it too long if it were just a single line
do_something
end
Add empty line after guard clause. Open
return nil unless id.match(UNIPROT_ID_PATTERN) or title.match(UNIPROT_ID_PATTERN)
- Read upRead up
- Exclude checks
This cop enforces empty line after guard clause
Example:
# bad
def foo
return if need_return?
bar
end
# good
def foo
return if need_return?
bar
end
# good
def foo
return if something?
return if something_different?
bar
end
# also good
def foo
if something?
do_something
return if need_return?
end
end
Use ||
instead of or
. Open
return nil unless id.match(NCBI_ID_PATTERN) or title.match(NCBI_ID_PATTERN)
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
||
instead. It can be configured to check only in conditions or in
all contexts.
Safety:
Auto-correction is unsafe because there is a different operator precedence
between logical operators (&&
and ||
) and semantic operators (and
and or
),
and that might change the behaviour.
Example: EnforcedStyle: always
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals (default)
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Call super
to initialize state of the parent class. Open
def initialize
self.datetime_format = '%Y-%m-%d %H:%M:%S'
end
- Read upRead up
- Exclude checks
This cop checks for the presence of constructors and lifecycle callbacks
without calls to super
.
This cop does not consider method_missing
(and respond_to_missing?
)
because in some cases it makes sense to overtake what is considered a
missing method. In other cases, the theoretical ideal handling could be
challenging or verbose for no actual gain.
Example:
# bad
class Employee < Person
def initialize(name, salary)
@salary = salary
end
end
# good
class Employee < Person
def initialize(name, salary)
super(name)
@salary = salary
end
end
# bad
class Parent
def self.inherited(base)
do_something
end
end
# good
class Parent
def self.inherited(base)
super
do_something
end
end
Align the elements of an array literal if they span more than one line. Open
SequenceServer::CONFIG_FILE_ERROR,
- Read upRead up
- Exclude checks
Here we check if the elements of a multi-line array literal are aligned.
Example: EnforcedStyle: withfirstelement (default)
# good
array = [1, 2, 3,
4, 5, 6]
array = ['run',
'forrest',
'run']
# bad
array = [1, 2, 3,
4, 5, 6]
array = ['run',
'forrest',
'run']
Example: EnforcedStyle: withfixedindentation
# good
array = [1, 2, 3,
4, 5, 6]
# bad
array = [1, 2, 3,
4, 5, 6]
Avoid using rescue
in its modifier form. Open
Resolv.getname(ip_address) rescue nil
- Read upRead up
- Exclude checks
This cop checks for uses of rescue in its modifier form.
The cop to check rescue
in its modifier form is added for following
reasons:
The syntax of modifier form
rescue
can be misleading because it might led us to believe thatrescue
handles the given exception but it actually rescue all exceptions to return the given rescue block. In this case, value returned by handle_error or SomeException.Modifier form
rescue
would rescue all the exceptions. It would silently skip all exception or errors and handle the error. Example: IfNoMethodError
is raised, modifier form rescue would handle the exception.
Example:
# bad
some_method rescue handle_error
# bad
some_method rescue SomeException
# good
begin
some_method
rescue
handle_error
end
# good
begin
some_method
rescue SomeException
handle_error
end
Use the double pipe equals operator ||=
instead. Open
unless seq
seq = "# ERROR: #{locus} not found in any database"
end
- Read upRead up
- Exclude checks
This cop checks for potential usage of the ||=
operator.
Example:
# bad
name = name ? name : 'Bozhidar'
# bad
name = if name
name
else
'Bozhidar'
end
# bad
unless name
name = 'Bozhidar'
end
# bad
name = 'Bozhidar' unless name
# good - set name to 'Bozhidar', only if it's nil or false
name ||= 'Bozhidar'
Add empty line after guard clause. Open
return nil unless id.match(NCBI_ID_PATTERN) or title.match(NCBI_ID_PATTERN)
- Read upRead up
- Exclude checks
This cop enforces empty line after guard clause
Example:
# bad
def foo
return if need_return?
bar
end
# good
def foo
return if need_return?
bar
end
# good
def foo
return if something?
return if something_different?
bar
end
# also good
def foo
if something?
do_something
return if need_return?
end
end