Missing magic comment # frozen_string_literal: true
. Open
require "csv"
- Read upRead up
- Exclude checks
This cop is designed to help upgrade to after Ruby 3.0. It will add the
comment # frozen_string_literal: true
to the top of files to
enable frozen string literals. Frozen string literals may be default
after Ruby 3.0. The comment will be added below a shebang and encoding
comment. The frozen string literal comment is only valid in Ruby 2.3+.
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
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
Avoid chaining a method call on a do...end block. Open
end.to_h
- Read upRead up
- Exclude checks
This cop checks for methods called on a do...end block. The point of this check is that it's easy to miss the call tacked on to the block when reading code.
Example:
a do
b
end.c
Replace class var @@headers with a class instance var. Open
@@headers ||= {}
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.
You have to be careful when setting a value for a class variable; if a class has been inherited, changing the value of a class variable also affects the inheriting classes. This means that it's almost always better to use a class instance variable instead.
Example:
# bad
class A
@@test = 10
end
# good
class A
@test = 10
end
class A
def test
@@test # you can access class variable without offense
end
end