gpt4 book ai didi

ruby-on-rails - 如何要求 Rubocop 检查特定方法/关键字的使用情况?

转载 作者:行者123 更新时间:2023-12-05 04:10:38 31 4
gpt4 key购买 nike

我不鼓励在我们的代码库中使用unscoped。 rubocop 中是否存在允许我指定关键字的现有 linter?如果没有,我是否必须编写自定义 cop 才能完成它?

最佳答案

我的同伴帮助了我。看来我们需要编写一个自定义 cop。

module RuboCop
module Cop
module Hired
class Unscoped < Cop
MSG = "Avoid using `unscoped`."

def_node_matcher :unscoped?, <<-END
(send _ :unscoped)
END

def on_send(node)
return unless unscoped?(node)
add_offense(node, :expression, MSG % node.source)
end
end
end
end
end

将它放到一个文件夹中,比如 lib/cops/ 然后将其添加到 .rubocop.yml:

require:
- ./lib/cops/<whatever_you_called_the_file>.rb

参见 http://www.rubydoc.info/github/bbatsov/RuboCop/RuboCop/NodePattern

关于ruby-on-rails - 如何要求 Rubocop 检查特定方法/关键字的使用情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44141627/

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