eendroroy/rspikes

View on GitHub

Showing 3 of 3 total issues

Method normalize_positive_upper has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def normalize_positive_upper(n_list, data, max_item, upper_limit)
      data.each do |item|
        norm = Integer(((Float(item) / Float(max_item)) * upper_limit).round)
        adjusted_norm = (norm > 0 ? norm : 1)
        n_list << (item.zero? ? item : adjusted_norm)
Severity: Minor
Found in lib/rspikes.rb - About 25 mins to fix

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

required_ruby_version (2.0, declared in rspikes.gemspec) and TargetRubyVersion (2.1, declared in .rubocop.yml) should be equal.
Open

  spec.required_ruby_version = '>= 2.0.0'
Severity: Minor
Found in rspikes.gemspec by rubocop

Checks that required_ruby_version of gemspec and TargetRubyVersion of .rubocop.yml are equal. Thereby, RuboCop to perform static analysis working on the version required by gemspec.

Example:

# When `TargetRubyVersion` of .rubocop.yml is `2.3`.

# bad
Gem::Specification.new do |spec|
  spec.required_ruby_version = '>= 2.2.0'
end

# bad
Gem::Specification.new do |spec|
  spec.required_ruby_version = '>= 2.4.0'
end

# good
Gem::Specification.new do |spec|
  spec.required_ruby_version = '>= 2.3.0'
end

# good
Gem::Specification.new do |spec|
  spec.required_ruby_version = '>= 2.3'
end

# good
Gem::Specification.new do |spec|
  spec.required_ruby_version = ['>= 2.3.0', '< 2.5.0']
end

Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
Open

  unless spec.respond_to?(:metadata)
Severity: Minor
Found in rspikes.gemspec by rubocop

Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

Example:

# bad
if condition
  do_stuff(bar)
end

unless qux.empty?
  Foo.do_something
end

# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Severity
Category
Status
Source
Language