Assignment Branch Condition size for remove_unused_setting_keys is too high. [32.63/15] Open
def self.remove_unused_setting_keys(settings_path)
raise "Settings file '#{path_file_name}' does not exist" unless File.exist?(settings_path)
settings = open(settings_path) { |f| YAML.safe_load(f) }
settings_root = settings.each_key.first if settings.present?
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method has too many lines. [24/10] Open
def self.remove_unused_setting_keys(settings_path)
raise "Settings file '#{path_file_name}' does not exist" unless File.exist?(settings_path)
settings = open(settings_path) { |f| YAML.safe_load(f) }
settings_root = settings.each_key.first if settings.present?
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for search_in_files is too high. [25.36/15] Open
def self.search_in_files(settings_path, search_path)
raise "Settings file '#{path_file_name}' does not exist" unless File.exist?(settings_path)
settings = open(settings_path) { |f| YAML.safe_load(f) }
settings_root = settings.each_key.first
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Complex method Goldencobra::SettingsCleanup::remove_unused_setting_keys (46.8) Open
def self.remove_unused_setting_keys(settings_path)
raise "Settings file '#{path_file_name}' does not exist" unless File.exist?(settings_path)
settings = open(settings_path) { |f| YAML.safe_load(f) }
settings_root = settings.each_key.first if settings.present?
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Method has too many lines. [14/10] Open
def self.search_in_files(settings_path, search_path)
raise "Settings file '#{path_file_name}' does not exist" unless File.exist?(settings_path)
settings = open(settings_path) { |f| YAML.safe_load(f) }
settings_root = settings.each_key.first
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Complex method Goldencobra::SettingsCleanup::search_in_files (33.2) Open
def self.search_in_files(settings_path, search_path)
raise "Settings file '#{path_file_name}' does not exist" unless File.exist?(settings_path)
settings = open(settings_path) { |f| YAML.safe_load(f) }
settings_root = settings.each_key.first
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Method remove_unused_setting_keys
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def self.remove_unused_setting_keys(settings_path)
raise "Settings file '#{path_file_name}' does not exist" unless File.exist?(settings_path)
settings = open(settings_path) { |f| YAML.safe_load(f) }
settings_root = settings.each_key.first if settings.present?
- 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
Goldencobra::SettingsCleanup#self.search_in_files has approx 12 statements Open
def self.search_in_files(settings_path, search_path)
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Goldencobra::SettingsCleanup#self.remove_unused_setting_keys contains iterators nested 2 deep Open
setting.path.pluck(:title).each do |key|
- Read upRead up
- Exclude checks
A Nested Iterator
occurs when a block contains another block.
Example
Given
class Duck
class << self
def duck_names
%i!tick trick track!.each do |surname|
%i!duck!.each do |last_name|
puts "full name is #{surname} #{last_name}"
end
end
end
end
end
Reek would report the following warning:
test.rb -- 1 warning:
[5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)
Goldencobra::SettingsCleanup#self.remove_unused_setting_keys has approx 17 statements Open
def self.remove_unused_setting_keys(settings_path)
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Goldencobra::SettingsCleanup#self.search_in_files calls 'p "*" * 100' 2 times Open
p "*" * 100
p "Searching for #{complete_setting} in #{search_path}"
p "-" * 100
unless system "grep -Rl '#{complete_setting}' #{search_path}"
p "#{complete_setting} not found in #{search_path}"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::SettingsCleanup#self.remove_unused_setting_keys calls '"*" * 100' 2 times Open
p "*" * 100
Goldencobra::Setting.roots.where(title: settings_root).first.descendants.each do |setting|
settings_to_fetch = settings
setting.path.pluck(:title).each do |key|
p "Setting key: #{key} - Setting path: #{setting.path.pluck(:title).join(".")}"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::SettingsCleanup#self.remove_unused_setting_keys calls 'setting.path.pluck(:title)' 2 times Open
setting.path.pluck(:title).each do |key|
p "Setting key: #{key} - Setting path: #{setting.path.pluck(:title).join(".")}"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::SettingsCleanup#self.remove_unused_setting_keys calls 'p "*" * 100' 2 times Open
p "*" * 100
Goldencobra::Setting.roots.where(title: settings_root).first.descendants.each do |setting|
settings_to_fetch = settings
setting.path.pluck(:title).each do |key|
p "Setting key: #{key} - Setting path: #{setting.path.pluck(:title).join(".")}"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::SettingsCleanup#self.remove_unused_setting_keys calls 'setting.path' 2 times Open
setting.path.pluck(:title).each do |key|
p "Setting key: #{key} - Setting path: #{setting.path.pluck(:title).join(".")}"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::SettingsCleanup#self.search_in_files calls '"*" * 100' 2 times Open
p "*" * 100
p "Searching for #{complete_setting} in #{search_path}"
p "-" * 100
unless system "grep -Rl '#{complete_setting}' #{search_path}"
p "#{complete_setting} not found in #{search_path}"
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Method search_in_files
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.search_in_files(settings_path, search_path)
raise "Settings file '#{path_file_name}' does not exist" unless File.exist?(settings_path)
settings = open(settings_path) { |f| YAML.safe_load(f) }
settings_root = settings.each_key.first
- 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
Goldencobra::SettingsCleanup#self.remove_unused_setting_keys has the variable name 'f' Open
settings = open(settings_path) { |f| YAML.safe_load(f) }
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Goldencobra::SettingsCleanup#self.search_in_files has the variable name 'f' Open
settings = open(settings_path) { |f| YAML.safe_load(f) }
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
The use of Kernel#open
is a serious security risk. Open
settings = open(settings_path) { |f| YAML.safe_load(f) }
- Read upRead up
- Exclude checks
This cop checks for the use of Kernel#open
.
Kernel#open
enables not only file access but also process invocation
by prefixing a pipe symbol (e.g., open("| ls")
). So, it may lead to
a serious security risk by using variable input to the argument of
Kernel#open
. It would be better to use File.open
or IO.popen
explicitly.
Example:
# bad
open(something)
# good
File.open(something)
IO.popen(something)
The use of Kernel#open
is a serious security risk. Open
settings = open(settings_path) { |f| YAML.safe_load(f) }
- Read upRead up
- Exclude checks
This cop checks for the use of Kernel#open
.
Kernel#open
enables not only file access but also process invocation
by prefixing a pipe symbol (e.g., open("| ls")
). So, it may lead to
a serious security risk by using variable input to the argument of
Kernel#open
. It would be better to use File.open
or IO.popen
explicitly.
Example:
# bad
open(something)
# good
File.open(something)
IO.popen(something)
Use compact module/class definition instead of nested style. Open
module Goldencobra
- Read upRead up
- Exclude checks
This cop checks the style of children definitions at classes and modules. Basically there are two different styles:
Example: EnforcedStyle: nested (default)
# good
# have each child on its own line
class Foo
class Bar
end
end
Example: EnforcedStyle: compact
# good
# combine definitions as much as possible
class Foo::Bar
end
The compact style is only forced for classes/modules with one child.