Method install_users
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def install_users(name:)
if (resp = existing_validation(name: name)).net_status_ok?
mapper = index[name].inheritance_mapper
# user / group
- 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
Method has too many lines. [40/38] Open
def install_users(name:)
if (resp = existing_validation(name: name)).net_status_ok?
mapper = index[name].inheritance_mapper
# user / group
- 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.
Method install_users
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def install_users(name:)
if (resp = existing_validation(name: name)).net_status_ok?
mapper = index[name].inheritance_mapper
# user / group
Method install_data
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def install_data(name:, model: nil)
etc_mapper = @config.containers.f(name)
if (model_ = model || etc_mapper.f('model', default: @config.default_model)).nil?
{ error: :input_error, code: :no_model_given }
else
- 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
Method stop_mux
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def stop_mux(name:)
if (resp = existing_validation(name: name)).net_status_ok?
mapper = index[name].inheritance_mapper
if (mux_mapper = mapper.mux).file?
- 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
Rename has_sites?
to sites?
. Open
def has_sites?(name:)
- 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 a guard clause instead of wrapping the code inside a conditional expression. Open
if has_sites?(name: name)
- 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
Don't use parentheses around a method call. Open
if (existing_validation(name: name)).net_status_ok? && model && index[name].model_name != model
- Read upRead up
- Exclude checks
This cop checks for redundant parentheses.
Example:
# bad
(x) if ((y.z).nil?)
# good
x if y.z.nil?