Showing 74 of 74 total issues
Method select
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def select(keystr = nil, config_name = nil)
prefix = [keystr, config_name].join(' ').strip
regex = /^(?<no>no )?#{Regexp.escape(prefix)} ?(?<data>.+)?/
io = StringIO.open(@nested_config)
- 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 connect
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
def connect
@session = Class.new do
def initialize
@closed = false
end
Method connect
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def connect
Net::SSH.start(@host, @user, @ssh_opts) do |session|
@session = session
@session.open_channel do |channel|
channel.send_channel_request('shell') do |ch, ch_success|
- 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 config_exec
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def config_exec(command, opts = {})
must_be_connected!
enable! if @terminal.prompt =~ EXEC_PROMPT
expect_prompt = opts.fetch(:expect_prompt, CONFIG_PROMPT)
- 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 connect
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def connect
Net::SSH.start(@host, @user, @ssh_opts) do |session|
@session = session
@session.open_channel do |channel|
channel.send_channel_request('shell') do |ch, ch_success|
Method select
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def select(keystr = nil, config_name = nil)
prefix = [keystr, config_name].join(' ').strip
regex = /^(?<no>no )?#{Regexp.escape(prefix)} ?(?<data>.+)?/
io = StringIO.open(@nested_config)
Method expect
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def expect(prompt_regex)
@last_output_received = Time.now.getlocal
while buffer !~ prompt_regex
begin
- 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 version_match_parse
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def self.version_match_parse(expr)
expr = expr.to_s # Forgive users who provide a number instead of a string
m = VERSION_EXPR_REGEX.match(expr)
fail Error::InvalidExpressionError, "Expression '#{expr}' is not valid" unless m
opr = m[:opr]
- 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 running_config
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def running_config(subcmd = nil)
unless @running_config.key? subcmd
output = subcmd ? show('running-config ' + subcmd) : show('running-config')
@running_config[subcmd] = Config.new(nested_config: output)
end
- 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 initialize
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def initialize(terminal_opts, enable_password = nil)
@asa = ASAConsole.ssh(terminal_opts)
@asa.enable_password = enable_password if enable_password
@asa.terminal.on_output do |prompt, input, output|
print Test.colorize(prompt, :prompt) if prompt
- 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 names_of
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def names_of(keystr)
names = []
regex = /^(?:no )?#{Regexp.escape(keystr)} (?<name>\S+)/
@nested_config.each_line do |line|
m = regex.match(line)
- 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 disconnect
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def disconnect
while @terminal.connected? && @terminal.prompt =~ ANY_EXEC_PROMPT
@terminal.send('exit', ANY_EXEC_PROMPT) { |success| break unless success }
end
@terminal.disconnect
- 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
Block has too many lines. [27/25] Open
@channel = Class.new do
attr_reader :terminal
def initialize(terminal)
@terminal = terminal
@input_buffer = ''
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Method version_match_compare
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.version_match_compare(opr, ver, pattern)
a = ver[0..(pattern.length - 1)]
b = pattern.clone
eq = true
gt = lt = false
- 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 line
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def line
parts = []
parts << 'no' if @negated
parts << @keystr if @keystr
parts << @config_name if @config_name
- 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
Do not use space inside array brackets. Open
[ '--show-session-log', '-s', GetoptLong::NO_ARGUMENT ],
- Read upRead up
- Exclude checks
Checks that brackets used for array literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that array literals have
# surrounding space.
# bad
array = [a, b, c, d]
# good
array = [ a, b, c, d ]
Example: EnforcedStyle: no_space
# The `no_space` style enforces that array literals have
# no surrounding space.
# bad
array = [ a, b, c, d ]
# good
array = [a, b, c, d]
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# array brackets, with the exception that successive left
# or right brackets are collapsed together in nested arrays.
# bad
array = [ a, [ b, c ] ]
# good
array = [ a, [ b, c ]]
Prefer annotated tokens (like %<foo>s</foo>
) over unannotated tokens (like %s
). Open
message = "Will not execute command in '%s' mode (expected '%s')"
- Read upRead up
- Exclude checks
Use a consistent style for named format string tokens.
Note:
unannotated
style cop only works for strings
which are passed as arguments to those methods:
sprintf
, format
, %
.
The reason is that unannotated format is very similar
to encoded URLs or Date/Time formatting strings.
Example: EnforcedStyle: annotated (default)
# bad
format('%{greeting}', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%<greeting>s', greeting: 'Hello')</greeting>
Example: EnforcedStyle: template
# bad
format('%<greeting>s', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%{greeting}', greeting: 'Hello')</greeting>
Example: EnforcedStyle: unannotated
# bad
format('%<greeting>s', greeting: 'Hello')
format('%{greeting}', 'Hello')
# good
format('%s', 'Hello')</greeting>
Always use raise
to signal exceptions. Open
fail Error::ConnectFailure 'Failed to parse EXEC prompt', self unless success
- Read upRead up
- Exclude checks
This cop checks for uses of fail
and raise
.
Example: EnforcedStyle: only_raise (default)
# The `only_raise` style enforces the sole use of `raise`.
# bad
begin
fail
rescue Exception
# handle it
end
def watch_out
fail
rescue Exception
# handle it
end
Kernel.fail
# good
begin
raise
rescue Exception
# handle it
end
def watch_out
raise
rescue Exception
# handle it
end
Kernel.raise
Example: EnforcedStyle: only_fail
# The `only_fail` style enforces the sole use of `fail`.
# bad
begin
raise
rescue Exception
# handle it
end
def watch_out
raise
rescue Exception
# handle it
end
Kernel.raise
# good
begin
fail
rescue Exception
# handle it
end
def watch_out
fail
rescue Exception
# handle it
end
Kernel.fail
Example: EnforcedStyle: semantic
# The `semantic` style enforces the use of `fail` to signal an
# exception, then will use `raise` to trigger an offense after
# it has been rescued.
# bad
begin
raise
rescue Exception
# handle it
end
def watch_out
# Error thrown
rescue Exception
fail
end
Kernel.fail
Kernel.raise
# good
begin
fail
rescue Exception
# handle it
end
def watch_out
fail
rescue Exception
raise 'Preferably with descriptive message'
end
explicit_receiver.fail
explicit_receiver.raise
Use the return of the conditional for variable assignment and comparison. Open
case scheme_key
when :light
@@colors = {
prompt: "\e[1;36m",
input: "\e[1;33m",
- Exclude checks
Prefer annotated tokens (like %<foo>s</foo>
) over unannotated tokens (like %s
). Open
message = "Will not execute command in '%s' mode (expected '%s')"
- Read upRead up
- Exclude checks
Use a consistent style for named format string tokens.
Note:
unannotated
style cop only works for strings
which are passed as arguments to those methods:
sprintf
, format
, %
.
The reason is that unannotated format is very similar
to encoded URLs or Date/Time formatting strings.
Example: EnforcedStyle: annotated (default)
# bad
format('%{greeting}', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%<greeting>s', greeting: 'Hello')</greeting>
Example: EnforcedStyle: template
# bad
format('%<greeting>s', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%{greeting}', greeting: 'Hello')</greeting>
Example: EnforcedStyle: unannotated
# bad
format('%<greeting>s', greeting: 'Hello')
format('%{greeting}', 'Hello')
# good
format('%s', 'Hello')</greeting>