ruby-on-rails - 针对 FrozenStringLiteralComment 的 Rubocop 自动更正不起作用

标签 ruby-on-rails ruby rubocop

我有一个 Rails 6 项目,正在尝试使用 RuboCop 的 auto-correct选项来修复许多 Style/FrozenStringLiteralComment错误(主要在生成的文件中)。
不管跑多少次bundle exec rubocop --auto-correct --only Style/FrozenStringLiteralComment从项目根目录,Rubocop 只会报告错误,但不会自动更正它们:app/models/product.rb:1:1: C: Style/FrozenStringLiteralComment: Missing frozen string literal comment.从运行 --show-cops选项我可以看到这个警察“支持--自动更正”,所以我不确定出了什么问题。
我的 .rubocop.yml文件只有一个配置设置:require: rubocop-rails .
我也跑了 bundle exec rubocop -a并且它更正了配置和类似文件中的其他错误(主要是单引号)。
知道为什么在这种情况下自动更正不起作用吗?谢谢。

最佳答案

这是 0.87 版本中引入的重大更改(请参阅 issue )。
从那里引用:

rubocop -a does all autocorrections, including unsafe ones. One has to add --safe-auto-correct to exclude unsafe ones.


您应该使用 -A立即标记以安全和/或不安全地自动更正您的文件:

rubocop -a / --autocorrect no longer run unsafe corrections; rubocop -A / --autocorrect-all run both safe and unsafe corrections. Options --safe-autocorrect is deprecated


它应该适合你:
bundle exec rubocop -A --only Style/FrozenStringLiteralComment

关于ruby-on-rails - 针对 FrozenStringLiteralComment 的 Rubocop 自动更正不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62984228/

相关文章:

Rubocop 不忽略 db/schema.rb 文件

ruby-on-rails - Ruby on Rails : Notification System For Different Sets of Tags

ruby-on-rails - 捆绑安装错误 : Source does not contain any versions of

ruby-on-rails - 设置一个 :has_many :through association on a belongs_to association Ruby on Rails

ruby - 如何在不引发 RuboCop 警告的情况下使用正则表达式

ruby-on-rails - Rubocop RSpec/MultipleMemoizedHelpers 问题关于专家规范测试

ruby-on-rails - 如何覆盖 Spree 结帐表单和步骤流程?

ruby-on-rails - Gemfile.lock 未 checkin - Heroku

ruby-on-rails - 带命令行参数的 Rake 任务环境变量

ruby - 使用数组中的键访问散列