Showing 58 of 58 total issues
Identical blocks of code found in 2 locations. Consider refactoring. Open
def get_total_space(storage)
total_space = 0
disks = storage[:physical_disks]
disks&.each { |disk| total_space += disk[:disk_size].to_i }
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 25.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
def parse_network(assignment, is_ipv6 = false)
{
:subnet_mask => assignment['subnet'],
:default_gateway => assignment['gateway'],
:ipaddress => (assignment['address'] unless is_ipv6),
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 25.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
def parse_network(assignment, is_ipv6 = false)
{
:subnet_mask => assignment['subnet'],
:default_gateway => assignment['gateway'],
:ipaddress => (assignment['address'] unless is_ipv6),
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 25.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Useless assignment to variable - version_parser
. Open
version_parser = @version.match(/^(?:(\d+)\.?(\d+))/).to_s if @version.present? # getting just major and minor version
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
NOTE: Given the assignment foo = 1, bar = 2
, removing unused variables
can lead to a syntax error, so this case is not autocorrected.
Safety:
This cop's autocorrection is unsafe because removing assignment from
operator assignment can cause NameError if this assignment has been used to declare
local variable. For example, replacing a ||= 1
to a || 1
may cause
"undefined local variable or method `a' for main:Object (NameError)".
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Do not chain ordinary method call after safe navigation operator. Open
ip_interfaces&.flat_map { |interface| interface[key] }
.select { |assignment| address_list.include?(assignment['address']) }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
The safe navigation operator returns nil if the receiver is nil. If you chain an ordinary method call after a safe navigation operator, it raises NoMethodError. We should use a safe navigation operator after a safe navigation operator. This cop checks for the problem outlined above.
Example:
# bad
x&.foo.bar
x&.foo + bar
x&.foo[bar]
Example:
# good
x&.foo&.bar
x&.foo || bar
Use filter_map
instead. Open
persisted_results.collect do |persisted_result|
if persisted_result.xITEs.present?
map_by_uuid(persisted_result.xITEs)
elsif persisted_result.racklist.present?
map_by_uuid(persisted_result.racklist)
- Create a ticketCreate a ticket
- Exclude checks
Method ManageIQ::Providers::Lenovo::PhysicalInfraManager::Parser::PhysicalStorageParser.get_total_space
is defined at both app/models/manageiq/providers/lenovo/physical_infra_manager/parser/physical_storage_parser.rb:107 and app/models/manageiq/providers/lenovo/physical_infra_manager/parser/physical_storage_parser.rb:118. Open
def get_total_space(storage)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for duplicated instance (or singleton) method definitions.
Example:
# bad
def foo
1
end
def foo
2
end
Example:
# bad
def foo
1
end
alias foo bar
Example:
# good
def foo
1
end
def bar
2
end
Example:
# good
def foo
1
end
alias bar foo
Do not chain ordinary method call after safe navigation operator. Open
ip_interfaces&.flat_map { |interface| interface[key] }
.select { |assignment| address_list.include?(assignment['address']) }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
The safe navigation operator returns nil if the receiver is nil. If you chain an ordinary method call after a safe navigation operator, it raises NoMethodError. We should use a safe navigation operator after a safe navigation operator. This cop checks for the problem outlined above.
Example:
# bad
x&.foo.bar
x&.foo + bar
x&.foo[bar]
Example:
# good
x&.foo&.bar
x&.foo || bar
Use String#include?
instead of a regex match with literal-only pattern. Open
device['class'] == 'Network controller' || device_name =~ /nic/ || device_name =~ /ethernet/
- Create a ticketCreate a ticket
- Exclude checks
Use String#include?
instead of a regex match with literal-only pattern. Open
device["class"] == "Mass storage controller" || device_name =~ /serveraid/ || device_name =~ /sd media raid/
- Create a ticketCreate a ticket
- Exclude checks
Use String#include?
instead of a regex match with literal-only pattern. Open
device['class'] == 'Network controller' || device_name =~ /nic/ || device_name =~ /ethernet/
- Create a ticketCreate a ticket
- Exclude checks
Use String#include?
instead of a regex match with literal-only pattern. Open
device['class'] == 'Network controller' || device_name =~ /nic/ || device_name =~ /ethernet/
- Create a ticketCreate a ticket
- Exclude checks
Use filter_map
instead. Open
persisted_results.collect do |persisted_result|
if persisted_result.xITEs.present?
map_by_uuid(persisted_result.xITEs)
elsif persisted_result.racklist.present?
map_by_uuid(persisted_result.racklist)
- Create a ticketCreate a ticket
- Exclude checks
Use String#include?
instead of a regex match with literal-only pattern. Open
device['class'] == 'Network controller' || device_name =~ /nic/ || device_name =~ /ethernet/
- Create a ticketCreate a ticket
- Exclude checks
Use String#include?
instead of a regex match with literal-only pattern. Open
device["class"] == "Mass storage controller" || device_name =~ /serveraid/ || device_name =~ /sd media raid/
- Create a ticketCreate a ticket
- Exclude checks
Wrap expressions with varying precedence with parentheses to avoid ambiguity. Open
@limit = @last_cn * @events_pool_percentage + offset
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Looks for expressions containing multiple binary operators
where precedence is ambiguous due to lack of parentheses. For example,
in 1 + 2 * 3
, the multiplication will happen before the addition, but
lexically it appears that the addition will happen first.
The cop does not consider unary operators (ie. !a
or -b
) or comparison
operators (ie. a =~ b
) because those are not ambiguous.
NOTE: Ranges are handled by Lint/AmbiguousRange
.
Example:
# bad
a + b * c
a || b && c
a ** b + c
# good (different precedence)
a + (b * c)
a || (b && c)
(a ** b) + c
# good (same precedence)
a + b + c
a * b / c % d
Use String#include?
instead of a regex match with literal-only pattern. Open
device["class"] == "Mass storage controller" || device_name =~ /serveraid/ || device_name =~ /sd media raid/
- Create a ticketCreate a ticket
- Exclude checks
Use String#include?
instead of a regex match with literal-only pattern. Open
device["class"] == "Mass storage controller" || device_name =~ /serveraid/ || device_name =~ /sd media raid/
- Create a ticketCreate a ticket
- Exclude checks