[英]Rubocop/Hound recommend freezing string literal class names
My project uses HoundCI as a code linter, which I believe internally uses rubocop. 我的项目使用HoundCI作为代码linter,我相信内部使用rubocop。
Recently I started noticing this sort of warning - 最近我开始注意到这种警告 -
It appears on every class definition (eg class User < ActiveRecord::Base
). 它出现在每个类定义中(例如,
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.
让10个以上的“错误”污染我们的拉动请求是非常烦人的。
Thank you! 谢谢!
Edit: Looks like it also started appearing on require
statements that use string literals, like with rspec tests. 编辑:看起来它也开始出现在使用字符串文字的
require
语句上,就像使用rspec测试一样。 This is definitely new and wasn't being flagged previously 这绝对是新的,之前没有被标记过
It looks like Hound/Rubocop is detecting a violation of the FrozenStringLiteralComment cop. 看起来Hound / Rubocop正在检测违反了FrozenStringLiteralComment警察。
This cop is designed to help upgrade to Ruby 3.0.
此警察旨在帮助升级到Ruby 3.0。 It will add the comment
# frozen_string_literal: true
to the top of files to enable frozen string literals.它会将注释
# frozen_string_literal: true
添加到文件的顶部以启用冻结的字符串文字。 Frozen string literals will be default in Ruby 3.0.在Ruby 3.0中,冻结的字符串文字将是默认的。 The comment will be added below a shebang and encoding comment.
评论将添加到shebang和编码评论下面。 The frozen string literal comment is only valid in Ruby 2.3+.
冻结的字符串文字注释仅在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 或者让Rubocop为你做
$ bundle exec rubocop --auto-correct --only FrozenStringLiteralComment
You can also ignore the cop in your rubocop.yml
, Style/FrozenStringLiteralComment
你也可以忽略你的
rubocop.yml
, Style/FrozenStringLiteralComment
的警察
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.