Showing 116 of 116 total issues
Method _find_all
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _find_all(name, prefix, partial, details, key, locals)
Similar blocks of code found in 2 locations. Consider refactoring. Open
def modify_author_service(namespace = nil)
author_service =
if namespace
"admin/app/services/admin/author_service.rb"
else
- Read upRead up
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 34.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
def modify_article_service(namespace = nil)
article_service =
if namespace
"admin/app/services/admin/article_service.rb"
else
- Read upRead up
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 34.
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
Method column_value
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def column_value(resource, attribute)
partial_override "#{controller_path}/columns/#{attribute}", resource: resource do
column_value = resource.send(attribute)
if column_value.is_a?(Date) || column_value.is_a?(Time)
- 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 parameter lists longer than 5 parameters. [6/5] Open
def _find_all(name, prefix, partial, details, key, locals)
- Read upRead up
- Exclude checks
This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.
Method perform_batch_action
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def perform_batch_action
return unless params[:batch_action].present?
set_resource_service
set_resource_class
- 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
unexpected token tCONSTANT
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
class <%= class_name %>Service
- Exclude checks
unexpected token tGT
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
attrs_for_show <%= @attributes.map { |x| ":#{x}" }.join(", ") %>
- Exclude checks
unexpected token kEND
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
end
- Exclude checks
Use delegate
to define delegations. Open
def root
- Read upRead up
- Exclude checks
This cop looks for delegations that could have been created
automatically with the delegate
method.
Safe navigation &.
is ignored because Rails' allow_nil
option checks not just for nil but also delegates if nil
responds to the delegated method.
The EnforceForPrefixed
option (defaulted to true
) means that
using the target object as a prefix of the method name
without using the delegate
method will be a violation.
When set to false
, this case is legal.
Example:
# bad
def bar
foo.bar
end
# good
delegate :bar, to: :foo
# good
def bar
foo&.bar
end
# good
private
def bar
foo.bar
end
# EnforceForPrefixed: true
# bad
def foo_bar
foo.bar
end
# good
delegate :bar, to: :foo, prefix: true
# EnforceForPrefixed: false
# good
def foo_bar
foo.bar
end
# good
delegate :bar, to: :foo, prefix: true
Use %r
around regular expression. Open
prefix.sub(/\A#{@controller_path}/, "resource").sub(/\A\//, "")
- Read upRead up
- Exclude checks
This cop enforces using // or %r around regular expressions.
Example: EnforcedStyle: slashes (default)
# bad
snake_case = %r{^[\dA-Z_]+$}
# bad
regex = %r{
foo
(bar)
(baz)
}x
# good
snake_case = /^[\dA-Z_]+$/
# good
regex = /
foo
(bar)
(baz)
/x
Example: EnforcedStyle: percent_r
# bad
snake_case = /^[\dA-Z_]+$/
# bad
regex = /
foo
(bar)
(baz)
/x
# good
snake_case = %r{^[\dA-Z_]+$}
# good
regex = %r{
foo
(bar)
(baz)
}x
Example: EnforcedStyle: mixed
# bad
snake_case = %r{^[\dA-Z_]+$}
# bad
regex = /
foo
(bar)
(baz)
/x
# good
snake_case = /^[\dA-Z_]+$/
# good
regex = %r{
foo
(bar)
(baz)
}x
Example: AllowInnerSlashes: false (default)
# If `false`, the cop will always recommend using `%r` if one or more
# slashes are found in the regexp string.
# bad
x =~ /home\//
# good
x =~ %r{home/}
Example: AllowInnerSlashes: true
# good
x =~ /home\//
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if @object.has_attribute?(attribute)
- 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
Rename has_many_map
to many_map?
. Open
def has_many_map
- Read upRead up
- Exclude checks
This cop makes sure that predicates are named properly.
Example:
# bad
def is_even?(value)
end
# good
def even?(value)
end
# bad
def has_value?
end
# good
def value?
end
Use meaningful heredoc delimiters. Open
END
- 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
Use nested module/class definitions instead of compact style. Open
class Godmin::InstallGenerator < Godmin::Generators::Base
- Read upRead up
- Exclude checks
This cop checks the style of children definitions at classes and modules. Basically there are two different styles:
Example: EnforcedStyle: nested (default)
# good
# have each child on its own line
class Foo
class Bar
end
end
Example: EnforcedStyle: compact
# good
# combine definitions as much as possible
class Foo::Bar
end
The compact style is only forced for classes/modules with one child.
unterminated string meets end of file
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
require_dependency "<%= File.join(namespaced_path, "application_controller") %>"
- Exclude checks
unexpected token tLT
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
class <%= class_name %> < ::<%= class_name %>
- Exclude checks
unexpected token tCONSTANT
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
class <%= class_name %>Policy < Godmin::Authorization::Policy
- Exclude checks
unterminated string meets end of file
(Using Ruby 2.1 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
<% end -%>
- Exclude checks
Indent the first parameter one step more than options.deep_merge(
. Open
value: datetime_value(attribute, options, :datetimepicker),
data: { behavior: "datetimepicker" }
- Read upRead up
- Exclude checks
This cop checks the indentation of the first parameter in a method call. Parameters after the first one are checked by Style/AlignParameters, not by this cop.
Example:
# bad
some_method(
first_param,
second_param)
# good
some_method(
first_param,
second_param)