Class has too many lines. [117/100] Open
class RepackageReleases
def initialize(root_deployment, missing_s3_releases = {}, list_releases = Tasks::Bosh::ListReleases.new, create_release = Tasks::Bosh::CreateRelease.new)
raise "Invalid root_deployment object" unless root_deployment.respond_to?(:release_version) && root_deployment.respond_to?(:releases_git_urls) && root_deployment.respond_to?(:release)
@root_deployment = root_deployment
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [30/10] Open
def process(repackaged_releases_path, base_git_clones_path, logs_path)
errors = {}
successfully_processed = []
begin
releases_not_uploaded_to_director = filter_releases
- Read upRead up
- Create a ticketCreate a ticket
- 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 process is too high. [25.81/15] Open
def process(repackaged_releases_path, base_git_clones_path, logs_path)
errors = {}
successfully_processed = []
begin
releases_not_uploaded_to_director = filter_releases
- Read upRead up
- Create a ticketCreate a ticket
- 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 has too many lines. [14/10] Open
def clone_git_repository(boshrelease_name, git_url, base_git_clones_path, logs_path)
git_clone_path = File.join(base_git_clones_path, boshrelease_name)
error_message = ""
status = nil
cmd_line = "git clone \"#{git_url}\" \"#{git_clone_path}\""
- Read upRead up
- Create a ticketCreate a ticket
- 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.
Method has too many lines. [13/10] Open
def generate_boshrelease_namespaces(repackaged_releases_path, successfully_processed)
File.open(File.join(repackaged_releases_path, 'boshreleases-namespaces.csv'), 'w+') do |file|
successfully_processed.each do |name|
version = @root_deployment.release_version(name)
release_details = @root_deployment.release(name)&.dig('repository')
- Read upRead up
- Create a ticketCreate a ticket
- 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.
Method has too many lines. [13/10] Open
def filter_releases
active_releases = @list_releases_command_holder.execute
puts "Filtering releases"
boshreleases_git_urls = @root_deployment.releases_git_urls
boshreleases_git_urls.delete_if do |name, _url|
- Read upRead up
- Create a ticketCreate a ticket
- 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.
Method process
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process(repackaged_releases_path, base_git_clones_path, logs_path)
errors = {}
successfully_processed = []
begin
releases_not_uploaded_to_director = filter_releases
- Create a ticketCreate a ticket
RepackageReleases#clone_git_repository has approx 11 statements Open
def clone_git_repository(boshrelease_name, git_url, base_git_clones_path, logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
RepackageReleases#process has approx 24 statements Open
def process(repackaged_releases_path, base_git_clones_path, logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
RepackageReleases#filter_releases has approx 13 statements Open
def filter_releases
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
RepackageReleases#clean_git_clone refers to 'git_clone_path' more than self (maybe move it to another class?) Open
raise "Invalid git_clone_path: #{git_clone_path}" if git_clone_path.to_s.empty? || git_clone_path == '/' || git_clone_path == '*'
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.
Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.
Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.
Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.
Example
Running Reek on:
class Warehouse
def sale_price(item)
(item.price - item.rebate) * @vat
end
end
would report:
Warehouse#total_price refers to item more than self (FeatureEnvy)
since this:
(item.price - item.rebate)
belongs to the Item class, not the Warehouse.
RepackageReleases#generate_boshrelease_namespaces has approx 9 statements Open
def generate_boshrelease_namespaces(repackaged_releases_path, successfully_processed)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Method clone_git_repository
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def clone_git_repository(boshrelease_name, git_url, base_git_clones_path, logs_path)
git_clone_path = File.join(base_git_clones_path, boshrelease_name)
error_message = ""
status = nil
cmd_line = "git clone \"#{git_url}\" \"#{git_clone_path}\""
- Read upRead up
- Create a ticketCreate a ticket
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
CloneError has no descriptive comment Open
class CloneError < RuntimeError; end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.
Example
Given
class Dummy
# Do things...
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:Dummy has no descriptive comment (IrresponsibleModule)
Fixing this is simple - just an explaining comment:
# The Dummy class is responsible for ...
class Dummy
# Do things...
end
RepackageReleases#initialize manually dispatches method call Open
raise "Invalid root_deployment object" unless root_deployment.respond_to?(:release_version) && root_deployment.respond_to?(:releases_git_urls) && root_deployment.respond_to?(:release)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Reek reports a Manual Dispatch smell if it finds source code that manually checks whether an object responds to a method before that method is called. Manual dispatch is a type of Simulated Polymorphism which leads to code that is harder to reason about, debug, and refactor.
Example
class MyManualDispatcher
attr_reader :foo
def initialize(foo)
@foo = foo
end
def call
foo.bar if foo.respond_to?(:bar)
end
end
Reek would emit the following warning:
test.rb -- 1 warning:
[9]: MyManualDispatcher manually dispatches method call (ManualDispatch)
Method filter_releases
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def filter_releases
active_releases = @list_releases_command_holder.execute
puts "Filtering releases"
boshreleases_git_urls = @root_deployment.releases_git_urls
boshreleases_git_urls.delete_if do |name, _url|
- Read upRead up
- Create a ticketCreate a ticket
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
RepackageReleases#filter_releases performs a nil-check Open
bosh_uploaded = version_details.nil? ? false : true
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
A NilCheck
is a type check. Failures of NilCheck
violate the "tell, don't ask" principle.
Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.
Example
Given
class Klass
def nil_checker(argument)
if argument.nil?
puts "argument isn't nil!"
end
end
end
Reek would emit the following warning:
test.rb -- 1 warning:
[3]:Klass#nil_checker performs a nil-check. (NilCheck)
RepackageReleases#clean_bosh_files has unused parameter 'logs_path' Open
def clean_bosh_files(logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Unused Parameter
refers to methods with parameters that are unused in scope of the method.
Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.
Example
Given:
class Klass
def unused_parameters(x,y,z)
puts x,y # but not z
end
end
Reek would emit the following warning:
[2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)
RepackageReleases#clone_git_repository has unused parameter 'logs_path' Open
def clone_git_repository(boshrelease_name, git_url, base_git_clones_path, logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Unused Parameter
refers to methods with parameters that are unused in scope of the method.
Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.
Example
Given:
class Klass
def unused_parameters(x,y,z)
puts x,y # but not z
end
end
Reek would emit the following warning:
[2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)
RepackageReleases#clean_git_clone has unused parameter 'logs_path' Open
def clean_git_clone(git_clone_path, logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Unused Parameter
refers to methods with parameters that are unused in scope of the method.
Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.
Example
Given:
class Klass
def unused_parameters(x,y,z)
puts x,y # but not z
end
end
Reek would emit the following warning:
[2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)
RepackageReleases#repackage_release has unused parameter 'logs_path' Open
def repackage_release(name, destination_dir, working_dir, logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Unused Parameter
refers to methods with parameters that are unused in scope of the method.
Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.
Example
Given:
class Klass
def unused_parameters(x,y,z)
puts x,y # but not z
end
end
Reek would emit the following warning:
[2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)
RepackageReleases#missing_boshrelease? has the variable name 'v' Open
v = @missing_s3_releases.dig(name, 'version').to_s
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
RepackageReleases#process has the variable name 'e' Open
rescue Tasks::Bosh::BoshCliError, Resolv::ResolvError => e
puts "Error detected while filtering bosh director releases"
errors.store("Bosh director", e)
releases_not_uploaded_to_director = {}
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. Open
while line = stdout_stderr.gets
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
Example:
# bad
if some_var = true
do_something
end
Example:
# good
if some_var == true
do_something
end
Place the end statement of a multi-line method on its own line. Open
class CloneError < RuntimeError; end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for trailing code after the method definition.
Example:
# bad
def some_method
do_stuff; end
def do_this(x)
baz.map { |b| b.this(x) } end
def foo
block do
bar
end end
# good
def some_method
do_stuff
end
def do_this(x)
baz.map { |b| b.this(x) }
end
def foo
block do
bar
end
end
Unused method argument - logs_path
. If it's necessary, use _
or _logs_path
as an argument name to indicate that it won't be used. Open
def repackage_release(name, destination_dir, working_dir, logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- 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
Unused method argument - logs_path
. If it's necessary, use _
or _logs_path
as an argument name to indicate that it won't be used. Open
def clone_git_repository(boshrelease_name, git_url, base_git_clones_path, logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- 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
Use a guard clause instead of wrapping the code inside a conditional expression. Open
unless errors.empty?
- Read upRead up
- Create a ticketCreate a ticket
- 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
Unused method argument - logs_path
. If it's necessary, use _
or _logs_path
as an argument name to indicate that it won't be used. You can also write as clean_bosh_files(*)
if you want the method to accept any arguments but don't care about them. Open
def clean_bosh_files(logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- 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
Redundant return
detected. Open
return v == target_version.to_s
- Read upRead up
- Create a ticketCreate a ticket
- 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.
Extra empty line detected at class body end. Open
end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cops checks if empty lines around the bodies of classes match the configuration.
Example: EnforcedStyle: empty_lines
# good
class Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
class Foo
class Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
class Foo
def bar; end
end
Example: EnforcedStyle: noemptylines (default)
# good
class Foo
def bar
# ...
end
end
Unused method argument - logs_path
. If it's necessary, use _
or _logs_path
as an argument name to indicate that it won't be used. Open
def clean_git_clone(git_clone_path, logs_path)
- Read upRead up
- Create a ticketCreate a ticket
- 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