Assignment Branch Condition size for complete_location is too high. [15.52/15] Open
def complete_location
result = ""
result += "#{self.street}" if self.street.present?
result += " #{self.street_number}" if self.street_number.present?
result += ", #{self.zip}" if self.zip.present?
- 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
Goldencobra::Location#complete_location calls 'self.city' 2 times Open
result += " #{self.city}" if self.city.present?
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Location#complete_location calls 'self.street' 2 times Open
result += "#{self.street}" if self.street.present?
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Location#complete_location calls 'self.zip' 2 times Open
result += ", #{self.zip}" if self.zip.present?
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Location has no descriptive comment Open
class Location < ActiveRecord::Base
- Read upRead up
- Exclude checks
Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.
Example
Given
class Dummy
# Do things...
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:Dummy has no descriptive comment (IrresponsibleModule)
Fixing this is simple - just an explaining comment:
# The Dummy class is responsible for ...
class Dummy
# Do things...
end
Goldencobra::Location#complete_location calls 'self.street_number' 2 times Open
result += " #{self.street_number}" if self.street_number.present?
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Location#skip_geocode is a writable attribute Open
attr_accessor :skip_geocode
- Read upRead up
- Exclude checks
A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.
The same holds to a lesser extent for getters, but Reek doesn't flag those.
Example
Given:
class Klass
attr_accessor :dummy
end
Reek would emit the following warning:
reek test.rb
test.rb -- 1 warning:
[2]:Klass declares the writable attribute dummy (Attribute)
Do not suppress exceptions. Open
rescue Geocoder::OverQueryLimitError
- Read upRead up
- Exclude checks
This cop checks for rescue blocks with no body.
Example:
# bad
def some_method
do_something
rescue
# do nothing
end
Example:
# bad
begin
do_something
rescue
# do nothing
end
Example:
# good
def some_method
do_something
rescue
handle_exception
end
Example:
# good
begin
do_something
rescue
handle_exception
end
Redundant self
detected. Open
result += " #{self.street_number}" if self.street_number.present?
- 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
Redundant self
detected. Open
result += " #{self.city}" if self.city.present?
- 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
Redundant self
detected. Open
result += "#{self.street}" if self.street.present?
- 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
Redundant self
detected. Open
result += ", #{self.zip}" if self.zip.present?
- 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
Prefer to_s
over string interpolation. Open
result += "#{self.street}" if self.street.present?
- Read upRead up
- Exclude checks
This cop checks for strings that are just an interpolated expression.
Example:
# bad
"#{@var}"
# good
@var.to_s
# good if @var is already a String
@var
Redundant self
detected. Open
self.skip_geocode || self.manual_geocoding
- 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
Add an empty line after magic comments. Open
# == Schema Information
- Read upRead up
- Exclude checks
Checks for a newline after the final magic comment.
Example:
# good
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
Redundant self
detected. Open
result += " #{self.city}" if self.city.present?
- 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
Space inside parentheses detected. Open
(Goldencobra::Setting.for_key("goldencobra.locations.geocoding") == "false" ) ||
- Read upRead up
- Exclude checks
Checks for spaces inside ordinary round parentheses.
Example: EnforcedStyle: no_space (default)
# The `no_space` style enforces that parentheses do not have spaces.
# bad
f( 3)
g = (a + 3 )
# good
f(3)
g = (a + 3)
Example: EnforcedStyle: space
# The `space` style enforces that parentheses have a space at the
# beginning and end.
# Note: Empty parentheses should not have spaces.
# bad
f(3)
g = (a + 3)
y( )
# good
f( 3 )
g = ( a + 3 )
y()
Use 2 (not 0) spaces for indenting an expression spanning multiple lines. Open
self.skip_geocode || self.manual_geocoding
- Read upRead up
- Exclude checks
This cop checks the indentation of the right hand side operand in binary operations that span more than one line.
Example: EnforcedStyle: aligned (default)
# bad
if a +
b
something
end
# good
if a +
b
something
end
Example: EnforcedStyle: indented
# bad
if a +
b
something
end
# good
if a +
b
something
end
Redundant self
detected. Open
result += " #{self.street_number}" if self.street_number.present?
- 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
Redundant self
detected. Open
result += ", #{self.zip}" if self.zip.present?
- 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
Redundant self
detected. Open
self.complete_location
- 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
Redundant self
detected. Open
self.skip_geocode || self.manual_geocoding
- 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
Useless assignment to variable - result
. Open
result += " #{self.city}" if self.city.present?
- Read upRead up
- Exclude checks
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
Unnecessary utf-8 encoding comment. Open
# encoding: utf-8
- Read upRead up
- Exclude checks
This cop checks ensures source files have no utf-8 encoding comments.
Example:
# bad
# encoding: UTF-8
# coding: UTF-8
# -*- coding: UTF-8 -*-
Redundant self
detected. Open
result += "#{self.street}" if self.street.present?
- 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
Missing top-level class documentation comment. Open
class Location < ActiveRecord::Base
- 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 compact module/class definition instead of nested style. Open
module Goldencobra
- Read upRead up
- Exclude checks
This cop checks the style of children definitions at classes and modules. Basically there are two different styles:
Example: EnforcedStyle: nested (default)
# good
# have each child on its own line
class Foo
class Bar
end
end
Example: EnforcedStyle: compact
# good
# combine definitions as much as possible
class Foo::Bar
end
The compact style is only forced for classes/modules with one child.