Assignment Branch Condition size for set_descendants_status is too high. [15.81/15] Open
def set_descendants_status
if !self.new_record? && self.active_changed? && self.descendants.any?
# Save without callbacks
if Rails::VERSION::MAJOR == 3
self.descendants.map{ |d| d.update_column(:active, self.active) }
- 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::Menue#self.filtered_methods has approx 8 statements Open
def self.filtered_methods(method_names=[])
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Goldencobra::Menue has no descriptive comment Open
class Menue < 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::Menue#is_active? calls 'request.path' 2 times Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- 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::Menue#is_active? calls 'request.path.squeeze("/").chomp("/")' 2 times Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- 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::Menue#set_descendants_status calls 'self.active' 2 times Open
self.descendants.map{ |d| d.update_column(:active, self.active) }
elsif Rails::VERSION::MAJOR > 3
self.descendants.map{ |d| d.update_columns(active: self.active) }
- 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::Menue#set_descendants_status calls 'self.descendants.map' 2 times Open
self.descendants.map{ |d| d.update_column(:active, self.active) }
elsif Rails::VERSION::MAJOR > 3
self.descendants.map{ |d| d.update_columns(active: self.active) }
- 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::Menue#set_descendants_status calls 'self.descendants' 3 times Open
if !self.new_record? && self.active_changed? && self.descendants.any?
# Save without callbacks
if Rails::VERSION::MAJOR == 3
self.descendants.map{ |d| d.update_column(:active, self.active) }
elsif Rails::VERSION::MAJOR > 3
- 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::Menue#is_active? calls 'request.path.squeeze("/").chomp("/").split("?")[0]' 2 times Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- 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::Menue#is_active? calls 'request.path.squeeze("/")' 2 times Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- 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::Menue#navigation_image calls 'self.image' 5 times Open
return {} unless self.image
{
"alt_text" => self.image.alt_text ? self.image.alt_text : self.image.image_file_name,
"src" => self.image.image(:original)
- 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::Menue#is_active? calls 'request.path.squeeze("/").chomp("/").split("?")' 2 times Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- 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::Menue#navigation_image calls 'self.image.alt_text' 2 times Open
"alt_text" => self.image.alt_text ? self.image.alt_text : self.image.image_file_name,
- 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.
Complex method Goldencobra::Menue#set_descendants_status (21.9) Open
def set_descendants_status
if !self.new_record? && self.active_changed? && self.descendants.any?
# Save without callbacks
if Rails::VERSION::MAJOR == 3
self.descendants.map{ |d| d.update_column(:active, self.active) }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Goldencobra::Menue#has_active_descendant? (20.9) Open
def has_active_descendant?(subtree_menues,request)
subtree_menues.select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0])
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Goldencobra::Menue::find_by_pathname (20.5) Open
def self.find_by_pathname(name)
if name.include?("/")
where(title: name.split("/").last).select{|a| a.path.map(&:title).join("/") == name}.first
else
find_by_title(name)
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Goldencobra::Menue#self.ransackable_scopes has unused parameter 'auth_object' Open
def self.ransackable_scopes(auth_object = nil)
- Read upRead up
- Exclude checks
Unused Parameter
refers to methods with parameters that are unused in scope of the method.
Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.
Example
Given:
class Klass
def unused_parameters(x,y,z)
puts x,y # but not z
end
end
Reek would emit the following warning:
[2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)
Goldencobra::Menue#has_active_descendant? has the variable name 'a' Open
subtree_menues.select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0])
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Goldencobra::Menue#article_id has the variable name 'a' Open
Goldencobra::Article.select([:url_name, :startpage, :ancestry, :id, :url_path]).select{ |a| a.public_url == target }.first.try(:id)
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Goldencobra::Menue#self.find_by_pathname has the variable name 'a' Open
where(title: name.split("/").last).select{|a| a.path.map(&:title).join("/") == name}.first
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Goldencobra::Menue#self.filtered_methods has the variable name 'a' Open
selected_methods = method_names.select{ |a| all_allowed_methodes.include?(a) }
#Wandle method names um in Symbols
method_names = selected_methods.map{ |a| a.to_sym }
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Goldencobra::Menue#set_descendants_status has the variable name 'd' Open
self.descendants.map{ |d| d.update_column(:active, self.active) }
elsif Rails::VERSION::MAJOR > 3
self.descendants.map{ |d| d.update_columns(active: self.active) }
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Use delete
instead of gsub
. Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- Read upRead up
- Exclude checks
This cop identifies places where gsub
can be replaced by
tr
or delete
.
Example:
# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')
# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')
TODO found Open
# TODO: Anfrage dauert zu lange bei 2000 Artikeln
- Exclude checks
Identical blocks of code found in 2 locations. Consider refactoring. Open
def set_descendants_status
if !self.new_record? && self.active_changed? && self.descendants.any?
# Save without callbacks
if Rails::VERSION::MAJOR == 3
self.descendants.map{ |d| d.update_column(:active, self.active) }
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 46.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Surrounding space missing in default value assignment. Open
def self.filtered_methods(method_names=[])
- Read upRead up
- Exclude checks
Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# bad
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
# good
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
Example: EnforcedStyle: no_space
# bad
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
# good
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
Line is too long. [137/100] Open
Goldencobra::Article.select([:url_name, :startpage, :ancestry, :id, :url_path]).select{ |a| a.public_url == target }.first.try(:id)
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [115/100] Open
# @param display_methods [:method] Optionale Liste an Mehtoden die auf das Menüelement aufgerufen werden sollen
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Space missing to the left of {. Open
Goldencobra::Article.select([:url_name, :startpage, :ancestry, :id, :url_path]).select{ |a| a.public_url == target }.first.try(:id)
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example: EnforcedStyle: space (default)
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Example: EnforcedStyle: no_space
# bad
foo.map { |a|
a.bar.to_s
}
# good
foo.map{ |a|
a.bar.to_s
}
Redundant self
detected. Open
"alt_text" => self.image.alt_text ? self.image.alt_text : self.image.image_file_name,
- 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
Do not use space inside array brackets. Open
[ :parent_ids_in ]
- Read upRead up
- Exclude checks
Checks that brackets used for array literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that array literals have
# surrounding space.
# bad
array = [a, b, c, d]
# good
array = [ a, b, c, d ]
Example: EnforcedStyle: no_space (default)
# The `no_space` style enforces that array literals have
# no surrounding space.
# bad
array = [ a, b, c, d ]
# good
array = [a, b, c, d]
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# array brackets, with the exception that successive left
# or right brackets are collapsed together in nested arrays.
# bad
array = [ a, [ b, c ] ]
# good
array = [ a, [ b, c ]]
Example: EnforcedStyleForEmptyBrackets: no_space (default)
# The `no_space` EnforcedStyleForEmptyBrackets style enforces that
# empty array brackets do not contain spaces.
# bad
foo = [ ]
bar = [ ]
# good
foo = []
bar = []
Example: EnforcedStyleForEmptyBrackets: space
# The `space` EnforcedStyleForEmptyBrackets style enforces that
# empty array brackets contain exactly one space.
# bad
foo = []
bar = [ ]
# good
foo = [ ]
bar = [ ]
Space inside parentheses detected. Open
def self.json_tree(nodes, display_methods )
- 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()
Rename has_active_descendant?
to active_descendant?
. Open
def has_active_descendant?(subtree_menues,request)
- Read upRead up
- Exclude checks
This cop makes sure that predicates are named properly.
Example:
# bad
def is_even?(value)
end
# good
def even?(value)
end
# bad
def has_value?
end
# good
def value?
end
Redundant self
detected. Open
self.has_children?
- 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
Line is too long. [159/100] Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Line is too long. [107/100] Open
# path_ids Returns a list the path ids, starting with the root id and ending with the node's own id
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Redundant self
detected. Open
template = Liquid::Template.parse(self.description)
- 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
if !self.new_record? && self.active_changed? && self.descendants.any?
- 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 missing to the left of {. Open
self.descendants.map{ |d| d.update_columns(active: self.active) }
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example: EnforcedStyle: space (default)
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Example: EnforcedStyle: no_space
# bad
foo.map { |a|
a.bar.to_s
}
# good
foo.map{ |a|
a.bar.to_s
}
Space inside { missing. Open
node.as_json(only: [:id, :title, :target], methods: display_methods).merge({children: json_tree(sub_nodes, display_methods).compact})
- Read upRead up
- Exclude checks
Checks that braces used for hash literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that hash literals have
# surrounding space.
# bad
h = {a: 1, b: 2}
# good
h = { a: 1, b: 2 }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that hash literals have
# no surrounding space.
# bad
h = { a: 1, b: 2 }
# good
h = {a: 1, b: 2}
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.
# bad
h = { a: { b: 2 } }
# good
h = { a: { b: 2 }}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces do not contain spaces.
# bad
foo = { }
bar = { }
# good
foo = {}
bar = {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces contain space.
# bad
foo = {}
# good
foo = { }
foo = { }
foo = { }
Line is too long. [156/100] Open
subtree_menues.select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0])
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
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
self.descendants.map{ |d| d.update_column(:active, self.active) }
- 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.descendants.map{ |d| d.update_columns(active: self.active) }
- 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
"alt_text" => self.image.alt_text ? self.image.alt_text : self.image.image_file_name,
- 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 missing after comma. Open
def has_active_descendant?(subtree_menues,request)
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Space missing to the left of {. Open
subtree_menues.select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0])
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example: EnforcedStyle: space (default)
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Example: EnforcedStyle: no_space
# bad
foo.map { |a|
a.bar.to_s
}
# good
foo.map{ |a|
a.bar.to_s
}
Space between { and | missing. Open
where(title: name.split("/").last).select{|a| a.path.map(&:title).join("/") == name}.first
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a space in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: false
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Rename has_children
to children?
. Open
def has_children
- Read upRead up
- Exclude checks
This cop makes sure that predicates are named properly.
Example:
# bad
def is_even?(value)
end
# good
def even?(value)
end
# bad
def has_value?
end
# good
def value?
end
Redundant curly braces around a hash parameter. Open
node.as_json(only: [:id, :title, :target], methods: display_methods).merge({children: json_tree(sub_nodes, display_methods).compact})
- Read upRead up
- Exclude checks
This cop checks for braces around the last parameter in a method call
if the last parameter is a hash.
It supports braces
, no_braces
and context_dependent
styles.
Example: EnforcedStyle: braces
# The `braces` style enforces braces around all method
# parameters that are hashes.
# bad
some_method(x, y, a: 1, b: 2)
# good
some_method(x, y, {a: 1, b: 2})
Example: EnforcedStyle: no_braces (default)
# The `no_braces` style checks that the last parameter doesn't
# have braces around it.
# bad
some_method(x, y, {a: 1, b: 2})
# good
some_method(x, y, a: 1, b: 2)
Example: EnforcedStyle: context_dependent
# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.
# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
Redundant self
detected. Open
self.descendants.map{ |d| d.update_columns(active: self.active) }
- 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 between { and | missing. Open
subtree_menues.select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0])
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a space in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: false
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Redundant self
detected. Open
"alt_text" => self.image.alt_text ? self.image.alt_text : self.image.image_file_name,
- 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 missing inside }. Open
where(title: name.split("/").last).select{|a| a.path.map(&:title).join("/") == name}.first
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a space in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: false
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Space missing inside }. Open
subtree_menues.select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0])
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a space in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: false
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Redundant return
detected. Open
return method_names.sort
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
# These bad cases should be extended to handle methods whose body is
# if/else or a case expression with a default branch.
# bad
def test
return something
end
# bad
def test
one
two
three
return something
end
# good
def test
return something if something_else
end
# good
def test
if x
elsif y
else
end
end
Redundant self
detected. Open
subtree_menues.select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0])
- 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
return {} unless self.image
- 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
Extra blank line detected. Open
# has_ancestry Doku
- Read upRead up
- Exclude checks
This cops checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method
Missing space after #
. Open
#Alle zugelasssenen methodennamen als Array of Strings
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Space missing to the left of {. Open
method_names = selected_methods.map{ |a| a.to_sym }
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example: EnforcedStyle: space (default)
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Example: EnforcedStyle: no_space
# bad
foo.map { |a|
a.bar.to_s
}
# good
foo.map{ |a|
a.bar.to_s
}
Line is too long. [106/100] Open
# ancestor_ids Returns a list of ancestor ids, starting with the root id and ending with the parent id
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if ActiveRecord::Base.connection.table_exists?("versions")
- Read upRead up
- Exclude checks
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. The tab size is configured
in the IndentationWidth
of the Layout/Tab
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?
Missing space after #
. Open
#Filter übergebene methodenliste auf die zugelassenen namen
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Redundant self
detected. Open
"src" => self.image.image(:original)
- 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
if !self.new_record? && self.active_changed? && self.descendants.any?
- 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
Do not use space inside array brackets. Open
[ :parent_ids_in ]
- Read upRead up
- Exclude checks
Checks that brackets used for array literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that array literals have
# surrounding space.
# bad
array = [a, b, c, d]
# good
array = [ a, b, c, d ]
Example: EnforcedStyle: no_space (default)
# The `no_space` style enforces that array literals have
# no surrounding space.
# bad
array = [ a, b, c, d ]
# good
array = [a, b, c, d]
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# array brackets, with the exception that successive left
# or right brackets are collapsed together in nested arrays.
# bad
array = [ a, [ b, c ] ]
# good
array = [ a, [ b, c ]]
Example: EnforcedStyleForEmptyBrackets: no_space (default)
# The `no_space` EnforcedStyleForEmptyBrackets style enforces that
# empty array brackets do not contain spaces.
# bad
foo = [ ]
bar = [ ]
# good
foo = []
bar = []
Example: EnforcedStyleForEmptyBrackets: space
# The `space` EnforcedStyleForEmptyBrackets style enforces that
# empty array brackets contain exactly one space.
# bad
foo = []
bar = [ ]
# good
foo = [ ]
bar = [ ]
Line is too long. [155/100] Open
# @mapped_to_article_result ||= Goldencobra::Article.select([:url_name, :startpage, :ancestry, :id]).map{|a| a.public_url}.uniq.include?(self.target)
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Rename is_active?
to active?
. Open
def is_active?(request)
- Read upRead up
- Exclude checks
This cop makes sure that predicates are named properly.
Example:
# bad
def is_even?(value)
end
# good
def even?(value)
end
# bad
def has_value?
end
# good
def value?
end
Rename has_active_child?
to active_child?
. Open
def has_active_child?(request, subtree_menues)
- Read upRead up
- Exclude checks
This cop makes sure that predicates are named properly.
Example:
# bad
def is_even?(value)
end
# good
def even?(value)
end
# bad
def has_value?
end
# good
def value?
end
Space missing to the left of {. Open
selected_methods = method_names.select{ |a| all_allowed_methodes.include?(a) }
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example: EnforcedStyle: space (default)
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Example: EnforcedStyle: no_space
# bad
foo.map { |a|
a.bar.to_s
}
# good
foo.map{ |a|
a.bar.to_s
}
Space missing to the left of {. Open
self.descendants.map{ |d| d.update_column(:active, self.active) }
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example: EnforcedStyle: space (default)
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Example: EnforcedStyle: no_space
# bad
foo.map { |a|
a.bar.to_s
}
# good
foo.map{ |a|
a.bar.to_s
}
Redundant self
detected. Open
self.descendants.map{ |d| d.update_column(:active, self.active) }
- 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 space after #
. Open
#Wandle method names um in Symbols
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Space missing to the left of {. Open
where(title: name.split("/").last).select{|a| a.path.map(&:title).join("/") == name}.first
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example: EnforcedStyle: space (default)
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Example: EnforcedStyle: no_space
# bad
foo.map { |a|
a.bar.to_s
}
# good
foo.map{ |a|
a.bar.to_s
}
Do not use spaces between ->
and opening brace in lambda literals Open
scope :parent_ids_in, -> (menue_id = 1) { subtree_of(menue_id) }
- Read upRead up
- Exclude checks
This cop checks for spaces between -> and opening parameter brace in lambda literals.
Example: EnforcedStyle: requirenospace (default)
# bad
a = -> (x, y) { x + y }
# good
a = ->(x, y) { x + y }
Example: EnforcedStyle: require_space
# bad
a = ->(x, y) { x + y }
# good
a = -> (x, y) { x + y }
Space inside } missing. Open
node.as_json(only: [:id, :title, :target], methods: display_methods).merge({children: json_tree(sub_nodes, display_methods).compact})
- Read upRead up
- Exclude checks
Checks that braces used for hash literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that hash literals have
# surrounding space.
# bad
h = {a: 1, b: 2}
# good
h = { a: 1, b: 2 }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that hash literals have
# no surrounding space.
# bad
h = { a: 1, b: 2 }
# good
h = {a: 1, b: 2}
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# hash braces, with the exception that successive left
# braces or right braces are collapsed together in nested hashes.
# bad
h = { a: { b: 2 } }
# good
h = { a: { b: 2 }}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces do not contain spaces.
# bad
foo = { }
bar = { }
# good
foo = {}
bar = {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# empty hash braces contain space.
# bad
foo = {}
# good
foo = { }
foo = { }
foo = { }
private
(on line 164) does not make singleton methods private. Use private_class_method
or private
inside a class << self
block instead. Open
def self.ransackable_scopes(auth_object = nil)
- Read upRead up
- Exclude checks
This cop checks for private
or protected
access modifiers which are
applied to a singleton method. These access modifiers do not make
singleton methods private/protected. private_class_method
can be
used for that.
Example:
# bad
class C
private
def self.method
puts 'hi'
end
end
Example:
# good
class C
def self.method
puts 'hi'
end
private_class_method :method
end
Example:
# good
class C
class << self
private
def method
puts 'hi'
end
end
end
Line is too long. [141/100] Open
node.as_json(only: [:id, :title, :target], methods: display_methods).merge({children: json_tree(sub_nodes, display_methods).compact})
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Missing top-level class documentation comment. Open
class Menue < 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
Redundant self
detected. Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- 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 double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Open
after_save 'Goldencobra::Article.recreate_cache'
- Read upRead up
- 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"
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- Read upRead up
- 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"
Pass &:to_sym
as an argument to map
instead of a block. Open
method_names = selected_methods.map{ |a| a.to_sym }
- Read upRead up
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)
Use %i
or %I
for an array of symbols. Open
Goldencobra::Article.select([:url_name, :startpage, :ancestry, :id, :url_path]).select{ |a| a.public_url == target }.first.try(:id)
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
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
Use 2 (not 0) spaces for rails indentation. Open
def set_descendants_status
- Read upRead up
- Exclude checks
This cops checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Use %i
or %I
for an array of symbols. Open
node.as_json(only: [:id, :title, :target], methods: display_methods).merge({children: json_tree(sub_nodes, display_methods).compact})
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Do not use spaces between ->
and opening brace in lambda literals Open
scope :parent_ids_in_eq, -> (menue_id = 1) { subtree_of(menue_id) }
- Read upRead up
- Exclude checks
This cop checks for spaces between -> and opening parameter brace in lambda literals.
Example: EnforcedStyle: requirenospace (default)
# bad
a = -> (x, y) { x + y }
# good
a = ->(x, y) { x + y }
Example: EnforcedStyle: require_space
# bad
a = ->(x, y) { x + y }
# good
a = -> (x, y) { x + y }
Unused method argument - auth_object
. If it's necessary, use _
or _auth_object
as an argument name to indicate that it won't be used. You can also write as ransackable_scopes(*)
if you want the method to accept any arguments but don't care about them. Open
def self.ransackable_scopes(auth_object = nil)
- Read upRead up
- Exclude checks
This cop checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
Example:
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end
Line is too long. [123/100] Open
@has_active_child_result[request.path.squeeze("/").split("?")[0]] ||= has_active_descendant?(subtree_menues, request)
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
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.
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if !self.new_record? && self.active_changed? && self.descendants.any?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Redundant self
detected. Open
subtree_menues.select{|a| a.ancestry.to_s.starts_with?("#{self.ancestry}/#{self.id}")}.map(&:target).include?(request.path.squeeze("/").split("?")[0])
- 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
if !self.new_record? && self.active_changed? && self.descendants.any?
- 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 missing after comma. Open
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
- Read upRead up
- Exclude checks
Checks for comma (,) not followed by some kind of space.
Example:
# bad
[1,2]
{ foo:bar,}
# good
[1, 2]
{ foo:bar, }
Use %i
or %I
for an array of symbols. Open
[ :parent_ids_in ]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Use double pipes ||
instead. Open
"alt_text" => self.image.alt_text ? self.image.alt_text : self.image.image_file_name,
- Read upRead up
- Exclude checks
This cop checks for unnecessary conditional expressions.
Example:
# bad
a = b ? b : c
# good
a = b || c
Example:
# bad
if b
b
else
c
end
# good
b || c
# good
if b
b
elsif cond
c
end