My project uses HoundCI as a code linter, which I believe internally uses rubocop.
Recently I started noticing this sort of warning -
It appears on every class definition (e.g. class User < ActiveRecord::Base
).
I understand the concept of freezing string literals, but why would it expect me to freeze class definitions? Also more importantly, how do I disable it? It's quite annoying to have 10+ of these "errors" polluting our pull requests.
Thank you!
Edit: Looks like it also started appearing on require
statements that use string literals, like with rspec tests. This is definitely new and wasn't being flagged previously
It looks like Hound/Rubocop is detecting a violation of the FrozenStringLiteralComment cop.
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 will 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+.
You can either add the magic comment manually to the top of your files
# frozen_string_literal: true
Or have Rubocop do it for you
$ bundle exec rubocop --auto-correct --only FrozenStringLiteralComment
You can also ignore the cop in your rubocop.yml
, Style/FrozenStringLiteralComment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With