Method count
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def count
res = client.body.match(%r{<a.*class="count">(.*)<\/span><\/a>})
return 0 if res.nil?
count = res[1]
- 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
Line is too long. [131/120] Open
@client = Net::HTTP.get_response(URI("https://nhentai.net/#{class_name}/#{keyword.tr(' ', '-')}/#{SORT[sort]}?page=#{page}"))
- Read upRead up
- Exclude checks
Checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/IndentationStyle
cop.
It also ignores a shebang line by default.
This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.
If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)
- ArgumentAlignment
- ArrayAlignment
- BlockAlignment
- BlockDelimiters
- BlockEndNewline
- ClosingParenthesisIndentation
- FirstArgumentIndentation
- FirstArrayElementIndentation
- FirstHashElementIndentation
- FirstParameterIndentation
- HashAlignment
- IndentationWidth
- MultilineArrayLineBreaks
- MultilineBlockLayout
- MultilineHashBraceLayout
- MultilineHashKeyLineBreaks
- MultilineMethodArgumentLineBreaks
- MultilineMethodParameterLineBreaks
- ParameterAlignment
Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:
Example:
# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}
# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}
# good (with recommended cops enabled)
{
foo: "0000000000",
bar: "0000000000",
baz: "0000000000",
}
Redundant escape inside regexp literal Open
res = client.body.match(%r{<a.*class="count">(.*)<\/span><\/a>})
- Read upRead up
- Exclude checks
Checks for redundant escapes inside Regexp literals.
Example:
# bad
%r{foo\/bar}
# good
%r{foo/bar}
# good
/foo\/bar/
# good
%r/foo\/bar/
# good
%r!foo\!bar!
# bad
/a\-b/
# good
/a-b/
# bad
/[\+\-]\d/
# good
/[+\-]\d/
Redundant escape inside regexp literal Open
res = client.body.match(%r{<a.*class="count">(.*)<\/span><\/a>})
- Read upRead up
- Exclude checks
Checks for redundant escapes inside Regexp literals.
Example:
# bad
%r{foo\/bar}
# good
%r{foo/bar}
# good
/foo\/bar/
# good
%r/foo\/bar/
# good
%r!foo\!bar!
# bad
/a\-b/
# good
/a-b/
# bad
/[\+\-]\d/
# good
/[+\-]\d/
Redundant escape inside regexp literal Open
res = client.body.split(%r{<div class="gallery".+?>(.*?)<\/div>}).select { |line| line.include?('<a href="/g/') }
- Read upRead up
- Exclude checks
Checks for redundant escapes inside Regexp literals.
Example:
# bad
%r{foo\/bar}
# good
%r{foo/bar}
# good
/foo\/bar/
# good
%r/foo\/bar/
# good
%r!foo\!bar!
# bad
/a\-b/
# good
/a-b/
# bad
/[\+\-]\d/
# good
/[+\-]\d/