gpt4 book ai didi

ruby-on-rails - Rubocop/Hound 建议卡住字符串文字类名

转载 作者:行者123 更新时间:2023-12-04 03:35:01 25 4
gpt4 key购买 nike

我的项目使用 HoundCI 作为代码 linter,我相信它在内部使用了 rubocop。

最近我开始注意到这种警告 -

enter image description here

它出现在每个类定义中(例如 class User < ActiveRecord::Base )。

我理解卡住字符串文字的概念,但为什么它期望我卡住类定义?同样更重要的是,我该如何禁用它?有 10 多个这样的“错误”污染了我们的拉取请求,这非常烦人。

谢谢!

编辑: 看起来它也开始出现在 require 上使用字符串文字的语句,例如 rspec 测试。这绝对是新的,之前没有被标记过

enter image description here

最佳答案

看起来 Hound/Rubocop 正在检测到违反 FrozenStringLiteralComment 的行为警察。

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals will be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

您可以手动将魔术注释添加到文件顶部

# frozen_string_literal: true

或者让 Rubocop 为您做

$ bundle exec rubocop --auto-correct --only FrozenStringLiteralComment

您也可以忽略 rubocop.yml 中的 cop,Style/FrozenStringLiteralComment

关于ruby-on-rails - Rubocop/Hound 建议卡住字符串文字类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39538276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com