Showing 436 of 436 total issues
if
condition requires an else
-clause. Open
elsif options[:payload]
call_to_action_content[:type] = 'postback'
# Encode the payload hash as JSON.
call_to_action_content[:payload] = JSON.generate(options[:payload])
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for if
expressions that do not have an else
branch.
SupportedStyles
if
Example:
# bad
if condition
statement
end
case
Example:
# bad
case var
when condition
statement
end
Example:
# good
if condition
statement
else
# the content of the else branch will be determined by Style/EmptyElse
end
Redundant self
detected. (https://github.com/voxable-labs/voxable-style-guide#no-self-unless-required) Open
self.to_s.tableize
- Read upRead up
- Create a ticketCreate a ticket
- 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. (https://github.com/voxable-labs/voxable-style-guide#no-self-unless-required) Open
Hg::MessageWorker.perform_async(user_id, redis_namespace, self.to_s)
- Read upRead up
- Create a ticketCreate a ticket
- 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
=
is not aligned with the following assignment. Open
@params = ActiveSupport::HashWithIndifferentAccess.new(request.parameters || request.params)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/bbatsov/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/bbatsov/rubocop"
Line is too long. [82/80] (https://github.com/voxable-labs/voxable-style-guide#80-character-limits) Open
# TODO: pass in a `user_id_field` to indicate how to find user in order to
- Create a ticketCreate a ticket
- Exclude checks
Line is too long. [84/80] (https://github.com/voxable-labs/voxable-style-guide#80-character-limits) Open
# from ActionController. They can either be accessed in their normal form, or with
- Create a ticketCreate a ticket
- Exclude checks
Use alias
instead of alias_method
in a class body. (https://github.com/voxable-labs/voxable-style-guide#alias-method) Open
alias_method :params, :parameters
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop enforces the use of either #alias
or #alias_method
depending on configuration.
It also flags uses of alias :symbol
rather than alias bareword
.
Example: EnforcedStyle: prefer_alias (default)
# bad
alias_method :bar, :foo
alias :bar :foo
# good
alias bar foo
Example: EnforcedStyle: preferaliasmethod
# bad
alias :bar :foo
alias bar foo
# good
alias_method :bar, :foo
Line is too long. [98/80] (https://github.com/voxable-labs/voxable-style-guide#80-character-limits) Open
@params = ActiveSupport::HashWithIndifferentAccess.new(request.parameters || request.params)
- Create a ticketCreate a ticket
- Exclude checks
Missing top-level class documentation comment. Open
class QueryError < StandardError
- Read upRead up
- Create a ticketCreate a ticket
- 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
Freeze mutable objects assigned to constants. Open
VERSION = "0.1.0"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).
Example:
# bad
CONST = [1, 2, 3]
# good
CONST = [1, 2, 3].freeze
=
is not aligned with the preceding assignment. Open
base.call_to_actions = []
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/bbatsov/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/bbatsov/rubocop"
=
is not aligned with the following assignment. Open
call_to_action_content[:type] = 'postback'
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/bbatsov/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/bbatsov/rubocop"
Add a line break before the first argument of a multi-line method argument list. Open
Facebook::Messenger::Profile.set({
greeting: [
{
locale: 'default',
text: @greeting_text
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for a line break before the first argument in a multi-line method call.
Example:
# bad
method(foo, bar,
baz)
# good
method(
foo, bar,
baz)
# ignored
method foo, bar,
baz
Indent the right brace the same as the first position after the preceding left parenthesis. Open
}, access_token: access_token)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cops checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the AlignHash cop.
By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.
Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.
This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:
Example: EnforcedStyle: specialinsideparentheses (default)
# The `special_inside_parentheses` style enforces that the first key
# in a hash literal where the opening brace and the first key are on
# separate lines is indented one step (two spaces) more than the
# position inside the opening parentheses.
# bad
hash = {
key: :value
}
and_in_a_method_call({
no: :difference
})
# good
special_inside_parentheses
hash = {
key: :value
}
but_in_a_method_call({
its_like: :this
})
Example: EnforcedStyle: consistent
# The `consistent` style enforces that the first key in a hash
# literal where the opening brace and the first key are on
# seprate lines is indented the same as a hash literal which is not
# defined inside a method call.
# bad
hash = {
key: :value
}
but_in_a_method_call({
its_like: :this
})
# good
hash = {
key: :value
}
and_in_a_method_call({
no: :difference
})
Example: EnforcedStyle: align_braces
# The `align_brackets` style enforces that the opening and closing
# braces are indented to the same position.
# bad
and_now_for_something = {
completely: :different
}
# good
and_now_for_something = {
completely: :different
}
module_inclusion
is supposed to appear before public_methods
. (https://github.com/bbatsov/ruby-style-guide#consistent-classes) Open
include AbstractController::Callbacks
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks if the code style follows the ExpectedOrder configuration:
Categories
allows us to map macro names into a category.
Consider an example of code style that covers the following order: - Constants - Associations (hasone, hasmany) - Attributes (attraccessor, attrwriter, attr_reader) - Initializer - Instance methods - Protected methods - Private methods
You can configure the following order:
Layout/ClassStructure:
Categories:
module_inclusion:
- include
- prepend
- extend
ExpectedOrder:
- module_inclusion
- constants
- public_class_methods
- initializer
- public_methods
- protected_methods
- private_methods
Instead of putting all literals in the expected order, is also possible to group categories of macros.
Layout/ClassStructure:
Categories:
association:
- has_many
- has_one
attribute:
- attr_accessor
- attr_reader
- attr_writer
Example:
# bad
# Expect extend be before constant
class Person < ApplicationRecord
has_many :orders
ANSWER = 42
extend SomeModule
include AnotherModule
end
# good
class Person
# extend and include go first
extend SomeModule
include AnotherModule
# inner classes
CustomError = Class.new(StandardError)
# constants are next
SOME_CONSTANT = 20
# afterwards we have attribute macros
attr_reader :name
# followed by other macros (if any)
validates :name
# public class methods are next in line
def self.some_method
end
# initialization goes between class methods and instance methods
def initialize
end
# followed by other public instance methods
def some_method
end
# protected and private methods are grouped near the end
protected
def some_protected_method
end
private
def some_private_method
end
end
@see https://github.com/bbatsov/ruby-style-guide#consistent-classes
Use alias
instead of alias_method
in a class body. (https://github.com/voxable-labs/voxable-style-guide#alias-method) Open
alias_method :send_action, :send
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop enforces the use of either #alias
or #alias_method
depending on configuration.
It also flags uses of alias :symbol
rather than alias bareword
.
Example: EnforcedStyle: prefer_alias (default)
# bad
alias_method :bar, :foo
alias :bar :foo
# good
alias bar foo
Example: EnforcedStyle: preferaliasmethod
# bad
alias :bar :foo
alias bar foo
# good
alias_method :bar, :foo
Use alias
instead of alias_method
in a class body. (https://github.com/voxable-labs/voxable-style-guide#alias-method) Open
alias_method :append_before_handler, :append_before_action
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop enforces the use of either #alias
or #alias_method
depending on configuration.
It also flags uses of alias :symbol
rather than alias bareword
.
Example: EnforcedStyle: prefer_alias (default)
# bad
alias_method :bar, :foo
alias :bar :foo
# good
alias bar foo
Example: EnforcedStyle: preferaliasmethod
# bad
alias :bar :foo
alias bar foo
# good
alias_method :bar, :foo
if
condition requires an else
-clause. Open
if ENV['CHATBASE_API_KEY']
@client.set_chatbase_fields(
request.action,
message.text,
false)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for if
expressions that do not have an else
branch.
SupportedStyles
if
Example:
# bad
if condition
statement
end
case
Example:
# bad
case var
when condition
statement
end
Example:
# good
if condition
statement
else
# the content of the else branch will be determined by Style/EmptyElse
end
Use parentheses for method calls with arguments. (https://github.com/voxable-labs/voxable-style-guide#method-invocation-parens) Open
build_payload_request @postback.payload, user
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks presence of parentheses in method calls containing
parameters. By default, macro methods are ignored. Additional methods
can be added to the IgnoredMethods
list.
Example:
# bad
array.delete e
# good
array.delete(e)
# good
# Operators don't need parens
foo == bar
# good
# Setter methods don't need parens
foo.bar = baz
# okay with `puts` listed in `IgnoredMethods`
puts 'test'
# IgnoreMacros: true (default)
# good
class Foo
bar :baz
end
# IgnoreMacros: false
# bad
class Foo
bar :baz
end
Script file rails doesn't have execute permission. Open
#!/usr/bin/env ruby
- Create a ticketCreate a ticket
- Exclude checks