Use keyword arguments when defining method with boolean argument. Open
def setup_redis_env_url(prefix = nil, defaults = true)
- Read upRead up
- Exclude checks
This cop checks for places where keyword arguments can be used instead of
boolean arguments when defining methods. respond_to_missing?
method is allowed by default.
These are customizable with AllowedMethods
option.
Example:
# bad
def some_method(bar = false)
puts bar
end
# bad - common hack before keyword args were introduced
def some_method(options = {})
bar = options.fetch(:bar, false)
puts bar
end
# good
def some_method(bar: false)
puts bar
end
Example: AllowedMethods: ['some_method']
# good
def some_method(bar = false)
puts bar
end
Prefer string interpolation to string concatenation. Open
cache_namespace = namespace ? namespace + '_cache' : 'cache'
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Prefer string interpolation to string concatenation. Open
db = ENV.fetch(prefix + 'REDIS_DB') { 0 if defaults }
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Prefer string interpolation to string concatenation. Open
return if ENV[prefix + 'REDIS_URL'].present?
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Prefer string interpolation to string concatenation. Open
password = ENV.fetch(prefix + 'REDIS_PASSWORD') { '' if defaults }
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Prefer string interpolation to string concatenation. Open
port = ENV.fetch(prefix + 'REDIS_PORT') { 6379 if defaults }
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Prefer string interpolation to string concatenation. Open
ENV[prefix + 'REDIS_URL'] = if [password, host, port, db].all?(&:nil?)
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Prefer string interpolation to string concatenation. Open
host = ENV.fetch(prefix + 'REDIS_HOST') { 'localhost' if defaults }
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'
Prefer string interpolation to string concatenation. Open
prefix = prefix.to_s.upcase + '_' unless prefix.nil?
- Read upRead up
- Exclude checks
This cop checks for places where string concatenation can be replaced with string interpolation.
The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.
NOTE: When concatenation between two strings is broken over multiple
lines, this cop does not register an offense; instead,
Style/LineEndConcatenation
will pick up the offense if enabled.
Example:
# bad
email_with_name = user.name + ' '
# good
email_with_name = "#{user.name} "
email_with_name = format('%s ', user.name, user.email)
# accepted, line-end concatenation
name = 'First' +
'Last'