Fix `Missing Frozen String Literal Comment` Issue

Fix `Missing Frozen String Literal Comment` Issue

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.

1

3 Answers

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
1

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

# frozen_string_literal: true

module FooBar
end

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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.