Showing 1,009 of 1,009 total issues
Favor a normal unless-statement over a modifier clause in a multiline statement. Open
Paperclip.interpolates(:s3_domain_url) do |attachment, style|
"#{attachment.s3_protocol(style, true)}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).sub(%r{\A/}, "".freeze)}"
end unless Paperclip::Interpolations.respond_to? :s3_domain_url
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Line is too long. [94/80] Open
# If you set :override_file_permissions to false, the chmod will be skipped. This allows
- Exclude checks
Line is too long. [87/80] Open
log("There was an unexpected error while deleting directories: #{e.class}")
- Exclude checks
Line is too long. [143/80] Open
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX = /\A(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}\z))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]\z/
- Exclude checks
Line is too long. [82/80] Open
warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
- Exclude checks
Prefer using YAML.safe_load
over YAML.load
. Open
YAML::load(ERB.new(File.read(creds)).result)
- Read upRead up
- Exclude checks
This cop checks for the use of YAML class methods which have potential security issues leading to remote code execution when loading from an untrusted source.
Example:
# bad
YAML.load("--- foo")
# good
YAML.safe_load("--- foo")
YAML.dump("foo")
URI.escape
method is obsolete and should not be used. Instead, use CGI.escape
, URI.encode_www_form
or URI.encode_www_form_component
depending on your specific use case. Open
URI.escape(url).gsub(escape_regex){|m| "%#{m.ord.to_s(16).upcase}" }
- Read upRead up
- Exclude checks
This cop identifies places where URI.escape
can be replaced by
CGI.escape
, URI.encode_www_form
or URI.encode_www_form_component
depending on your specific use case.
Also this cop identifies places where URI.unescape
can be replaced by
CGI.unescape
, URI.decode_www_form
or URI.decode_www_form_component
depending on your specific use case.
Example:
# bad
URI.escape('http://example.com')
URI.encode('http://example.com')
# good
CGI.escape('http://example.com')
URI.encode_www_form([['example', 'param'], ['lang', 'en']])
URI.encode_www_form(page: 10, locale: 'en')
URI.encode_www_form_component('http://example.com')
# bad
URI.unescape(enc_uri)
URI.decode(enc_uri)
# good
CGI.unescape(enc_uri)
URI.decode_www_form(enc_uri)
URI.decode_www_form_component(enc_uri)
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Open
require 'uri'
- 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"
Useless assignment to variable - path
. Open
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Space found before comma. Open
scale = [new_geometry.width.to_f / self.width.to_f , new_geometry.height.to_f / self.height.to_f].min
- Read upRead up
- Exclude checks
Checks for comma (,) preceded by space.
Example:
# bad
[1 , 2 , 3]
a(1 , 2)
each { |a , b| }
# good
[1, 2, 3]
a(1, 2)
each { |a, b| }
Do not use space inside array brackets. Open
[ "x%d" % dst.height, ratio.height ]
- Read upRead up
- Exclude checks
Checks that brackets used for array literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that array literals have
# surrounding space.
# bad
array = [a, b, c, d]
# good
array = [ a, b, c, d ]
Example: EnforcedStyle: no_space
# The `no_space` style enforces that array literals have
# no surrounding space.
# bad
array = [ a, b, c, d ]
# good
array = [a, b, c, d]
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# array brackets, with the exception that successive left
# or right brackets are collapsed together in nested arrays.
# bad
array = [ a, [ b, c ] ]
# good
array = [ a, [ b, c ]]
Line is too long. [88/80] Open
# Other storage classes, such as <tt>:STANDARD_IA</tt>, are also available—see the
- Exclude checks
Line is too long. [87/80] Open
raise ArgumentError, "Credentials given are not a path, file, proc, or hash."
- Exclude checks
Do not use space inside array brackets. Open
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
- Read upRead up
- Exclude checks
Checks that brackets used for array literals have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space
# The `space` style enforces that array literals have
# surrounding space.
# bad
array = [a, b, c, d]
# good
array = [ a, b, c, d ]
Example: EnforcedStyle: no_space
# The `no_space` style enforces that array literals have
# no surrounding space.
# bad
array = [ a, b, c, d ]
# good
array = [a, b, c, d]
Example: EnforcedStyle: compact
# The `compact` style normally requires a space inside
# array brackets, with the exception that successive left
# or right brackets are collapsed together in nested arrays.
# bad
array = [ a, [ b, c ] ]
# good
array = [ a, [ b, c ]]
Useless assignment to variable - e
. Open
rescue Errno::ENOENT => e
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Line is too long. [90/80] Open
"%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
- Exclude checks
Line is too long. [86/80] Open
# almost all cases, should) be coordinated with the value of the +url+ option to
- Exclude checks
Prefer annotated tokens (like %<foo>s</foo>
) over unannotated tokens (like %s
). Open
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
- Read upRead up
- Exclude checks
Use a consistent style for named format string tokens.
Note:
unannotated
style cop only works for strings
which are passed as arguments to those methods:
sprintf
, format
, %
.
The reason is that unannotated format is very similar
to encoded URLs or Date/Time formatting strings.
Example: EnforcedStyle: annotated (default)
# bad
format('%{greeting}', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%<greeting>s', greeting: 'Hello')</greeting>
Example: EnforcedStyle: template
# bad
format('%<greeting>s', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%{greeting}', greeting: 'Hello')</greeting>
Example: EnforcedStyle: unannotated
# bad
format('%<greeting>s', greeting: 'Hello')
format('%{greeting}', 'Hello')
# good
format('%s', 'Hello')</greeting>
Use 0o for octal literals. Open
resolved_chmod = (@options[:override_file_permissions] & ~0111) || (0666 & ~File.umask)
- Read upRead up
- Exclude checks
This cop checks for octal, hex, binary and decimal literals using
uppercase prefixes and corrects them to lowercase prefix
or no prefix (in case of decimals).
eg. for octal use 0o
instead of 0
or 0O
.
Can be configured to use 0
only for octal literals using
EnforcedOctalStyle
=> zero_only
Prefer annotated tokens (like %<foo>s</foo>
) over unannotated tokens (like %s
). Open
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
- Read upRead up
- Exclude checks
Use a consistent style for named format string tokens.
Note:
unannotated
style cop only works for strings
which are passed as arguments to those methods:
sprintf
, format
, %
.
The reason is that unannotated format is very similar
to encoded URLs or Date/Time formatting strings.
Example: EnforcedStyle: annotated (default)
# bad
format('%{greeting}', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%<greeting>s', greeting: 'Hello')</greeting>
Example: EnforcedStyle: template
# bad
format('%<greeting>s', greeting: 'Hello')
format('%s', 'Hello')
# good
format('%{greeting}', greeting: 'Hello')</greeting>
Example: EnforcedStyle: unannotated
# bad
format('%<greeting>s', greeting: 'Hello')
format('%{greeting}', 'Hello')
# good
format('%s', 'Hello')</greeting>