Goldencobra::Author has no descriptive comment Open
class Author < 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
Unnecessary spacing detected. Open
has_many :articles, through: :article_authors
- Read upRead up
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/rubocop-hq/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/rubocop-hq/rubocop"
Missing top-level class documentation comment. Open
class Author < 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
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.try(:firstname), self.try(:lastname)].join(" ")
- 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
Use 2 (not 3) spaces for indentation. Open
attr_accessible :firstname, :lastname, :email, :googleplus
- 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
Tab detected. Open
[self.try(:firstname), self.try(:lastname)].join(" ")
- Read upRead up
- Exclude checks
This cop checks for tabs inside the source code.
Example:
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Put one space between the method name and the first argument. Open
has_many :articles, through: :article_authors
- Read upRead up
- Exclude checks
Checks that exactly one space is used between a method name and the first argument for method calls without parentheses.
Alternatively, extra spaces can be added to align the argument with something on a preceding or following line, if the AllowForAlignment config parameter is true.
Example:
# bad
something x
something y, z
something'hello'
# good
something x
something y, z
something 'hello'
Tab detected. Open
def title
- Read upRead up
- Exclude checks
This cop checks for tabs inside the source code.
Example:
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Use 2 (not 1) spaces for indentation. Open
class Author < ActiveRecord::Base
- 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
Tab detected. Open
web_url :googleplus
- Read upRead up
- Exclude checks
This cop checks for tabs inside the source code.
Example:
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Unnecessary spacing detected. Open
has_many :article_authors
- Read upRead up
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/rubocop-hq/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/rubocop-hq/rubocop"
Inconsistent indentation detected. Open
def title
[self.try(:firstname), self.try(:lastname)].join(" ")
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
The difference between rails
and normal
is that the rails
style
prescribes that in classes and modules the protected
and private
modifier keywords shall be indented the same as public methods and that
protected and private members shall be indented one step more than the
modifiers. Other than that, both styles mean that entities on the same
logical depth shall have the same indentation.
Example: EnforcedStyle: normal (default)
# bad
class A
def test
puts 'hello'
puts 'world'
end
end
# bad
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
Example: EnforcedStyle: rails
# bad
class A
def test
puts 'hello'
puts 'world'
end
end
# bad
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
Tab detected. Open
end
- Read upRead up
- Exclude checks
This cop checks for tabs inside the source code.
Example:
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Put one space between the method name and the first argument. Open
has_many :article_authors
- Read upRead up
- Exclude checks
Checks that exactly one space is used between a method name and the first argument for method calls without parentheses.
Alternatively, extra spaces can be added to align the argument with something on a preceding or following line, if the AllowForAlignment config parameter is true.
Example:
# bad
something x
something y, z
something'hello'
# good
something x
something y, z
something 'hello'
Use 2 (not 1) spaces for indentation. Open
[self.try(:firstname), self.try(:lastname)].join(" ")
- 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
Tab detected. Open
end
- Read upRead up
- Exclude checks
This cop checks for tabs inside the source code.
Example:
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
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.
Tab detected. Open
has_many :article_authors
- Read upRead up
- Exclude checks
This cop checks for tabs inside the source code.
Example:
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Redundant self
detected. Open
[self.try(:firstname), self.try(:lastname)].join(" ")
- 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
Tab detected. Open
class Author < ActiveRecord::Base
- Read upRead up
- Exclude checks
This cop checks for tabs inside the source code.
Example:
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Inconsistent indentation detected. Open
has_many :article_authors
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
The difference between rails
and normal
is that the rails
style
prescribes that in classes and modules the protected
and private
modifier keywords shall be indented the same as public methods and that
protected and private members shall be indented one step more than the
modifiers. Other than that, both styles mean that entities on the same
logical depth shall have the same indentation.
Example: EnforcedStyle: normal (default)
# bad
class A
def test
puts 'hello'
puts 'world'
end
end
# bad
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
Example: EnforcedStyle: rails
# bad
class A
def test
puts 'hello'
puts 'world'
end
end
# bad
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
Inconsistent indentation detected. Open
web_url :googleplus
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
The difference between rails
and normal
is that the rails
style
prescribes that in classes and modules the protected
and private
modifier keywords shall be indented the same as public methods and that
protected and private members shall be indented one step more than the
modifiers. Other than that, both styles mean that entities on the same
logical depth shall have the same indentation.
Example: EnforcedStyle: normal (default)
# bad
class A
def test
puts 'hello'
puts 'world'
end
end
# bad
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
Example: EnforcedStyle: rails
# bad
class A
def test
puts 'hello'
puts 'world'
end
end
# bad
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
end
# good
class A
def test
puts 'hello'
puts 'world'
end
protected
def foo
end
private
def bar
end
end