39

I'm newbie in Rails. I am using 'Rubocop' for checking standards, however I'm bothered with the way it checks the 'frozen string literal'. It keeps on saying on my files:

Missing frozen string literal comment.

Is there a way to disable the checking of this on rubocop? Or is it a bad idea to disable it?

I tried this on rubocop.yml but didn't work

frozen_string_literal: false
mpalencia
  • 5,481
  • 4
  • 45
  • 59

4 Answers4

74

This one worked for me

Style/FrozenStringLiteralComment:
  Enabled: false
mpalencia
  • 5,481
  • 4
  • 45
  • 59
39

You might want to add the following to your .rubocop.yml:

Style/FrozenStringLiteralComment:
  Enabled: false

Is it a bad idea to disable this cop? It depends. You probably want to revisit this before migrating to Ruby 3.0. But because Ruby 3.0 will not be released soon, there might be more important things to do in the meanwhile.

spickermann
  • 100,941
  • 9
  • 101
  • 131
  • 5
    It seems like Ruby 3.0 won't include frozen string literals by default, so it should be safe to disable it: https://bugs.ruby-lang.org/issues/11473#note-53 – gonzaloriestra Jul 11 '19 at 07:42
5

Adding rubocop.yml file not worked for me. It should be .rubocop.yml.

Create a .rubocop.yml file in the root directory of the Rails app and add the following code to disable frozen_string_literal check.

.rubocop.yml

Style/FrozenStringLiteralComment:
  Enabled: false
Gokul
  • 3,101
  • 4
  • 27
  • 45
1

Further to this, If you don't want any magic frozen_string_literal comments, you can use this:

Style/FrozenStringLiteralComment:
  EnforcedStyle: never
sgbett
  • 348
  • 3
  • 15