Showing 23 of 23 total issues
Cyclomatic complexity for request_filename is too high. [8/6] Open
def request_filename
if node.root? and node.default_format == format
""
elsif node.root? and format
"#{node.default_name}.#{format}"
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Cyclomatic complexity for resolve_layout is too high. [7/6] Open
def resolve_layout
return resource.data.fetch("layout") if resource.data.key? "layout"
return layout unless has_layout_conditions?
clause, formats = layout_conditions.first
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Method compile
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def compile
before_compile
each do |resource, *args, **kwargs|
if resource.renderable?
render_resource(resource, *args, **kwargs)
- 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 resolve_layout
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def resolve_layout
return resource.data.fetch("layout") if resource.data.key? "layout"
return layout unless has_layout_conditions?
clause, formats = layout_conditions.first
- 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 request_filename
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def request_filename
if node.root? and node.default_format == format
""
elsif node.root? and format
"#{node.default_name}.#{format}"
- 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 controller_layout
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def controller_layout(resource)
private_layout_method = self.method(:_layout)
layout =
if Rails.version >= "6"
private_layout_method.call lookup_context, resource_rails_formats(resource)
- 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 parse_basename
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def parse_basename
base = basename
filename, extname = split_filename(base)
# This is a root path, so we have to treat it a little differently
- 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 kRESCUE
(Using Ruby 2.2 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
rescue
- Exclude checks
Unused method argument - glob
. If it's necessary, use _
or _glob
as an argument name to indicate that it won't be used. You can also write as all(*)
if you want the method to accept any arguments but don't care about them. Open
def self.all(glob = "**/*.gemspec")
- Read upRead up
- 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
unexpected token error
(Using Ruby 2.2 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
format_extension = path.format&.to_s
- Exclude checks
Useless assignment to variable - code
. Use _
or _code
as a variable name to indicate that it won't be used. Open
code, headers, response = rails_app.routes.call env
- Read upRead up
- Exclude checks
This cop 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.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Method Sitepress::Rendition#layout
is defined at both sitepress-rails/lib/sitepress/rendition.rb:6 and sitepress-rails/lib/sitepress/rendition.rb:24. Open
def layout
- Read upRead up
- Exclude checks
This cop checks for duplicated instance (or singleton) method definitions.
Example:
# bad
def duplicated
1
end
def duplicated
2
end
Example:
# bad
def duplicated
1
end
alias duplicated other_duplicated
Example:
# good
def duplicated
1
end
def other_duplicated
2
end
Unused method argument - title_key
. Open
def link_to_page(page, *args, title_key: DEFAULT_TITLE_KEY, **kwargs, &block)
- Read upRead up
- 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 - layout
. Open
def initialize(resource, layout: nil)
- Read upRead up
- 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
unexpected token error
(Using Ruby 2.2 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
(handler_is_format? ? handler : @format)&.to_sym
- Exclude checks
Useless assignment to variable - headers
. Use _
or _headers
as a variable name to indicate that it won't be used. Open
code, headers, response = rails_app.routes.call env
- Read upRead up
- Exclude checks
This cop 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.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
end
at 55, 6 is not aligned with if
at 49, 48. Open
end
- Read upRead up
- Exclude checks
This cop checks whether the end keywords are aligned properly.
Three modes are supported through the EnforcedStyleAlignWith
configuration parameter:
If it's set to keyword
(which is the default), the end
shall be aligned with the start of the keyword (if, class, etc.).
If it's set to variable
the end
shall be aligned with the
left-hand-side of the variable assignment, if there is one.
If it's set to start_of_line
, the end
shall be aligned with the
start of the line where the matching keyword appears.
Example: EnforcedStyleAlignWith: keyword (default)
# bad
variable = if true
end
# good
variable = if true
end
Example: EnforcedStyleAlignWith: variable
# bad
variable = if true
end
# good
variable = if true
end
Example: EnforcedStyleAlignWith: startofline
# bad
variable = if true
end
# good
puts(if true
end)
Method Sitepress::Resource.path_suffix_hack_that_you_should_not_use
is defined at both sitepress-core/lib/sitepress/resource.rb:107 and sitepress-core/lib/sitepress/resource.rb:109. Open
def path_suffix_hack_that_you_should_not_use
- Read upRead up
- Exclude checks
This cop checks for duplicated instance (or singleton) method definitions.
Example:
# bad
def duplicated
1
end
def duplicated
2
end
Example:
# bad
def duplicated
1
end
alias duplicated other_duplicated
Example:
# good
def duplicated
1
end
def other_duplicated
2
end
unexpected token error
(Using Ruby 2.2 parser; configure using TargetRubyVersion
parameter, under AllCops
) Open
format&.to_sym
- Exclude checks
TODO found Open
# TODO: When `type: :all` is scoped, some queries will mistakenly return single resources.
- Exclude checks