You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This cop checks block parameter names for how descriptive they
are. It is highly configurable.
The MinNameLength config option takes an integer. It represents
the minimum amount of characters the name must be. Its default is 1.
The AllowNamesEndingInNumbers config option takes a boolean. When
set to false, this cop will register offenses for names ending with
numbers. Its default is false. The AllowedNames config option
takes an array of permitted names that will never register an
offense. The ForbiddenNames config option takes an array of
restricted names that will always register an offense.
Examples
# badbardo |varOne,varTwo|
varOne + varTwoend# With `AllowNamesEndingInNumbers` set to falsefoo{ |num1,num2| num1 * num2}# With `MinParamNameLength` set to number greater than 1baz{ |a,b,c| do_stuff(a,b,c)}# goodbardo |thud,fred|
thud + fredendfoo{ |speed,distance| speed * distance}baz{ |age,height,gender| do_stuff(age,height,gender)}
Configurable attributes
Name
Default value
Configurable values
MinNameLength
1
Integer
AllowNamesEndingInNumbers
true
Boolean
AllowedNames
[]
Array
ForbiddenNames
[]
Array
Naming/ClassAndModuleCamelCase
Enabled by default
Safe
Supports autocorrection
VersionAdded
VersionChanged
Enabled
Yes
No
0.50
-
This cop checks for class and module names with
an underscore in them.
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.
The cop also ignores .gemspec files, because Bundler
recommends using dashes to separate namespaces in nested gems
(i.e. bundler-console becomes Bundler::Console). As such, the
gemspec is supposed to be named bundler-console.gemspec.
This cop checks that your heredocs are using meaningful delimiters.
By default it disallows END and EO*, and can be configured through
forbidden listing additional delimiters.
Examples
# good<<-SQL SELECT * FROM fooSQL# bad<<-END SELECT * FROM fooEND# bad<<-EOS SELECT * FROM fooEOS
This cop checks for memoized methods whose instance variable name
does not match the method name.
This cop can be configured with the EnforcedStyleForLeadingUnderscores
directive. It can be configured to allow for memoized instance variables
prefixed with an underscore. Prefixing ivars with an underscore is a
convention that is used to implicitly indicate that an ivar should not
be set or referenced outside of the memoization method.
# bad# Method foo is memoized using an instance variable that is# not `@foo`. This can cause confusion and bugs.deffoo@something ||= calculate_expensive_thingend# gooddef_foo@foo ||= calculate_expensive_thingend# gooddeffoo@foo ||= calculate_expensive_thingend# gooddeffoo@foo ||= begincalculate_expensive_thingendend# gooddeffoohelper_variable=something_we_need_to_calculate_foo@foo ||= calculate_expensive_thing(helper_variable)end
This cop checks method parameter names for how descriptive they
are. It is highly configurable.
The MinNameLength config option takes an integer. It represents
the minimum amount of characters the name must be. Its default is 3.
The AllowNamesEndingInNumbers config option takes a boolean. When
set to false, this cop will register offenses for names ending with
numbers. Its default is false. The AllowedNames config option
takes an array of permitted names that will never register an
offense. The ForbiddenNames config option takes an array of
restricted names that will always register an offense.
Examples
# baddefbar(varOne,varTwo)varOne + varTwoend# With `AllowNamesEndingInNumbers` set to falsedeffoo(num1,num2)num1 * num2end# With `MinArgNameLength` set to number greater than 1defbaz(a,b,c)do_stuff(a,b,c)end# gooddefbar(thud,fred)thud + fredenddeffoo(speed,distance)speed * distanceenddefbaz(age_a,height_b,gender_c)do_stuff(age_a,height_b,gender_c)end
Configurable attributes
Name
Default value
Configurable values
MinNameLength
3
Integer
AllowNamesEndingInNumbers
true
Boolean
AllowedNames
io, id, to, by, on, in, at, ip, db, os, pp
Array
ForbiddenNames
[]
Array
Naming/PredicateName
Enabled by default
Safe
Supports autocorrection
VersionAdded
VersionChanged
Enabled
Yes
No
0.50
0.77
This cop makes sure that predicates are named properly.
This cop makes sure that rescued exceptions variables are named as
expected.
The PreferredName config option takes a String. It represents
the required name of the variable. Its default is e.
Examples
PreferredName: e (default)
# badbegin# do somethingrescueMyException=>exception# do somethingend# goodbegin# do somethingrescueMyException=>e# do somethingend# goodbegin# do somethingrescueMyException=>_e# do somethingend
PreferredName: exception
# badbegin# do somethingrescueMyException=>e# do somethingend# goodbegin# do somethingrescueMyException=>exception# do somethingend# goodbegin# do somethingrescueMyException=>_exception# do somethingend
Configurable attributes
Name
Default value
Configurable values
PreferredName
e
String
Naming/VariableName
Enabled by default
Safe
Supports autocorrection
VersionAdded
VersionChanged
Enabled
Yes
No
0.50
-
This cop makes sure that all variables use the configured style,
snake_case or camelCase, for their names.