app/presenters/tabular_data/container.rb
Method sort=
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
def sort=(field)
sort_field = field || ""
direction = sort_field.start_with?("-") ? :desc : :asc
field_name = sort_field.gsub(/\A-/, "")
- 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
Use the return of the conditional for variable assignment and comparison. Open
Open
if config == true
query = join_table(query, klass, table_name)
else
query = query.joins(config)
end
- Exclude checks
self
used in void context. Open
Open
self
- Read upRead up
- Exclude checks
This cop checks for operators, variables and literals used in void context.
Example:
# bad
def some_method
some_num * 10
do_something
end
Example:
# bad
def some_method(some_var)
some_var
do_something
end
Example:
# good
def some_method
do_something
some_num * 10
end
Example:
# good
def some_method(some_var)
do_something
some_var
end