MatteoRagni/cas-rb

View on GitHub
lib/functions/fnc-sum.rb

Summary

Maintainability
A
1 hr
Test Coverage

Assignment Branch Condition size for reduce_associativity is too high. [30.82/15]
Open

    def reduce_associativity
      pos, neg = [], []

      @x.each do |x_el|
        case x_el
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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 reduce_associativity
      pos, neg = [], []

      @x.each do |x_el|
        case x_el
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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 reduce_associativity is too high. [11/6]
Open

    def reduce_associativity
      pos, neg = [], []

      @x.each do |x_el|
        case x_el
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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.

Perceived complexity for reduce_associativity is too high. [10/7]
Open

    def reduce_associativity
      pos, neg = [], []

      @x.each do |x_el|
        case x_el
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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

Method reduce_associativity has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def reduce_associativity
      pos, neg = [], []

      @x.each do |x_el|
        case x_el
Severity: Minor
Found in lib/functions/fnc-sum.rb - About 1 hr 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

Redundant self detected.
Open

      pos, neg = self.reduce_associativity_array pos, neg
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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

Use empty? instead of size == 0.
Open

      return CAS::Zero if @x.size == 0
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.

Example:

# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0

# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?

Line is too long. [94/80]
Open

      # return CAS.const(self.call({})) if (@x.is_a? CAS::Constant and @y.is_a? CAS::Constant)
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

Do not place comments on the same line as the end keyword.
Open

  end # Sum
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks for comments put on the same line as some keywords. These keywords are: begin, class, def, end, module.

Note that some comments (such as :nodoc: and rubocop:disable) are allowed.

Example:

# bad
if condition
  statement
end # end if

# bad
class X # comment
  statement
end

# bad
def x; end # comment

# good
if condition
  statement
end

# good
class X # :nodoc:
  y
end

Do not use parallel assignment.
Open

      pos, neg = [], []
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

Checks for simple usages of parallel assignment. This will only complain when the number of variables being assigned matched the number of assigning variables.

Example:

# bad
a, b, c = 1, 2, 3
a, b, c = [1, 2, 3]

# good
one, two = *foo
a, b = foo()
a, b = b, a

a = 1
b = 2
c = 3

Redundant return detected.
Open

      return left - right
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Prefer single-quoted strings inside interpolations.
Open

      "(#{@x.map(&:to_s).join(" + ")})"
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Do not use parallel assignment.
Open

      p_del, n_del = [], []
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

Checks for simple usages of parallel assignment. This will only complain when the number of variables being assigned matched the number of assigning variables.

Example:

# bad
a, b, c = 1, 2, 3
a, b, c = [1, 2, 3]

# good
one, two = *foo
a, b = foo()
a, b = b, a

a = 1
b = 2
c = 3

Useless assignment to variable - t. Use + instead of +=.
Open

        xs + [cs.inject { |t, c| t += c.call({}) }]
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Line is too long. [89/80]
Open

    #  * **returns**: `String` that represent Ruby code to be parsed in `CAS::Op#to_proc`
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

Redundant self detected.
Open

      return self.reduce_associativity
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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

Redundant self detected.
Open

      pos = self.__reduce_multeplicity(pos)
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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

Redundant return detected. To return multiple values, use an array.
Open

      return (p_old - p_del), (n_old - n_del)
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Redundant self detected.
Open

      neg = self.__reduce_multeplicity neg
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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

Useless assignment to variable - sum_x. Use + instead of +=.
Open

      @x.map { |x| x.diff(v) }.inject { |sum_x, dx| sum_x += dx }
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Use @x.size.zero? instead of @x.size == 0.
Open

      return CAS::Zero if @x.size == 0
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

Prefer single-quoted strings inside interpolations.
Open

      "(#{@x.map(&:to_code).join(" + ")})"
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Script file fnc-sum.rb doesn't have execute permission.
Open

#!/usr/bin/env ruby
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

When defining the + operator, name its argument other.
Open

    def +(op)
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop makes sure that certain binary operator methods have their sole parameter named other.

Example:

# bad
def +(amount); end

# good
def +(other); end

Do not use parallel assignment.
Open

      left, right = nil, nil
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

Checks for simple usages of parallel assignment. This will only complain when the number of variables being assigned matched the number of assigning variables.

Example:

# bad
a, b, c = 1, 2, 3
a, b, c = [1, 2, 3]

# good
one, two = *foo
a, b = foo()
a, b = b, a

a = 1
b = 2
c = 3

Redundant self detected.
Open

      @x = self.__reduce_constants(@x) do |cs, xs|
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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

Missing top-level module documentation comment.
Open

module CAS
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

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

Redundant return detected.
Open

      return self.reduce_associativity
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Use self-assignment shorthand -=.
Open

      @x = @x - [CAS::Zero]
Severity: Minor
Found in lib/functions/fnc-sum.rb by rubocop

This cop enforces the use the shorthand for self-assignment.

Example:

# bad
x = x + 1

# good
x += 1

There are no issues that match your filters.

Category
Status