Assignment Branch Condition size for perform is too high. [28.3/15] Open
def perform
cli.ensure_par(tarball: '-o')
unless cli[:tarball] =~ /\.tar\.gz$/
raise 'The tarball path (-o) must have .tar.gz extension'
end
- 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. [17/10] Open
def perform
cli.ensure_par(tarball: '-o')
unless cli[:tarball] =~ /\.tar\.gz$/
raise 'The tarball path (-o) must have .tar.gz extension'
end
- 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 each_file_listed is too high. [22/15] Open
def each_file_listed(datasets, &blk)
datasets.each_with_index do |ds, k|
cli.advance('Datasets:', k + 1, datasets.size, false)
# Metadata
blk.call(
- 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. [14/10] Open
def each_file_listed(datasets, &blk)
datasets.each_with_index do |ds, k|
cli.advance('Datasets:', k + 1, datasets.size, false)
# Metadata
blk.call(
- 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 has too many lines. [12/10] Open
def parse_cli
cli.parse do |opt|
opt.on(
'-o', '--tarball PATH',
'(Mandatory) Path to the archive to be created ending in .tar.gz'
- 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 has too many lines. [12/10] Open
def add_file_to_tar(tar, rel_path, abs_path)
if File.directory? abs_path
Dir["#{abs_path}/*"].each do |f|
add_file_to_tar(tar, File.join(rel_path, File.basename(f)), f)
end
- 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 add_file_to_tar is too high. [15.17/15] Open
def add_file_to_tar(tar, rel_path, abs_path)
if File.directory? abs_path
Dir["#{abs_path}/*"].each do |f|
add_file_to_tar(tar, File.join(rel_path, File.basename(f)), f)
end
- 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 add_file_to_tar
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add_file_to_tar(tar, rel_path, abs_path)
if File.directory? abs_path
Dir["#{abs_path}/*"].each do |f|
add_file_to_tar(tar, File.join(rel_path, File.basename(f)), f)
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
Use yield
instead of blk.call
. Open
blk.call(tar)
- Read upRead up
- Create a ticketCreate a ticket
- 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
Use yield
instead of blk.call
. Open
blk.call(
File.join('metadata', File.basename(ds.metadata.path)),
ds.metadata.path
)
- Read upRead up
- Create a ticketCreate a ticket
- 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
Use yield
instead of blk.call
. Open
blk.call(File.join(res.relative_dir, rel_path), abs_path)
- Read upRead up
- Create a ticketCreate a ticket
- 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
Use yield
instead of blk.call
. Open
blk.call(res.relative_path, res.path) # <- JSON
- Read upRead up
- Create a ticketCreate a ticket
- 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
Use 0o for octal literals. Open
tar.add_file_simple(in_tar, 0666, File.size(abs_path)) do |ofh|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for octal, hex, binary and decimal literals using
uppercase prefixes and corrects them to lowercase prefix
or no prefix (in case of decimals).
eg. for octal use 0o
instead of 0
or 0O
.
Can be configured to use 0
only for octal literals using
EnforcedOctalStyle
=> zero_only
Use %i
or %I
for an array of symbols. Open
cli.opt_object(opt, [:project, :dataset_opt])
- 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]
Unused block argument - sym
. If it's necessary, use _
or _sym
as an argument name to indicate that it won't be used. Open
ds.each_result do |sym, res|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for unused block arguments.
Example:
# bad
do_something do |used, unused|
puts used
end
do_something do |bar|
puts :foo
end
define_method(:foo) do |bar|
puts :baz
end
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Missing top-level class documentation comment. Open
class MiGA::Cli::Action::Archive < 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
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
Use 0o for octal literals. Open
tar.add_file_simple(in_tar, 0666, string.size) { |fh| fh.write(string) }
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for octal, hex, binary and decimal literals using
uppercase prefixes and corrects them to lowercase prefix
or no prefix (in case of decimals).
eg. for octal use 0o
instead of 0
or 0O
.
Can be configured to use 0
only for octal literals using
EnforcedOctalStyle
=> zero_only