19

I created a new migration, it looks like this one:

class AddCommentsToUsers < ActiveRecord::Migration
  def change
    add_column :users, :comments, :text
  end
end

Now with Code Climate I am warned of an issue: Missing frozen string literal comment.

I tried to fix it like this:

# frozen_string_literal: true
class AddCommentsToUsers < ActiveRecord::Migration
  def change
    add_column :users, :comments, :text
  end
end

But I still have the same issue. How can I solve it? Thanks.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
John Smith
  • 6,105
  • 16
  • 58
  • 109

3 Answers3

10

I experienced the same problem. Rubocop was working fine before but suddenly it started acting up. I read through their configuration options on github and saw the particular property that is messing with your code. The property can be found here: FrozenStringLiteral.

To silence this warning, you only need to add this to your rubocop.yml file

Style/FrozenStringLiteralComment:
  Enabled: false
Koen.
  • 25,449
  • 7
  • 83
  • 78
Van_Paitin
  • 3,678
  • 2
  • 22
  • 26
  • 2
    This change just silences the warning. The linked page describes the right solution: `Add the frozen_string_literal comment to the top of files to help transition to frozen string literals by default.`. – WhyNotHugo Jul 23 '21 at 09:51
4

Adding an empty line below the string literal line fixed it for me.

# frozen_string_literal: true

module FooBar
end
debao84
  • 103
  • 1
  • 1
  • 8
0

Make sure you added your changes to the staging area before trying to run Rubocop again. I had the same problem and that solved it for me.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 02 '22 at 17:17
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31653064) – Renews May 05 '22 at 07:22