【问题标题】:fix `Missing frozen string literal comment` issue修复“缺少冻结字符串文字注释”问题
【发布时间】:2016-09-04 12:15:05
【问题描述】:

我创建了一个新的迁移,它看起来像这样:

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

现在有了 Code Climate,我被警告一个问题: Missing frozen string literal comment.

我试着这样修复它:

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

但我仍然有同样的问题。我该如何解决? 谢谢。

【问题讨论】:

  • 对我来说是正确的。您是否使用 Code Climate CLI 或 rubocop 在本地进行过调查?

标签: ruby-on-rails ruby rubocop code-climate ruby-2.3


【解决方案1】:

我遇到了同样的问题。 Rubocop 之前工作正常,但突然开始出现问题。我在 github 上阅读了他们的配置选项,并看到了与您的代码混淆的特定属性。 该属性可以在这里找到:FrozenStringLiteral

要消除此警告,您只需将其添加到您的 rubocop.yml 文件中

Style/FrozenStringLiteralComment:
  Enabled: false

【讨论】:

  • 此更改只是使警告静音。链接页面描述了正确的解决方案:Add the frozen_string_literal comment to the top of files to help transition to frozen string literals by default.
猜你喜欢
  • 2016-11-14
  • 2021-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多