Showing 319 of 319 total issues
Use &&
instead of and
. Open
(date != "" and date != "nil" and not date.nil?) ? date : Time.new.strftime("%Y-%m-%d %H:%M:%S %Z")
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Use &&
instead of and
. Open
(date != "" and date != "nil" and not date.nil?) ? date : Time.new.strftime("%Y-%m-%d %H:%M:%S %Z")
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Space missing to the left of {. Open
Dir.glob("./#{cur_dir}/lib/**/*").select{|f| File.file? f}.each{|f| require f}
- Read upRead up
- Exclude checks
Checks that block braces have or don't have a space before the opening brace depending on configuration.
Example:
# bad
foo.map{ |a|
a.bar.to_s
}
# good
foo.map { |a|
a.bar.to_s
}
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
f.puts "layout: default"
- 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"
Line is too long. [108/80] Open
puts "Building while running other tasks (e.g., preview), might create a website with broken links.\n\n"
- Exclude checks
Do not introduce global variables. Open
$git_check ||= true
- Read upRead up
- Exclude checks
This cops looks for uses of global variables. It does not report offenses for built-in global variables. Built-in global variables are allowed by default. Additionally users can allow additional variables via the AllowedVariables option.
Note that backreferences like $1, $2, etc are not global variables.
Example:
# bad
$foo = 2
bar = $foo + 5
# good
FOO = 2
foo = 2
$stdin.read
Do not use then
for multi-line if
. Open
if git_requires_attention("gh_pages") then
- Read upRead up
- Exclude checks
Checks for uses of the then
keyword in multi-line if statements.
Example:
# bad
# This is considered bad practice.
if cond then
end
# good
# If statements can contain `then` on the same line.
if cond then a
elsif cond then b
end
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
puts "Error! deploy_url not found in _config_deploy.yml"
- 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"
Use ||
instead of or
. Open
if File.extname(filename) == ".textile" or File.extname(filename) == ".md" then
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Use backticks around command string. Open
%x{git diff --name-only} != ""
- Read upRead up
- Exclude checks
This cop enforces using `` or %x around command literals.
Example: EnforcedStyle: backticks (default)
# bad
folders = %x(find . -type d).split
# bad
%x(
ln -s foo.example.yml foo.example
ln -s bar.example.yml bar.example
)
# good
folders = `find . -type d`.split
# good
`
ln -s foo.example.yml foo.example
ln -s bar.example.yml bar.example
`
Example: EnforcedStyle: mixed
# bad
folders = %x(find . -type d).split
# bad
`
ln -s foo.example.yml foo.example
ln -s bar.example.yml bar.example
`
# good
folders = `find . -type d`.split
# good
%x(
ln -s foo.example.yml foo.example
ln -s bar.example.yml bar.example
)
Example: EnforcedStyle: percent_x
# bad
folders = `find . -type d`.split
# bad
`
ln -s foo.example.yml foo.example
ln -s bar.example.yml bar.example
`
# good
folders = %x(find . -type d).split
# good
%x(
ln -s foo.example.yml foo.example
ln -s bar.example.yml bar.example
)
Example: AllowInnerBackticks: false (default)
# If `false`, the cop will always recommend using `%x` if one or more
# backticks are found in the command string.
# bad
`echo \`ls\``
# good
%x(echo `ls`)
Example: AllowInnerBackticks: true
# good
`echo \`ls\``
Line is too long. [83/80] Open
# Handle inserting screen shots into markdown and copying those to the images dir
- Exclude checks
Unnecessary spacing detected. Open
def get_unique_filename()
- Read upRead up
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/bbatsov/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/bbatsov/rubocop"
Line is too long. [82/80] Open
filename = @date[0..9] + "-" + JekyllRake::Utils.slugify(@title) + $post_ext
- Exclude checks
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
f.puts "---"
- 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"
Do not use do
with multi-line while
. Open
while File.exists?(@post_dir + filename) do
- Read upRead up
- Exclude checks
Checks for uses of do
in multi-line while/until
statements.
Example:
# bad
while x.any? do
do_something(x.pop)
end
# good
while x.any?
do_something(x.pop)
end
Example:
# bad
until x.empty? do
do_something(x.pop)
end
# good
until x.empty?
do_something(x.pop)
end
Line is too long. [81/80] Open
# strip characters and whitespace to create valid filenames, also lowercase
- Exclude checks
Operator =
should be surrounded by a single space. Open
spec.files = `git ls-files -z`.split("\x0").reject do |f|
- Read upRead up
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b
Line is too long. [90/80] Open
# to allow pushing to a single host or delete this section to allow pushing to any host.
- Exclude checks
%q
-literals should be delimited by (
and )
. Open
spec.description = %q{Write a longer description or delete this line.}
- Read upRead up
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)
Do not introduce global variables. Open
$post_ext ||= ".markdown"
- Read upRead up
- Exclude checks
This cops looks for uses of global variables. It does not report offenses for built-in global variables. Built-in global variables are allowed by default. Additionally users can allow additional variables via the AllowedVariables option.
Note that backreferences like $1, $2, etc are not global variables.
Example:
# bad
$foo = 2
bar = $foo + 5
# good
FOO = 2
foo = 2
$stdin.read