我想通过以下一行将记录中的一列更改为is_deleted: true:
UserTag.where(cms_tag_id: webhook.dig('entity', 'id')).update_all(is_deleted: true)但我知道鲁波克的错误:
Rails/skipsmodelvalidations: avoid using update_all because it skips validations.
我知道我可以使用每个块并在一个块中通过e.update更新所有列,但是update_all要快得多,一行,很好的解决方案。
如何禁用这样的rubocop错误仅针对这,具体的行?
发布于 2020-08-13 16:14:28
您可以运行以下命令,该命令将生成一个.rubocop_todo.yml文件,该文件将记录并忽略违规文件的特定违规行为:
rubocop --auto-gen-config --exclude-limit 999 --no-offense-counts--auto-gen-config生成yml文件,这是实现所需的唯一非可选标志。
在rubocop禁用整个应用程序的检查之前,--exclude-limit xxx是一种犯罪行为。
--no-offense-counts没有在yml文件中记录有多少违法行为。
确保你已经考虑过忽略指针的后果;不遵循linter建议通常是不明智的。请注意,这将禁用对规范测试中所有违规行为的检查。
更新
如果您想在不生成文件的情况下禁用rubocop检查,可以使用如下注释:
Company.where(cms_tag_id: webhook.dig('entity', 'id')).update_all(is_deleted: true) # rubocop:disable Rails/SkipsModelValidations发布于 2020-08-13 18:57:46
以下是@benjessop的回答:
若要选择性地对代码块禁用RuboCop,请使用# rubocop:disable . # rubocop:enable块,如下所示:
# rubocop:disable Rails::SkipsModelValidations
# The specified cop is not enforced here.
# Therefore, make this block of code minimal.
# For example, just this one line:
UserTag.where(cms_tag_id: webhook.dig('entity', 'id')).update_all(is_deleted: true)
# rubocop:enable Rails::SkipsModelValidations还请参见:
关于RuboCop配置的更多一般信息
https://stackoverflow.com/questions/63399047
复制相似问题