Module has too many lines. [206/100] Open
module MiGA::Result::Stats
##
# (Re-)calculate and save the statistics for the result
def compute_stats
method = :"compute_stats_#{key}"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks if the length a module exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for compute_stats_ssu is too high. [55.34/15] Open
def compute_stats_ssu
stats = {
ssu: 0, complete_ssu: 0, ssu_fragment: [0.0, '%'],
lsu: 0, complete_lsu: 0, lsu_fragment: [0.0, '%']
}
- 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. [46/10] Open
def compute_stats_ssu
stats = {
ssu: 0, complete_ssu: 0, ssu_fragment: [0.0, '%'],
lsu: 0, complete_lsu: 0, lsu_fragment: [0.0, '%']
}
- 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 compute_stats_essential_genes is too high. [50.65/15] Open
def compute_stats_essential_genes
stats = {}
if source.multi?
stats = { median_copies: 0, mean_copies: 0 }
File.open(file_path(:report), 'r') 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. [38/10] Open
def compute_stats_essential_genes
stats = {}
if source.multi?
stats = { median_copies: 0, mean_copies: 0 }
File.open(file_path(:report), 'r') 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.
Method compute_stats_ssu
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
def compute_stats_ssu
stats = {
ssu: 0, complete_ssu: 0, ssu_fragment: [0.0, '%'],
lsu: 0, complete_lsu: 0, lsu_fragment: [0.0, '%']
}
- 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 lines. [21/10] Open
def compute_stats_cds
s = MiGA::MiGA.seqs_length(file_path(:proteins), :fasta)
stats = {
predicted_proteins: s[:n],
average_length: [s[:avg], 'aa']
- 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 compute_stats_cds is too high. [24.06/15] Open
def compute_stats_cds
s = MiGA::MiGA.seqs_length(file_path(:proteins), :fasta)
stats = {
predicted_proteins: s[:n],
average_length: [s[:avg], 'aa']
- 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 fix_essential_genes_by_domain is too high. [22.72/15] Open
def fix_essential_genes_by_domain
return if file_path(:raw_report)
tax = source.metadata[:tax]
return unless tax.nil? || %w[Archaea Bacteria].include?(tax[:d])
- 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 compute_stats_essential_genes
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def compute_stats_essential_genes
stats = {}
if source.multi?
stats = { median_copies: 0, mean_copies: 0 }
File.open(file_path(:report), 'r') do |fh|
- 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
Perceived complexity for compute_stats_essential_genes is too high. [13/7] Open
def compute_stats_essential_genes
stats = {}
if source.multi?
stats = { median_copies: 0, mean_copies: 0 }
File.open(file_path(:report), 'r') do |fh|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Perceived complexity for compute_stats_ssu is too high. [13/7] Open
def compute_stats_ssu
stats = {
ssu: 0, complete_ssu: 0, ssu_fragment: [0.0, '%'],
lsu: 0, complete_lsu: 0, lsu_fragment: [0.0, '%']
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for compute_stats_ssu is too high. [12/6] Open
def compute_stats_ssu
stats = {
ssu: 0, complete_ssu: 0, ssu_fragment: [0.0, '%'],
lsu: 0, complete_lsu: 0, lsu_fragment: [0.0, '%']
}
- 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.
Method has too many lines. [15/10] Open
def compute_stats_raw_reads
stats = {}
seq_opts = { gc: true, x: true, skew: true }
if self[:files][:pair1].nil?
s = MiGA::MiGA.seqs_length(file_path(:single), :fastq, seq_opts)
- 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. [15/10] Open
def compute_stats_assembly
s = MiGA::MiGA.seqs_length(
file_path(:largecontigs), :fasta,
n50: true, gc: true, x: true, skew: true
)
- 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.
Cyclomatic complexity for compute_stats_essential_genes is too high. [11/6] Open
def compute_stats_essential_genes
stats = {}
if source.multi?
stats = { median_copies: 0, mean_copies: 0 }
File.open(file_path(:report), 'r') do |fh|
- 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.
Method has too many lines. [13/10] Open
def compute_stats_taxonomy
stats = {}
return stats unless file_path(:intax_test)
File.open(file_path(:intax_test), 'r') 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.
Method has too many lines. [13/10] Open
def fix_essential_genes_by_domain
return if file_path(:raw_report)
tax = source.metadata[:tax]
return unless tax.nil? || %w[Archaea Bacteria].include?(tax[:d])
- 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 compute_stats_ssu
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def compute_stats_ssu
stats = {
ssu: 0, complete_ssu: 0, ssu_fragment: [0.0, '%'],
lsu: 0, complete_lsu: 0, lsu_fragment: [0.0, '%']
}
- Create a ticketCreate a ticket
Method compute_stats_essential_genes
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def compute_stats_essential_genes
stats = {}
if source.multi?
stats = { median_copies: 0, mean_copies: 0 }
File.open(file_path(:report), 'r') do |fh|
- Create a ticketCreate a ticket
Method compute_stats_taxonomy
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def compute_stats_taxonomy
stats = {}
return stats unless file_path(:intax_test)
File.open(file_path(:intax_test), 'r') do |fh|
- 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 compute_stats_cds
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def compute_stats_cds
s = MiGA::MiGA.seqs_length(file_path(:proteins), :fasta)
stats = {
predicted_proteins: s[:n],
average_length: [s[:avg], 'aa']
- 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 fix_essential_genes_by_domain
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def fix_essential_genes_by_domain
return if file_path(:raw_report)
tax = source.metadata[:tax]
return unless tax.nil? || %w[Archaea Bacteria].include?(tax[:d])
- 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 =~
in places where the MatchData
returned by #match
will not be used. Open
if /^! (Mean|Median) number of copies per model: (.*)\./.match(ln)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop identifies the use of Regexp#match
or String#match
, which
returns #<MatchData>
/nil
. The return value of =~
is an integral
index/nil
and is more performant.
Example:
# bad
do_something if str.match(/regex/)
while regex.match('str')
do_something
end
# good
method(str =~ /regex/)
return value unless regex =~ 'str'
Use =~
in places where the MatchData
returned by #match
will not be used. Open
if /^! (Completeness|Contamination): (.*)%/.match(ln)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop identifies the use of Regexp#match
or String#match
, which
returns #<MatchData>
/nil
. The return value of =~
is an integral
index/nil
and is more performant.
Example:
# bad
do_something if str.match(/regex/)
while regex.match('str')
do_something
end
# good
method(str =~ /regex/)
return value unless regex =~ 'str'
Missing magic comment # frozen_string_literal: true
. Open
require 'miga/result/base'
- 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
Avoid the use of Perl-style backrefs. Open
stats["#{$1.downcase}_copies".to_sym] = $2.to_f
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
stats[:"#{$1}_pvalue"] = $3.to_f unless $1 == 'root'
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
stats[:"#{$1}_pvalue"] = $3.to_f unless $1 == 'root'
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
stats["#{$1.downcase}_copies".to_sym] = $2.to_f
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
fragment = $1.to_f
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Redundant self
detected. Open
stats = self.respond_to?(method, true) ? send(method) : nil
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for redundant uses of self
.
The usage of self
is only needed when:
Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.
Calling an attribute writer to prevent an local variable assignment.
Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.
Note we allow uses of self
with operators because it would be awkward
otherwise.
Example:
# bad
def foo(bar)
self.baz
end
# good
def foo(bar)
self.bar # Resolves name clash with the argument.
end
def foo
bar = 1
self.bar # Resolves name clash with the local variable.
end
def foo
%w[x y z].select do |bar|
self.bar == bar # Resolves name clash with argument of the block.
end
end
Incorrect indentation detected (column 8 instead of 6). Open
# * Bowers et al 2017, DOI: 10.1038/nbt.3893
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cops checks the indentation of comments.
Example:
# bad
# comment here
def method_name
end
# comment here
a = 'hello'
# yet another comment
if true
true
end
# good
# comment here
def method_name
end
# comment here
a = 'hello'
# yet another comment
if true
true
end
Avoid the use of Perl-style backrefs. Open
stats[:aai] = [$2.to_f, '%']
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
stats[$1.downcase.to_sym][0] = $2.to_f
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
stats[$1.downcase.to_sym][0] = $2.to_f
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
stats[:closest_relative] = $1
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
stats[:"#{$1}_pvalue"] = $3.to_f unless $1 == 'root'
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Avoid the use of Perl-style backrefs. Open
stats[:codon_table] = $1
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.
Example:
# bad
puts $1
# good
puts Regexp.last_match(1)
Use ||
instead of or
. Open
unless asm.nil? or asm[:stats][:total_length].nil?
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Favor a normal if-statement over a modifier clause in a multiline statement. Open
Zlib::GzipReader.open(file_path(:trna_list)) do |fh|
no = 0
stats[:trna_count] = 0
aa = {}
fh.each_line do |ln|
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
MiGA::MiGA.DEBUG "Fixing essential genes by domain"
- 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"