Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Open
require 'caxlsx'
- 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"
Missing top-level documentation comment for class NtqExcelsior::MultiWorkbookExporter
. Open
class MultiWorkbookExporter
- Read upRead up
- Exclude checks
Checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, constant definitions or constant visibility declarations.
The documentation requirement is annulled if the class or module has
a #:nodoc:
comment next to it. Likewise, #:nodoc: all
does the
same for all its children.
Example:
# bad
class Person
# ...
end
module Math
end
# good
# Description/Explanation of Person class
class Person
# ...
end
# allowed
# Class without body
class Person
end
# Namespace - A namespace can be a class or a module
# Containing a class
module Namespace
# Description/Explanation of Person class
class Person
# ...
end
end
# Containing constant visibility declaration
module Namespace
class Private
end
private_constant :Private
end
# Containing constant definition
module Namespace
Public = Class.new
end
# Macro calls
module Namespace
extend Foo
end
Example: AllowedConstants: ['ClassMethods']
# good
module A
module ClassMethods
# ...
end
end
Trailing whitespace detected. Open
- Read upRead up
- Exclude checks
Looks for trailing whitespace in the source code.
Example:
# The line in this example contains spaces after the 0.
# bad
x = 0
# The line in this example ends directly after the 0.
# good
x = 0
Example: AllowInHeredoc: false (default)
# The line in this example contains spaces after the 0.
# bad
code = <<~RUBY
x = 0
RUBY
# ok
code = <<~RUBY
x = 0 #{}
RUBY
# good
trailing_whitespace = ' '
code = <<~RUBY
x = 0#{trailing_whitespace}
RUBY
Example: AllowInHeredoc: true
# The line in this example contains spaces after the 0.
# good
code = <<~RUBY
x = 0
RUBY
Extra empty line detected at class body beginning. Open
attr_accessor :exporters
- Read upRead up
- Exclude checks
Checks if empty lines around the bodies of classes match the configuration.
Example: EnforcedStyle: noemptylines (default)
# good
class Foo
def bar
# ...
end
end
Example: EnforcedStyle: empty_lines
# good
class Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
class Foo
class Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
class Foo
def bar; end
end
Example: EnforcedStyle: beginning_only
# good
class Foo
def bar
# ...
end
end
Example: EnforcedStyle: ending_only
# good
class Foo
def bar
# ...
end
end
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
Extra empty line detected at class body end. Open
end
- Read upRead up
- Exclude checks
Checks if empty lines around the bodies of classes match the configuration.
Example: EnforcedStyle: noemptylines (default)
# good
class Foo
def bar
# ...
end
end
Example: EnforcedStyle: empty_lines
# good
class Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
class Foo
class Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
class Foo
def bar; end
end
Example: EnforcedStyle: beginning_only
# good
class Foo
def bar
# ...
end
end
Example: EnforcedStyle: ending_only
# good
class Foo
def bar
# ...
end
end
Missing frozen string literal comment. Open
require 'caxlsx'
- 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