diff --git a/.rubocop.yml b/.rubocop.yml index 7d5623304..3c9ae87c8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ require: - rubocop/rspec/focused + - ./lib/cops/unscoped.rb AllCops: Exclude: diff --git a/lib/cops/unscoped.rb b/lib/cops/unscoped.rb new file mode 100644 index 000000000..8374c2116 --- /dev/null +++ b/lib/cops/unscoped.rb @@ -0,0 +1,18 @@ +module RuboCop + module Cop + module DS + class Unscoped < Cop + MSG = "Avoid using `unscoped`. Instead unscope specific clauses by using `unscope(where: :attribute)`." + + def_node_matcher :unscoped?, <<-END + (send _ :unscoped) + END + + def on_send(node) + return unless unscoped?(node) + add_offense(node) + end + end + end + end +end