Block has too many lines. [26/25] Open
guard :rspec, cmd: "bundle exec rspec -f doc" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# Feel free to open issues for suggestions and improvements
- Read upRead up
- Exclude checks
Checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
You can set constructs you want to fold with CountAsOne
.
Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct
will be counted as one line regardless of its actual size.
NOTE: This cop does not apply for Struct
definitions.
NOTE: The ExcludedMethods
configuration is deprecated and only kept
for backwards compatibility. Please use AllowedMethods
and AllowedPatterns
instead. By default, there are no methods to allowed.
Example: CountAsOne: ['array', 'heredoc', 'method_call']
something do
array = [ # +1
1,
2
]
hash = { # +3
key: 'value'
}
msg = <<~HEREDOC # +1
Heredoc
content.
HEREDOC
foo( # +1
1,
2
)
end # 6 points
Missing frozen string literal comment. Open
# A sample Guardfile
- Read upRead up
- Exclude checks
Helps you transition from mutable string literals
to frozen string literals.
It will add the # frozen_string_literal: true
magic comment to the top
of files to enable frozen string literals. Frozen string literals may be
default in future Ruby. The comment will be added below a shebang and
encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.
Note that the cop will accept files where the comment exists but is set
to false
instead of true
.
To require a blank line after this comment, please see
Layout/EmptyLineAfterMagicComment
cop.
Safety:
This cop's autocorrection is unsafe since any strings mutations will
change from being accepted to raising FrozenError
, as all strings
will become frozen by default, and will need to be manually refactored.
Example: EnforcedStyle: always (default)
# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
# ...
end
# good
# frozen_string_literal: true
module Bar
# ...
end
# good
# frozen_string_literal: false
module Bar
# ...
end
Example: EnforcedStyle: never
# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true
module Baz
# ...
end
# good
module Baz
# ...
end
Example: EnforcedStyle: always_true
# The `always_true` style enforces that the frozen string literal
# comment is set to `true`. This is a stricter option than `always`
# and forces projects to use frozen string literals.
# bad
# frozen_string_literal: false
module Baz
# ...
end
# bad
module Baz
# ...
end
# good
# frozen_string_literal: true
module Bar
# ...
end
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
guard :rspec, cmd: "bundle exec rspec -f doc" do
- 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"
Extra blank line detected. Open
guard 'migrate', rails_env: 'test', run_on_start: true do
- Read upRead up
- Exclude checks
Checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method
Unnecessary spacing detected. Open
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
- Read upRead up
- Exclude checks
Checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/rubocop/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/rubocop/rubocop"
# good only if AllowBeforeTrailingComments is true
object.method(arg) # this is a comment
# good even if AllowBeforeTrailingComments is false or not set
object.method(arg) # this is a comment
# good with either AllowBeforeTrailingComments or AllowForAlignment
object.method(arg) # this is a comment
another_object.method(arg) # this is another comment
some_object.method(arg) # this is some comment
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
watch ("Guardfile") do
- 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"
Prefer the use of rspec.spec.call("controllers/#{m[1]}_controller")
over rspec.spec.("controllers/#{m[1]}_controller")
. Open
rspec.spec.("controllers/#{m[1]}_controller"),
- Read upRead up
- Exclude checks
Checks for use of the lambda.(args) syntax.
Example: EnforcedStyle: call (default)
# bad lambda.(x, y)
# good lambda.call(x, y)
Example: EnforcedStyle: braces
# bad lambda.call(x, y)
# good lambda.(x, y)
Prefer the use of rspec.spec.call("routing/#{m[1]}_routing")
over rspec.spec.("routing/#{m[1]}_routing")
. Open
rspec.spec.("routing/#{m[1]}_routing"),
- Read upRead up
- Exclude checks
Checks for use of the lambda.(args) syntax.
Example: EnforcedStyle: call (default)
# bad lambda.(x, y)
# good lambda.call(x, y)
Example: EnforcedStyle: braces
# bad lambda.call(x, y)
# good lambda.(x, y)
Prefer the use of rspec.spec.call("features/#{m[1]}")
over rspec.spec.("features/#{m[1]}")
. Open
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
- Read upRead up
- Exclude checks
Checks for use of the lambda.(args) syntax.
Example: EnforcedStyle: call (default)
# bad lambda.(x, y)
# good lambda.call(x, y)
Example: EnforcedStyle: braces
# bad lambda.call(x, y)
# good lambda.(x, y)
%w
-literals should be delimited by [
and ]
. Open
rails = dsl.rails(view_extensions: %w(erb haml slim))
- Read upRead up
- Exclude checks
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)
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
UI.info "Exiting because Guard must be restarted for changes to take effect"
- 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"
Final newline missing. Open
end
- Read upRead up
- Exclude checks
Looks for trailing blank lines and a final newline in the source code.
Example: EnforcedStyle: final_newline (default)
# `final_newline` looks for one newline at the end of files.
# bad
class Foo; end
# EOF
# bad
class Foo; end # EOF
# good
class Foo; end
# EOF
Example: EnforcedStyle: finalblankline
# `final_blank_line` looks for one blank line followed by a new line
# at the end of files.
# bad
class Foo; end
# EOF
# bad
class Foo; end # EOF
# good
class Foo; end
# EOF
("Guardfile")
interpreted as grouped expression. Open
watch ("Guardfile") do
- Read upRead up
- Exclude checks
Checks for space between the name of a called method and a left parenthesis.
Example:
# bad
do_something (foo)
# good
do_something(foo)
do_something (2 + 3) * 4
do_something (foo * bar).baz
Annotation keywords like Note
should be all upper case, followed by a colon, and a space, then a note describing the problem. Open
# Note: The cmd option is now required due to the increasing number of ways
- Read upRead up
- Exclude checks
Checks that comment annotation keywords are written according to guidelines.
Annotation keywords can be specified by overriding the cop's Keywords
configuration. Keywords are allowed to be single words or phrases.
NOTE: With a multiline comment block (where each line is only a
comment), only the first line will be able to register an offense, even
if an annotation keyword starts another line. This is done to prevent
incorrect registering of keywords (eg. review
) inside a paragraph as an
annotation.
Example: RequireColon: true (default)
# bad
# TODO make better
# good
# TODO: make better
# bad
# TODO:make better
# good
# TODO: make better
# bad
# fixme: does not work
# good
# FIXME: does not work
# bad
# Optimize does not work
# good
# OPTIMIZE: does not work
Example: RequireColon: false
# bad
# TODO: make better
# good
# TODO make better
# bad
# fixme does not work
# good
# FIXME does not work
# bad
# Optimize does not work
# good
# OPTIMIZE does not work
Prefer the use of rspec.spec.call("acceptance/#{m[1]}")
over rspec.spec.("acceptance/#{m[1]}")
. Open
rspec.spec.("acceptance/#{m[1]}")
- Read upRead up
- Exclude checks
Checks for use of the lambda.(args) syntax.
Example: EnforcedStyle: call (default)
# bad lambda.(x, y)
# good lambda.call(x, y)
Example: EnforcedStyle: braces
# bad lambda.call(x, y)
# good lambda.(x, y)
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
require "guard/rspec/dsl"
- 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"
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
- 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"