samples/smelly_source/ruby.rb
Method scan_tokens
has a Cognitive Complexity of 273 (exceeds 5 allowed). Consider refactoring. Open
Open
def scan_tokens tokens, options
last_token_dot = false
value_expected = true
heredocs = nil
last_state = nil
- 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 scan_tokens
has 283 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def scan_tokens tokens, options
last_token_dot = false
value_expected = true
heredocs = nil
last_state = nil
File ruby.rb
has 296 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
module CodeRay
module Scanners
# This scanner is really complex, since Ruby _is_ a complex language!
#
Avoid deeply nested control flow statements. Open
Open
case m = getch
when state.delim, '\\'
tokens << [match + m, :char]
when nil
tokens << [match, :error]
Avoid deeply nested control flow statements. Open
Open
tokens << [modifiers, :modifier] unless modifiers.empty?
Avoid deeply nested control flow statements. Open
Open
elsif match = scan(/\#.*/) or
( bol? and match = scan(/#{patterns::RUBYDOC_OR_DATA}/o) )
kind = :comment
value_expected = true
tokens << [match, kind]
Avoid deeply nested control flow statements. Open
Open
if esc = scan(/ #{patterns::ESCAPE} /ox)
tokens << [match + esc, :char]
else
tokens << [match, :error]
end
Avoid deeply nested control flow statements. Open
Open
if heredocs
unscan # heredoc scanning needs \n at start
state = heredocs.shift
tokens << [:open, state.type]
heredocs = nil if heredocs.empty?
Avoid deeply nested control flow statements. Open
Open
if match == "\n"
value_expected = true # FIXME not quite true
state = :initial if state == :undef_comma_expected
end
Avoid deeply nested control flow statements. Open
Open
if state.paren_depth > 0
tokens << [match, :nesting_delimiter]
next
end