Method has too many lines. [35/10] Open
def install_template(template_declaration)
template_name = template_declaration.name
puts("Installing #{template_name}...")
template_name = template_declaration.name
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for install_template is too high. [39.42/15] Open
def install_template(template_declaration)
template_name = template_declaration.name
puts("Installing #{template_name}...")
template_name = template_declaration.name
- 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
Method install_template
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def install_template(template_declaration)
template_name = template_declaration.name
puts("Installing #{template_name}...")
template_name = template_declaration.name
Method install_template
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def install_template(template_declaration)
template_name = template_declaration.name
puts("Installing #{template_name}...")
template_name = template_declaration.name
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid using {...}
for multi-line blocks. Open
}.select { |catalog_path|
- Read upRead up
- Exclude checks
Check for uses of braces or do/end around single line or multi-line blocks.
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
Example: EnforcedStyle: bracesforchaining
# bad
words.each do |word|
word.flip.flop
end.join("-")
# good
words.each { |word|
word.flip.flop
}.join("-")
Prefer the use of the nil?
predicate. Open
if catalog_path == nil
- Read upRead up
- Exclude checks
This cop checks for comparison of something with nil using ==.
Example:
# bad
if x == nil
end
# good
if x.nil?
end
Align .join
with .new
on line 47. Open
.join(template_name)
- Read upRead up
- Exclude checks
This cop checks the indentation of the method name part in method calls that span more than one line.
Example: EnforcedStyle: aligned
# bad
while myvariable
.b
# do something
end
# good
while myvariable
.b
# do something
end
# good
Thing.a
.b
.c
Example: EnforcedStyle: indented
# good
while myvariable
.b
# do something
end
Example: EnforcedStyle: indentedrelativeto_receiver
# good
while myvariable
.a
.b
# do something
end
# good
myvariable = Thing
.a
.b
.c
Align .join
with .new
on line 15. Open
.join(CATALOGS_DIR)
- Read upRead up
- Exclude checks
This cop checks the indentation of the method name part in method calls that span more than one line.
Example: EnforcedStyle: aligned
# bad
while myvariable
.b
# do something
end
# good
while myvariable
.b
# do something
end
# good
Thing.a
.b
.c
Example: EnforcedStyle: indented
# good
while myvariable
.b
# do something
end
Example: EnforcedStyle: indentedrelativeto_receiver
# good
while myvariable
.a
.b
# do something
end
# good
myvariable = Thing
.a
.b
.c
Line is too long. [86/80] Open
# Incapsulates the logic of installing Generamba templates from the template catalog
- Exclude checks
Line is too long. [86/80] Open
error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
- Exclude checks
Line is too long. [82/80] Open
template_path = browse_catalog_for_a_template(catalog_path, template_name)
- Exclude checks
Redundant return
detected. Open
return nil
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Line is too long. [97/80] Open
rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, template_path)
- Exclude checks
Extra empty line detected at module body beginning. Open
# Incapsulates the logic of installing Generamba templates from the template catalog
- Read upRead up
- Exclude checks
This cops checks if empty lines around the bodies of modules match the configuration.
Example: EnforcedStyle: empty_lines
# good
module Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
module Foo
module Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
module Foo
def bar; end
end
Example: EnforcedStyle: noemptylines (default)
# good
module Foo
def bar
# ...
end
end
Prefer !expression.nil?
over expression != nil
. Open
template_path != nil
- Read upRead up
- Exclude checks
This cop checks for non-nil checks, which are usually redundant.
Example:
# bad
if x != nil
end
# good (when not allowing semantic changes)
# bad (when allowing semantic changes)
if !x.nil?
end
# good (when allowing semantic changes)
if x
end
Non-nil checks are allowed if they are the final nodes of predicate.
# good
def signed_in?
!current_user.nil?
end
Line is too long. [96/80] Open
error_description = "Cannot find #{template_name} in any catalog. Try another name.".red
- Exclude checks
Line is too long. [107/80] Open
rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, template_path)
- Exclude checks
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if Dir.exist?(template_path)
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Avoid multi-line chains of blocks. Open
}.select { |catalog_path|
- Read upRead up
- Exclude checks
This cop checks for chaining of a block after another block that spans multiple lines.
Example:
Thread.list.find_all do |t|
t.alive?
end.map do |t|
t.object_id
end
Final newline missing. Open
end
- Exclude checks
Line is too long. [143/80] Open
error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the template catalog #{catalog_path}. Try another name.".red
- Exclude checks
Align .join
with .new
on line 15. Open
.join(GENERAMBA_HOME_DIR)
- Read upRead up
- Exclude checks
This cop checks the indentation of the method name part in method calls that span more than one line.
Example: EnforcedStyle: aligned
# bad
while myvariable
.b
# do something
end
# good
while myvariable
.b
# do something
end
# good
Thing.a
.b
.c
Example: EnforcedStyle: indented
# good
while myvariable
.b
# do something
end
Example: EnforcedStyle: indentedrelativeto_receiver
# good
while myvariable
.a
.b
# do something
end
# good
myvariable = Thing
.a
.b
.c
Shadowing outer local variable - catalog_path
. Open
}.select { |catalog_path|
- 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
Avoid using {...}
for multi-line blocks. Open
catalog_path = catalogs_path.children.select { |child|
- Read upRead up
- Exclude checks
Check for uses of braces or do/end around single line or multi-line blocks.
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
Example: EnforcedStyle: bracesforchaining
# bad
words.each do |word|
word.flip.flop
end.join("-")
# good
words.each { |word|
word.flip.flop
}.join("-")