Method walk
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def self.walk(node, parents = "")
tags = []
sep = "/"
case node.name
- Read upRead up
- Create a ticketCreate a ticket
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 walk
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.walk(node, parents = "")
tags = []
sep = "/"
case node.name
- Create a ticketCreate a ticket
Method findNamedElement
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def self.findNamedElement(findStr, ele)
ele.each_element do |e|
if e.name == "value" && e.attributes['name'].downcase == findStr.downcase
return e.text
end # if
- Read upRead up
- Create a ticketCreate a ticket
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 element2hash
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def self.element2hash(doc, path)
obj = {}
doc.find_each(path + "/*") do |element|
text = element.text
text = "" if text.nil?
- Read upRead up
- Create a ticketCreate a ticket
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 findNamedElement_hash
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def self.findNamedElement_hash(findStr, ele)
ele.each_element do |e|
if e.name == :value && e.attributes[:name].downcase == findStr.downcase
return e.text
end # if
- Read upRead up
- Create a ticketCreate a ticket
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 findElementInt
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def self.findElementInt(paths, ele)
if paths.length > 0
searchStr = paths[0]
paths = paths[1..paths.length]
# puts "Search String: #{searchStr}"
- Read upRead up
- Create a ticketCreate a ticket
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 :value
instead of "value"
. Open
if e.respond_to?("value")
- Create a ticketCreate a ticket
- Exclude checks
Odd else
layout detected. Did you mean to use elsif
? Open
else break
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for odd else
block layout - like
having an expression on the same line as the else
keyword,
which is usually a mistake.
Its autocorrection tweaks layout to keep the syntax. So, this autocorrection
is compatible correction for bad case syntax, but if your code makes a mistake
with elsif
and else
, you will have to correct it manually.
Example:
# bad
if something
# ...
else do_this
do_that
end
Example:
# good
# This code is compatible with the bad case. It will be autocorrected like this.
if something
# ...
else
do_this
do_that
end
# This code is incompatible with the bad case.
# If `do_this` is a condition, `elsif` should be used instead of `else`.
if something
# ...
elsif do_this
do_that
end
Shadowing outer local variable - h
. Open
h.each_with_object({}) { |(k, v), h| h[k.to_s] = remove_invalid_chars(v.to_s.encode('UTF-8', :undef => :replace, :invalid => :replace, :replace => '')) }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for the use of local variable names from an outer scope
in block arguments or block-local variables. This mirrors the warning
given by ruby -cw
prior to Ruby 2.6:
"shadowing outer local variable - foo".
NOTE: Shadowing of variables in block passed to Ractor.new
is allowed
because Ractor
should not access outer variables.
eg. following style is encouraged:
```ruby
worker_id, pipe = env
Ractor.new(worker_id, pipe) do |worker_id, pipe|
end
```
Example:
# bad
def some_method
foo = 1
2.times do |foo| # shadowing outer `foo`
do_something(foo)
end
end
Example:
# good
def some_method
foo = 1
2.times do |bar|
do_something(bar)
end
end
Avoid when
branches without a body. Open
when *REXML::Text::VALID_CHAR
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for the presence of when
branches without a body.
Example:
# bad
case foo
when bar
do_something
when baz
end
Example:
# good
case condition
when foo
do_something
when bar
nil
end
Example: AllowComments: true (default)
# good
case condition
when foo
do_something
when bar
# noop
end
Example: AllowComments: false
# bad
case condition
when foo
do_something
when bar
# do nothing
end