Method ask_for_disk
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def ask_for_disk(disk_name, verify = true, silent = false)
require "linux_admin"
disks = LinuxAdmin::Disk.local.select { |d| d.partitions.empty? }
if disks.empty?
- 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 just_ask
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def just_ask(prompt, default = nil, validate = nil, error_text = nil, klass = nil)
ask("Enter the #{prompt}: ", klass) do |q|
q.readline = true
q.default = default.to_s if default
q.validate = validate if validate
- 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 ask_for_password
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def ask_for_password(prompt, default = nil)
pass = just_ask(prompt, default.present? ? "********" : nil) do |q|
q.echo = '*'
yield q if block_given?
end
- 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 ask_for_domain
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def ask_for_domain(prompt, default = nil, validate = DOMAIN_REGEXP, error_text = "a valid Domain.", &block)
- Create a ticketCreate a ticket
Method ask_for_ip
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def ask_for_ip(prompt, default, validate = IP_REGEXP, error_text = "a valid IP Address.", &block)
- Create a ticketCreate a ticket
Method ask_for_many
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def ask_for_many(prompt, collective = nil, default = nil, max_length = 255, max_count = 6)
- Create a ticketCreate a ticket
Method ask_for_hostname
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def ask_for_hostname(prompt, default = nil, validate = HOSTNAME_REGEXP, error_text = "a valid Hostname.", &block)
- Create a ticketCreate a ticket
Method just_ask
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def just_ask(prompt, default = nil, validate = nil, error_text = nil, klass = nil)
- Create a ticketCreate a ticket
Method default_to_index
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def default_to_index(default, options)
return unless default
default_index = if options.kind_of?(Hash)
options.values.index(default) || options.keys.index(default)
else
- 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 has too many optional parameters. [4/3] Open
def ask_for_many(prompt, collective = nil, default = nil, max_length = 255, max_count = 6)
collective ||= "#{prompt}s"
validate = ->(p) { (p.length < max_length) && (p.split(/[\s,;]+/).length <= max_count) }
error_message = "up to #{max_count} #{prompt}s separated by a space and up to #{max_length} characters"
just_ask(collective, default, validate, error_message).split(/[\s,;]+/).collect(&:strip)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for methods with too many parameters.
The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count, as they add less complexity than positional or optional parameters.
Any number of arguments for initialize
method inside a block of
Struct.new
and Data.define
like this is always allowed:
Struct.new(:one, :two, :three, :four, :five, keyword_init: true) do
def initialize(one:, two:, three:, four:, five:)
end
end
This is because checking the number of arguments of the initialize
method
does not make sense.
NOTE: Explicit block argument &block
is not counted to prevent
erroneous change that is avoided by making block argument implicit.
Example: Max: 3
# good
def foo(a, b, c = 1)
end
Example: Max: 2
# bad
def foo(a, b, c = 1)
end
Example: CountKeywordArgs: true (default)
# counts keyword args towards the maximum
# bad (assuming Max is 3)
def foo(a, b, c, d: 1)
end
# good (assuming Max is 3)
def foo(a, b, c: 1)
end
Example: CountKeywordArgs: false
# don't count keyword args towards the maximum
# good (assuming Max is 3)
def foo(a, b, c, d: 1)
end
This cop also checks for the maximum number of optional parameters.
This can be configured using the MaxOptionalParameters
config option.
Example: MaxOptionalParameters: 3 (default)
# good
def foo(a = 1, b = 2, c = 3)
end
Example: MaxOptionalParameters: 2
# bad
def foo(a = 1, b = 2, c = 3)
end
Method ask_with_menu
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def ask_with_menu(prompt, options, default = nil, clear_screen_after = true)
say("#{prompt}\n\n")
default = default_to_index(default, options)
selection = 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 ask_for_uri
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def ask_for_uri(prompt, expected_scheme, opts = {})
require 'uri'
just_ask(prompt, nil, nil, 'a valid URI') do |q|
q.validate = lambda do |a|
# Convert all backslashes in the URI to forward slashes and strip whitespace
- 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 has too many optional parameters. [4/3] Open
def just_ask(prompt, default = nil, validate = nil, error_text = nil, klass = nil)
ask("Enter the #{prompt}: ", klass) do |q|
q.readline = true
q.default = default.to_s if default
q.validate = validate if validate
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for methods with too many parameters.
The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count, as they add less complexity than positional or optional parameters.
Any number of arguments for initialize
method inside a block of
Struct.new
and Data.define
like this is always allowed:
Struct.new(:one, :two, :three, :four, :five, keyword_init: true) do
def initialize(one:, two:, three:, four:, five:)
end
end
This is because checking the number of arguments of the initialize
method
does not make sense.
NOTE: Explicit block argument &block
is not counted to prevent
erroneous change that is avoided by making block argument implicit.
Example: Max: 3
# good
def foo(a, b, c = 1)
end
Example: Max: 2
# bad
def foo(a, b, c = 1)
end
Example: CountKeywordArgs: true (default)
# counts keyword args towards the maximum
# bad (assuming Max is 3)
def foo(a, b, c, d: 1)
end
# good (assuming Max is 3)
def foo(a, b, c: 1)
end
Example: CountKeywordArgs: false
# don't count keyword args towards the maximum
# good (assuming Max is 3)
def foo(a, b, c, d: 1)
end
This cop also checks for the maximum number of optional parameters.
This can be configured using the MaxOptionalParameters
config option.
Example: MaxOptionalParameters: 3 (default)
# good
def foo(a = 1, b = 2, c = 3)
end
Example: MaxOptionalParameters: 2
# bad
def foo(a = 1, b = 2, c = 3)
end
Method ask_yn?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def ask_yn?(prompt, default = nil)
ask("#{prompt}? (Y/N): ") do |q|
q.default = default if default
q.validate = ->(p) { (p.blank? && default) || %w(y n).include?(p.downcase[0]) }
q.responses[:not_valid] = "Please provide yes or no."
- 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"