Showing 19 of 19 total issues
File ontap_method_map.rb
has 640 lines of code (exceeds 250 allowed). Consider refactoring. Open
module NetAppManageability
module OntapMethodMap
METHOD_MAP = {
:aggr_add => "aggr-add",
:aggr_check_spare_low => "aggr-check-spare-low",
Method method_missing
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def method_missing(method_name, *args)
key = method_name.to_s.sub(/^#{STRIP_PREFIX}/, "").tr('_', '-')
if key[-1, 1] == '='
return (self[key[0...-1]] = args[0]) unless @sym_keys
return (self[key[0...-1].to_sym] = args[0])
- 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 method_missing
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def method_missing(method_name, *args, &block)
cmd = map_method(method_name.to_sym)
return super if cmd.nil?
ah = 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
Avoid too many return
statements within this method. Open
return self[key.to_sym]
Avoid too many return
statements within this method. Open
return self[key] unless @sym_keys
Extract this regexp into a constant, memoize it, or append an /o
option to its options. Open
key = method_name.to_s.sub(/^#{STRIP_PREFIX}/, "").tr('_', '-')
- Exclude checks
Use yield
instead of block.call
. Open
block.arity < 1 ? ah.instance_eval(&block) : block.call(ah)
- Read upRead up
- Exclude checks
This cop identifies the use of a &block
parameter and block.call
where yield
would do just as well.
Example:
# bad
def method(&block)
block.call
end
def another(&func)
func.call 1, 2, 3
end
# good
def method
yield
end
def another
yield 1, 2, 3
end
Avoid hard coding large quantities of data in code. Prefer reading the data from an external source. Open
METHOD_MAP = {
:aggr_add => "aggr-add",
:aggr_check_spare_low => "aggr-check-spare-low",
:aggr_create => "aggr-create",
:aggr_destroy => "aggr-destroy",
- Read upRead up
- Exclude checks
Checks for literals with extremely many entries. This is indicative of configuration or data that may be better extracted somewhere else, like a database, fetched from an API, or read from a non-code file (CSV, JSON, YAML, etc.).
Example:
# bad
# Huge Array literal
[1, 2, '...', 999_999_999]
# bad
# Huge Hash literal
{ 1 => 1, 2 => 2, '...' => '...', 999_999_999 => 999_999_999}
# bad
# Huge Set "literal"
Set[1, 2, '...', 999_999_999]
# good
# Reasonably sized Array literal
[1, 2, '...', 10]
# good
# Reading huge Array from external data source
# File.readlines('numbers.txt', chomp: true).map!(&:to_i)
# good
# Reasonably sized Hash literal
{ 1 => 1, 2 => 2, '...' => '...', 10 => 10}
# good
# Reading huge Hash from external data source
CSV.foreach('numbers.csv', headers: true).each_with_object({}) do |row, hash|
hash[row["key"].to_i] = row["value"].to_i
end
# good
# Reasonably sized Set "literal"
Set[1, 2, '...', 10]
# good
# Reading huge Set from external data source
SomeFramework.config_for(:something)[:numbers].to_set
Use yield
instead of block.call
. Open
block.arity < 1 ? self.instance_eval(&block) : block.call(self)
- Read upRead up
- Exclude checks
This cop identifies the use of a &block
parameter and block.call
where yield
would do just as well.
Example:
# bad
def method(&block)
block.call
end
def another(&func)
func.call 1, 2, 3
end
# good
def method
yield
end
def another
yield 1, 2, 3
end
metadata['rubygems_mfa_required']
must be set to 'true'
. Open
Gem::Specification.new do |spec|
spec.name = "net_app_manageability"
spec.version = NetAppManageability::VERSION
spec.authors = ["Rich Oliveri", "Oleg Barenboim", "Jason Frey"]
spec.email = ["roliveri@redhat.com", "chessbyte@gmail.com", "fryguy9@gmail.com"]
- Read upRead up
- Exclude checks
Requires a gemspec to have rubygems_mfa_required
metadata set.
This setting tells RubyGems that MFA (Multi-Factor Authentication) is required for accounts to be able perform privileged operations, such as (see RubyGems' documentation for the full list of privileged operations):
gem push
gem yank
gem owner --add/remove
- adding or removing owners using gem ownership page
This helps make your gem more secure, as users can be more confident that gem updates were pushed by maintainers.
Example:
# bad
Gem::Specification.new do |spec|
# no `rubygems_mfa_required` metadata specified
end
# good
Gem::Specification.new do |spec|
spec.metadata = {
'rubygems_mfa_required' => 'true'
}
end
# good
Gem::Specification.new do |spec|
spec.metadata['rubygems_mfa_required'] = 'true'
end
# bad
Gem::Specification.new do |spec|
spec.metadata = {
'rubygems_mfa_required' => 'false'
}
end
# good
Gem::Specification.new do |spec|
spec.metadata = {
'rubygems_mfa_required' => 'true'
}
end
# bad
Gem::Specification.new do |spec|
spec.metadata['rubygems_mfa_required'] = 'false'
end
# good
Gem::Specification.new do |spec|
spec.metadata['rubygems_mfa_required'] = 'true'
end
Useless assignment to variable - rv
. Open
rv = netapp_client.options_set do
- Read upRead up
- Exclude checks
Checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
NOTE: Given the assignment foo = 1, bar = 2
, removing unused variables
can lead to a syntax error, so this case is not autocorrected.
Safety:
This cop's autocorrection is unsafe because removing assignment from
operator assignment can cause NameError if this assignment has been used to declare
local variable. For example, replacing a ||= 1
to a || 1
may cause
"undefined local variable or method `a' for main:Object (NameError)".
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Useless assignment to variable - rv
. Open
rv = netapp_client.nfs_exportfs_modify_rule do
- Read upRead up
- Exclude checks
Checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
NOTE: Given the assignment foo = 1, bar = 2
, removing unused variables
can lead to a syntax error, so this case is not autocorrected.
Safety:
This cop's autocorrection is unsafe because removing assignment from
operator assignment can cause NameError if this assignment has been used to declare
local variable. For example, replacing a ||= 1
to a || 1
may cause
"undefined local variable or method `a' for main:Object (NameError)".
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Useless assignment to variable - rv
. Open
rv = netapp_client.nfs_exportfs_modify_rule do
- Read upRead up
- Exclude checks
Checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
NOTE: Given the assignment foo = 1, bar = 2
, removing unused variables
can lead to a syntax error, so this case is not autocorrected.
Safety:
This cop's autocorrection is unsafe because removing assignment from
operator assignment can cause NameError if this assignment has been used to declare
local variable. For example, replacing a ||= 1
to a || 1
may cause
"undefined local variable or method `a' for main:Object (NameError)".
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Useless assignment to variable - rv
. Open
rv = netapp_client.volume_create do
- Read upRead up
- Exclude checks
Checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
NOTE: Given the assignment foo = 1, bar = 2
, removing unused variables
can lead to a syntax error, so this case is not autocorrected.
Safety:
This cop's autocorrection is unsafe because removing assignment from
operator assignment can cause NameError if this assignment has been used to declare
local variable. For example, replacing a ||= 1
to a || 1
may cause
"undefined local variable or method `a' for main:Object (NameError)".
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Use yield
instead of block.call
. Open
block.arity < 1 ? @options.instance_eval(&block) : block.call(@options)
- Read upRead up
- Exclude checks
This cop identifies the use of a &block
parameter and block.call
where yield
would do just as well.
Example:
# bad
def method(&block)
block.call
end
def another(&func)
func.call 1, 2, 3
end
# good
def method
yield
end
def another
yield 1, 2, 3
end
Useless assignment to variable - rv
. Open
rv = netapp_client.volume_create do
- Read upRead up
- Exclude checks
Checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
NOTE: Given the assignment foo = 1, bar = 2
, removing unused variables
can lead to a syntax error, so this case is not autocorrected.
Safety:
This cop's autocorrection is unsafe because removing assignment from
operator assignment can cause NameError if this assignment has been used to declare
local variable. For example, replacing a ||= 1
to a || 1
may cause
"undefined local variable or method `a' for main:Object (NameError)".
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Parenthesize the param NetAppManageability::NAMHash.new { name rh }
to make sure that the block will be associated with the NetAppManageability::NAMHash.new
method call. Open
push NetAppManageability::NAMHash.new { name rh }
- Read upRead up
- Exclude checks
Checks for ambiguous block association with method when param passed without parentheses.
This cop can customize allowed methods with AllowedMethods
.
By default, there are no methods to allowed.
Example:
# bad
some_method a { |val| puts val }
Example:
# good
# With parentheses, there's no ambiguity.
some_method(a { |val| puts val })
# or (different meaning)
some_method(a) { |val| puts val }
# good
# Operator methods require no disambiguation
foo == bar { |b| b.baz }
# good
# Lambda arguments require no disambiguation
foo = ->(bar) { bar.baz }
Example: AllowedMethods: [] (default)
# bad
expect { do_something }.to change { object.attribute }
Example: AllowedMethods: [change]
# good
expect { do_something }.to change { object.attribute }
Example: AllowedPatterns: [] (default)
# bad
expect { do_something }.to change { object.attribute }
Example: AllowedPatterns: ['change']
# good
expect { do_something }.to change { object.attribute }
expect { do_something }.to not_change { object.attribute }
Use yield
instead of block.call
. Open
block.arity < 1 ? self.instance_eval(&block) : block.call(self)
- Read upRead up
- Exclude checks
This cop identifies the use of a &block
parameter and block.call
where yield
would do just as well.
Example:
# bad
def method(&block)
block.call
end
def another(&func)
func.call 1, 2, 3
end
# good
def method
yield
end
def another
yield 1, 2, 3
end
Parenthesize the param NetAppManageability::NAMHash.new { name rh }
to make sure that the block will be associated with the NetAppManageability::NAMHash.new
method call. Open
push NetAppManageability::NAMHash.new { name rh }
- Read upRead up
- Exclude checks
Checks for ambiguous block association with method when param passed without parentheses.
This cop can customize allowed methods with AllowedMethods
.
By default, there are no methods to allowed.
Example:
# bad
some_method a { |val| puts val }
Example:
# good
# With parentheses, there's no ambiguity.
some_method(a { |val| puts val })
# or (different meaning)
some_method(a) { |val| puts val }
# good
# Operator methods require no disambiguation
foo == bar { |b| b.baz }
# good
# Lambda arguments require no disambiguation
foo = ->(bar) { bar.baz }
Example: AllowedMethods: [] (default)
# bad
expect { do_something }.to change { object.attribute }
Example: AllowedMethods: [change]
# good
expect { do_something }.to change { object.attribute }
Example: AllowedPatterns: [] (default)
# bad
expect { do_something }.to change { object.attribute }
Example: AllowedPatterns: ['change']
# good
expect { do_something }.to change { object.attribute }
expect { do_something }.to not_change { object.attribute }