Class has too many lines. [224/100] Open
class MiGA::Cli::Action::Db < MiGA::Cli::Action
def parse_cli
cli.defaults = {
database: :recommended,
version: :latest,
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [52/10] Open
def parse_cli
cli.defaults = {
database: :recommended,
version: :latest,
local: File.join(ENV['MIGA_HOME'], '.miga_db'),
- Read upRead up
- Create a ticketCreate a ticket
- 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 parse_cli is too high. [39.85/15] Open
def parse_cli
cli.defaults = {
database: :recommended,
version: :latest,
local: File.join(ENV['MIGA_HOME'], '.miga_db'),
- Read upRead up
- Create a ticketCreate a ticket
- 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
Assignment Branch Condition size for register_database is too high. [37.5/15] Open
def register_database(manif, db, ver)
cli.say "Registering database locally"
reg = (local_manifest || {}).merge(last_update: Time.now.to_s)
reg[:databases] ||= {}
reg[:databases][cli[:database]] ||= {}
- Read upRead up
- Create a ticketCreate a ticket
- 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
Assignment Branch Condition size for perform is too high. [36.01/15] Open
def perform
# Quick check when the database is not an alias
dir = File.join(cli[:local], cli[:database].to_s)
if !cli[:overwrite] && Dir.exist?(dir)
cli.puts "Database exists: #{dir}"
- Read upRead up
- Create a ticketCreate a ticket
- 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. [22/10] Open
def perform
# Quick check when the database is not an alias
dir = File.join(cli[:local], cli[:database].to_s)
if !cli[:overwrite] && Dir.exist?(dir)
cli.puts "Database exists: #{dir}"
- Read upRead up
- Create a ticketCreate a ticket
- 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 list_local is too high. [25.67/15] Open
def list_local
local_manif = local_manifest
raise "Local manifest not found." unless local_manif
databases =
if %i[recommended test].include?(cli[:database])
- Read upRead up
- Create a ticketCreate a ticket
- 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. [19/10] Open
def list_local
local_manif = local_manifest
raise "Local manifest not found." unless local_manif
databases =
if %i[recommended test].include?(cli[:database])
- Read upRead up
- Create a ticketCreate a ticket
- 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.
Method parse_cli
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
def parse_cli
cli.defaults = {
database: :recommended,
version: :latest,
local: File.join(ENV['MIGA_HOME'], '.miga_db'),
- Create a ticketCreate a ticket
Assignment Branch Condition size for download_file is too high. [17.49/15] Open
def download_file(ftp, path, reuse = false)
cli.say "Downloading '#{path}'"
file = File.expand_path(path, cli[:local])
if reuse && File.exist?(file)
cli.say "Reusing #{file}"
- Read upRead up
- Create a ticketCreate a ticket
- 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
Assignment Branch Condition size for version_requested is too high. [17.38/15] Open
def version_requested(db)
cli[:version] = db[:latest].to_sym if cli[:version] == :latest
ver = db[:versions][cli[:version]]
raise 'Cannot find database version' if ver.nil?
ver[:version] = cli[:version]
- Read upRead up
- Create a ticketCreate a ticket
- 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
Assignment Branch Condition size for list_databases is too high. [16.03/15] Open
def list_databases(manif)
return false unless cli[:list_databases]
cli.puts "# Recommended database: #{manif[:recommended]}"
cli.puts ''
- Read upRead up
- Create a ticketCreate a ticket
- 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
Cyclomatic complexity for perform is too high. [7/6] Open
def perform
# Quick check when the database is not an alias
dir = File.join(cli[:local], cli[:database].to_s)
if !cli[:overwrite] && Dir.exist?(dir)
cli.puts "Database exists: #{dir}"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Assignment Branch Condition size for check_digest is too high. [16.25/15] Open
def check_digest(ver, file)
cli.say 'Checking MD5 digest'
cli.say "Expected: #{ver[:MD5]}"
md5 = Digest::MD5.new
File.open(file, 'rb') do |fh|
- Read upRead up
- Create a ticketCreate a ticket
- 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. [11/10] Open
def check_digest(ver, file)
cli.say 'Checking MD5 digest'
cli.say "Expected: #{ver[:MD5]}"
md5 = Digest::MD5.new
File.open(file, 'rb') do |fh|
- Read upRead up
- Create a ticketCreate a ticket
- 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 db_requested is too high. [16.4/15] Open
def db_requested(manif)
[:recommended, :test].each do |n|
if cli[:database] == n
raise "This host has no #{n} database" if manif[n].nil?
- Read upRead up
- Create a ticketCreate a ticket
- 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. [11/10] Open
def download_file(ftp, path, reuse = false)
cli.say "Downloading '#{path}'"
file = File.expand_path(path, cli[:local])
if reuse && File.exist?(file)
cli.say "Reusing #{file}"
- Read upRead up
- Create a ticketCreate a ticket
- 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 list_versions is too high. [15.03/15] Open
def list_versions(db)
return false unless cli[:list_versions]
cli.puts "# Database: #{cli[:database]}"
cli.puts ''
- Read upRead up
- Create a ticketCreate a ticket
- 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
Block has too many lines. [41/25] Open
cli.parse do |opt|
opt.on(
'-n', '--database STRING',
"Name of the database to download. By default: #{cli[:database]}"
) { |v| cli[:database] = v.to_sym }
- Read upRead up
- Create a ticketCreate a ticket
- 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 download_file
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def download_file(ftp, path, reuse = false)
cli.say "Downloading '#{path}'"
file = File.expand_path(path, cli[:local])
if reuse && File.exist?(file)
cli.say "Reusing #{file}"
- 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
Avoid too many return
statements within this method. Open
check_target and return
- Create a ticketCreate a ticket
Method list_local
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def list_local
local_manif = local_manifest
raise "Local manifest not found." unless local_manif
databases =
if %i[recommended test].include?(cli[:database])
- 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 db_requested
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def db_requested(manif)
[:recommended, :test].each do |n|
if cli[:database] == n
raise "This host has no #{n} database" if manif[n].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
Use safe navigation (&.
) instead of checking if an object exists before calling the method. Open
@ftp.close unless @ftp.nil?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop transforms usages of a method call safeguarded by a non nil
check for the variable whose method is being called to
safe navigation (&.
).
Configuration option: ConvertCodeThatCanStartToReturnNil
The default for this is false
. When configured to true
, this will
check for code in the format !foo.nil? && foo.bar
. As it is written,
the return of this code is limited to false
and whatever the return
of the method is. If this is converted to safe navigation,
foo&.bar
can start returning nil
as well as what the method
returns.
Example:
# bad
foo.bar if foo
foo.bar(param1, param2) if foo
foo.bar { |e| e.something } if foo
foo.bar(param) { |e| e.something } if foo
foo.bar if !foo.nil?
foo.bar unless !foo
foo.bar unless foo.nil?
foo && foo.bar
foo && foo.bar(param1, param2)
foo && foo.bar { |e| e.something }
foo && foo.bar(param) { |e| e.something }
# good
foo&.bar
foo&.bar(param1, param2)
foo&.bar { |e| e.something }
foo&.bar(param) { |e| e.something }
foo.nil? || foo.bar
!foo || foo.bar
# Methods that `nil` will `respond_to?` should not be converted to
# use safe navigation
foo.to_i if foo
Favor modifier until
usage when having a single-line body. Open
until fh.eof?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for while and until statements that would fit on one line
if written as a modifier while/until. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
while x < 10
x += 1
end
# good
x += 1 while x < 10
Example:
# bad
until x > 10
x += 1
end
# good
x += 1 until x > 10
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
raise "Local manifest not found." unless local_manif
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Missing top-level class documentation comment. Open
class MiGA::Cli::Action::Db < MiGA::Cli::Action
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Use next
to skip iteration. Open
if cli[:database] == n
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Use next
to skip iteration instead of a condition at the end.
Example: EnforcedStyle: skipmodifierifs (default)
# bad
[1, 2].each do |a|
if a == 1
puts a
end
end
# good
[1, 2].each do |a|
next unless a == 1
puts a
end
# good
[1, 2].each do |o|
puts o unless o == 1
end
Example: EnforcedStyle: always
# With `always` all conditions at the end of an iteration needs to be
# replaced by next - with `skip_modifier_ifs` the modifier if like
# this one are ignored: `[1, 2].each { |a| return 'yes' if a == 1 }`
# bad
[1, 2].each do |o|
puts o unless o == 1
end
# bad
[1, 2].each do |a|
if a == 1
puts a
end
end
# good
[1, 2].each do |a|
next unless a == 1
puts a
end
Missing magic comment # frozen_string_literal: true
. Open
# @package MiGA
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop is designed to help upgrade to Ruby 3.0. It will add the
comment # frozen_string_literal: true
to the top of files to
enable frozen string literals. Frozen string literals may be default
in Ruby 3.0. The comment will be added below a shebang and encoding
comment. The frozen string literal comment is only valid in Ruby 2.3+.
Example: EnforcedStyle: when_needed (default)
# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
# ...
end
# good
# frozen_string_literal: true
module Foo
# ...
end
Example: EnforcedStyle: always
# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
# ...
end
# good
# frozen_string_literal: true
module Bar
# ...
end
Example: EnforcedStyle: never
# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true
module Baz
# ...
end
# good
module Baz
# ...
end
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
cli.say "Registering database locally"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Use %i
or %I
for an array of symbols. Open
[:recommended, :test].each do |n|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]