bin/spring
Prefer find
over detect
. (https://rubystyle.guide#map-find-select-reduce-include-size) Open
Open
if spring = lockfile.specs.detect { |spec| spec.name == "spring" }
- Read upRead up
- Exclude checks
Enforces the use of consistent method names from the Enumerable module.
You can customize the mapping from undesired method to desired method.
e.g. to use detect
over find
:
Style/CollectionMethods:
PreferredMethods:
find: detect
Safety:
This cop is unsafe because it finds methods by name, without actually being able to determine if the receiver is an Enumerable or not, so this cop may register false positives.
Example:
# These examples are based on the default mapping for `PreferredMethods`.
# bad
items.collect
items.collect!
items.inject
items.detect
items.find_all
items.member?
# good
items.map
items.map!
items.reduce
items.find
items.select
items.include?
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. (https://rubystyle.guide#safe-assignment-in-condition) Open
Open
if spring = lockfile.specs.detect { |spec| spec.name == "spring" }
- Read upRead up
- Exclude checks
Checks for assignments in the conditions of if/while/until.
AllowSafeAssignment
option for safe assignment.
By safe assignment we mean putting parentheses around
an assignment to indicate "I know I'm using an assignment
as a condition. It's not a mistake."
Example:
# bad
if some_var = true
do_something
end
# good
if some_var == true
do_something
end
Example: AllowSafeAssignment: true (default)
# good
if (some_var = true)
do_something
end
Example: AllowSafeAssignment: false
# bad
if (some_var = true)
do_something
end
Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://rubystyle.guide#consistent-string-literals) Open
Open
if spring = lockfile.specs.detect { |spec| spec.name == "spring" }
- 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"