This cop is designed to help upgrade to 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
in 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+.
# The `when_needed` style will add the frozen string literal comment# to files only when the `TargetRubyVersion` is set to 2.3+.# badmodule Foo # ...end # good# frozen_string_literal: true module Foo # ...end
# 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.# badmodule Bar # ...end # good# frozen_string_literal: true module Bar # ...end
# The `never` will enforce that the frozen string literal comment does# not exist in a file.# bad# frozen_string_literal: true module Baz # ...end # goodmodule Baz # ...end
This cop checks hash literal syntax.
It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).
A separate offense is registered for each problematic pair.
The supported styles are:
{a: 1}
) when hashes have
all symbols for keys# bad{:a => 2}{b: 1, :c => 2} # good{a: 2, b: 1}{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol{d: 1, 'e' => 2} # technically not forbidden
# bad{a: 1, b: 2}{c: 1, 'd' => 5} # good{:a => 1, :b => 2}
# bad{:a => 1, b: 2}{c: 1, 'd' => 2} # good{:a => 1, :b => 2}{c: 1, d: 2}
# bad{:a => 1, :b => 2}{c: 2, 'd' => 3} # should just use hash rockets # good{a: 1, b: 2}{:c => 3, 'd' => 4}