Assignment Branch Condition size for new is too high. [15.3/15] Open
def Function.new(name, *xs)
xs.flatten!
if @@container[name]
# return @@container[name] if (@@container[name].x.uniq - xs.uniq == [] or xs.size == 0)
return @@container[name] if (@@container[name].x.uniq.map(&:to_s).sort == xs.uniq.map(&:to_s).sort or xs.size == 0)
- Read upRead up
- 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
Line is too long. [84/80] Open
raise CASError, "Function #{name} already defined with different arguments!"
- Exclude checks
Line is too long. [91/80] Open
# # Returns the inspect string of the function, that is similar to `CAS::Function#to_s`
- Exclude checks
Line is too long. [83/80] Open
# * **argument**: `Array` of `CAS::Variable` that are argument of the function
- Exclude checks
Missing top-level module documentation comment. Open
module CAS
- Read upRead up
- 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 empty?
instead of size == 0
. Open
return @@container[name] if (@@container[name].x.uniq.map(&:to_s).sort == xs.uniq.map(&:to_s).sort or xs.size == 0)
- Read upRead up
- Exclude checks
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
# Overrides new method. This will return an existing function if in the function container
- Exclude checks
Line is too long. [85/80] Open
# * **raises**: `CAS::CASError`: Ruby code for CAs::Function cannot be generated
- Exclude checks
Avoid single-line method definitions. Open
def self.size; @@container.keys.size; end
- Read upRead up
- Exclude checks
This cop checks for single-line method definitions that contain a body. It will accept single-line methods with no body.
Example:
# bad
def some_method; body end
def link_to(url); {:name => url}; end
def @table.columns; super; end
# good
def no_op; end
def self.resource_class=(klass); end
def @table.columns; end
Line is too long. [114/80] Open
# * **raises**: `CASError` if something different with resppect to a `CAS::Variable` is a active substitution
- Exclude checks
Use ||
instead of or
. Open
return @@container[name] if (@@container[name].x.uniq.map(&:to_s).sort == xs.uniq.map(&:to_s).sort or xs.size == 0)
- Read upRead up
- 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
Line is too long. [123/80] Open
return @@container[name] if (@@container[name].x.uniq.map(&:to_s).sort == xs.uniq.map(&:to_s).sort or xs.size == 0)
- Exclude checks
Line is too long. [106/80] Open
# has a name with respect to a schema that for now is fixed (TODO: make it variable and user defined).
- Exclude checks
When defining the ==
operator, name its argument other
. Open
def ==(op)
- Read upRead up
- Exclude checks
This cop makes sure that certain binary operator methods have their
sole parameter named other
.
Example:
# bad
def +(amount); end
# good
def +(other); end
Line is too long. [112/80] Open
# Substitutions in which a function is involved directly generates a CAS::Error unless the substitution will
- Exclude checks
Favor unless
over if
for negative conditions. Open
return false if not self.class == op.class
- Read upRead up
- Exclude checks
Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:
- both
- prefix
- postfix
Example: EnforcedStyle: both (default)
# enforces `unless` for `prefix` and `postfix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# bad
bar if !foo
# good
bar unless foo
Example: EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# good
bar if !foo
Example: EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals
# bad
bar if !foo
# good
bar unless foo
# good
if !foo
bar
end
Use &&
instead of and
. Open
return false if not (@name == op.name and @x.uniq == op.x.uniq)
- Read upRead up
- 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
Use !
instead of not
. Open
return false if not self.class == op.class
- Read upRead up
- Exclude checks
This cop checks for uses of the keyword not
instead of !
.
Example:
# bad - parentheses are required because of op precedence
x = (not something)
# good
x = !something
Favor unless
over if
for negative conditions. Open
return false if not (@name == op.name and @x.uniq == op.x.uniq)
- Read upRead up
- Exclude checks
Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:
- both
- prefix
- postfix
Example: EnforcedStyle: both (default)
# enforces `unless` for `prefix` and `postfix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# bad
bar if !foo
# good
bar unless foo
Example: EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# good
bar if !foo
Example: EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals
# bad
bar if !foo
# good
bar unless foo
# good
if !foo
bar
end
Redundant self
detected. Open
return @@container[s] if self.exist? s
- Read upRead up
- 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
Script file functions.rb doesn't have execute permission. Open
#!/usr/bin/env ruby
- Exclude checks
Line is too long. [82/80] Open
# * **returns**: `CAS::Function` instance if exists, raises a `CAS::CASError`
- Exclude checks
Line is too long. [83/80] Open
# * **returns**: `TrueClass` if functions are equal, `FalseClass` if not equal
- Exclude checks
Don't use parentheses around the condition of an if
. Open
return @@container[name] if (@@container[name].x.uniq.map(&:to_s).sort == xs.uniq.map(&:to_s).sort or xs.size == 0)
- Read upRead up
- Exclude checks
This cop checks for the presence of superfluous parentheses around the condition of if/unless/while/until.
Example:
# bad
x += 1 while (x < 10)
foo unless (bar || baz)
if (x > 10)
elsif (x < 3)
end
# good
x += 1 while x < 10
foo unless bar || baz
if x > 10
elsif x < 3
end
Redundant return
detected. Open
return a
- Read upRead up
- Exclude checks
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.
Avoid single-line method definitions. Open
def self.list; @@container; end
- Read upRead up
- Exclude checks
This cop checks for single-line method definitions that contain a body. It will accept single-line methods with no body.
Example:
# bad
def some_method; body end
def link_to(url); {:name => url}; end
def @table.columns; super; end
# good
def no_op; end
def self.resource_class=(klass); end
def @table.columns; end
Line is too long. [96/80] Open
# return @@container[name] if (@@container[name].x.uniq - xs.uniq == [] or xs.size == 0)
- Exclude checks
Use self.new
instead of Function.new
. Open
def Function.new(name, *xs)
- Read upRead up
- Exclude checks
This cop checks for uses of the class/module name instead of self, when defining class/module methods.
Example:
# bad
class SomeClass
def SomeClass.class_method
# ...
end
end
# good
class SomeClass
def self.class_method
# ...
end
end
Line is too long. [83/80] Open
# Performs the derivative with respect to one of the variable. The new function
- Exclude checks
Avoid single-line method definitions. Open
def self.exist?(name); @@container.keys.include?(name); end
- Read upRead up
- Exclude checks
This cop checks for single-line method definitions that contain a body. It will accept single-line methods with no body.
Example:
# bad
def some_method; body end
def link_to(url); {:name => url}; end
def @table.columns; super; end
# good
def no_op; end
def self.resource_class=(klass); end
def @table.columns; end
Avoid single-line method definitions. Open
def [](i); @x[i]; end
- Read upRead up
- Exclude checks
This cop checks for single-line method definitions that contain a body. It will accept single-line methods with no body.
Example:
# bad
def some_method; body end
def link_to(url); {:name => url}; end
def @table.columns; super; end
# good
def no_op; end
def self.resource_class=(klass); end
def @table.columns; end
Avoid single-line method definitions. Open
def simplify; self; end
- Read upRead up
- Exclude checks
This cop checks for single-line method definitions that contain a body. It will accept single-line methods with no body.
Example:
# bad
def some_method; body end
def link_to(url); {:name => url}; end
def @table.columns; super; end
# good
def no_op; end
def self.resource_class=(klass); end
def @table.columns; end
Replace class var @@container with a class instance var. Open
@@container = {}
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.
Do not place comments on the same line as the end
keyword. Open
end # Function
- Read upRead up
- Exclude checks
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
Method CAS::Function.exist?
is defined at both lib/numbers/functions.rb:47 and lib/numbers/functions.rb:71. Open
def self.exist?(name); @@container.keys.include?(name); end
- Read upRead up
- Exclude checks
This cop checks for duplicated instance (or singleton) method definitions.
Example:
# bad
def duplicated
1
end
def duplicated
2
end
Example:
# bad
def duplicated
1
end
alias duplicated other_duplicated
Example:
# good
def duplicated
1
end
def other_duplicated
2
end
Use xs.size.zero?
instead of xs.size == 0
. Open
return @@container[name] if (@@container[name].x.uniq.map(&:to_s).sort == xs.uniq.map(&:to_s).sort or xs.size == 0)
- Read upRead up
- Exclude checks
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
"#{@name}(#{@x.map(&:to_s).join(", ")})"
- Read upRead up
- Exclude checks
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"}"
Line is too long. [86/80] Open
# raise CASError, "Function #{name} already exists" if CAS::Function.exist? name
- Exclude checks
Line is too long. [91/80] Open
# Simplifications cannot be performed on anonymous function, thus it will always return
- Exclude checks
Line is too long. [101/80] Open
# Tries to convert an anonymous function into Ruby code will always raise a `CASError` because it
- Exclude checks
Use !
instead of not
. Open
return false if not (@name == op.name and @x.uniq == op.x.uniq)
- Read upRead up
- Exclude checks
This cop checks for uses of the keyword not
instead of !
.
Example:
# bad - parentheses are required because of op precedence
x = (not something)
# good
x = !something