Naming

Naming/AccessorMethodName

Enabled by default Supports autocorrection
Enabled No

This cop makes sure that accessor methods are named properly.

Examples

# bad
def set_attribute(value)
end

# good
def attribute=(value)
end

# bad
def get_attribute
end

# good
def attribute
end

References

Naming/AsciiIdentifiers

Enabled by default Supports autocorrection
Enabled No

This cop checks for non-ascii characters in identifier names.

Examples

# bad
def καλημερα # Greek alphabet (non-ascii)
end

# bad
def こんにちはと言う # Japanese character (non-ascii)
end

# bad
def hello_🍣 # Emoji (non-ascii)
end

# good
def say_hello
end

# bad
신장 = 10 # Hangul character (non-ascii)

# good
height = 10

# bad
params[:عرض_gteq] # Arabic character (non-ascii)

# good
params[:width_gteq]

References

Naming/BinaryOperatorParameterName

Enabled by default Supports autocorrection
Enabled No

This cop makes sure that certain binary operator methods have their sole parameter named other.

Examples

# bad
def +(amount); end

# good
def +(other); end

References

Naming/ClassAndModuleCamelCase

Enabled by default Supports autocorrection
Enabled No

This cops checks for class and module names with an underscore in them.

Examples

# bad
class My_Class
end
module My_Module
end

# good
class MyClass
end
module MyModule
end

References

Naming/ConstantName

Enabled by default Supports autocorrection
Enabled No

This cop checks whether constant names are written using SCREAMING_SNAKE_CASE.

To avoid false positives, it ignores cases in which we cannot know for certain the type of value that would be assigned to a constant.

Examples

# bad
InchInCm = 2.54
INCHinCM = 2.54
Inch_In_Cm = 2.54

# good
INCH_IN_CM = 2.54

References

Naming/FileName

Enabled by default Supports autocorrection
Enabled No

This cop makes sure that Ruby source files have snake_case names. Ruby scripts (i.e. source files with a shebang in the first line) are ignored.

Examples

# bad
lib/layoutManager.rb

anything/usingCamelCase

# good
lib/layout_manager.rb

anything/using_snake_case.rake

Configurable attributes

Name Default value Configurable values
Exclude [] Array
ExpectMatchingDefinition false Boolean
Regex <none>
IgnoreExecutableScripts true Boolean
AllowedAcronyms CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS Array

References

Naming/HeredocDelimiterCase

Enabled by default Supports autocorrection
Enabled No

This cop checks that your heredocs are using the configured case. By default it is configured to enforce uppercase heredocs.

Examples

EnforcedStyle: uppercase (default)

# bad
<<-sql
  SELECT * FROM foo
sql

# good
<<-SQL
  SELECT * FROM foo
SQL

EnforcedStyle: lowercase

# bad
<<-SQL
  SELECT * FROM foo
SQL

# good
<<-sql
  SELECT * FROM foo
sql

Configurable attributes

Name Default value Configurable values
EnforcedStyle uppercase lowercase, uppercase

References

Naming/HeredocDelimiterNaming

Enabled by default Supports autocorrection
Enabled No

This cop checks that your heredocs are using meaningful delimiters. By default it disallows END and EO*, and can be configured through blacklisting additional delimiters.

Examples

# good
<<-SQL
  SELECT * FROM foo
SQL

# bad
<<-END
  SELECT * FROM foo
END

# bad
<<-EOS
  SELECT * FROM foo
EOS

Configurable attributes

Name Default value Configurable values
Blacklist END, (?-mix:EO[A-Z]{1}) Array

References

Naming/MethodName

Enabled by default Supports autocorrection
Enabled No

This cop makes sure that all methods use the configured style, snake_case or camelCase, for their names.

Examples

EnforcedStyle: snake_case (default)

# bad
def fooBar; end

# good
def foo_bar; end

EnforcedStyle: camelCase

# bad
def foo_bar; end

# good
def fooBar; end

Configurable attributes

Name Default value Configurable values
EnforcedStyle snake_case snake_case, camelCase

References

Naming/PredicateName

Enabled by default Supports autocorrection
Enabled No

This cop makes sure that predicates are named properly.

Examples

# bad
def is_even?(value)
end

# good
def even?(value)
end

# bad
def has_value?
end

# good
def value?
end

Configurable attributes

Name Default value Configurable values
NamePrefix is_, has_, have_ Array
NamePrefixBlacklist is_, has_, have_ Array
NameWhitelist is_a? Array
MethodDefinitionMacros define_method, define_singleton_method Array
Exclude spec/**/* Array

References

Naming/VariableName

Enabled by default Supports autocorrection
Enabled No

This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

Examples

EnforcedStyle: snake_case (default)

# bad
fooBar = 1

# good
foo_bar = 1

EnforcedStyle: camelCase

# bad
foo_bar = 1

# good
fooBar = 1

Configurable attributes

Name Default value Configurable values
EnforcedStyle snake_case snake_case, camelCase

References

Naming/VariableNumber

Enabled by default Supports autocorrection
Enabled No

This cop makes sure that all numbered variables use the configured style, snake_case, normalcase or non_integer, for their numbering.

Examples

EnforcedStyle: snake_case

# bad

variable1 = 1

# good

variable_1 = 1

EnforcedStyle: normalcase (default)

# bad

variable_1 = 1

# good

variable1 = 1

EnforcedStyle: non_integer

# bad

variable1 = 1

variable_1 = 1

# good

variableone = 1

variable_one = 1

Configurable attributes

Name Default value Configurable values
EnforcedStyle normalcase snake_case, normalcase, non_integer