-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ignored_methods.rb
52 lines (43 loc) · 1.25 KB
/
ignored_methods.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
module RuboCop
module Cop
# This module encapsulates the ability to ignore certain methods when
# parsing.
# Cops that use `IgnoredMethods` can accept either strings or regexes to match
# against.
module IgnoredMethods
# Configuration for IgnoredMethods. It is added to classes that include
# the module so that configuration can be set using the `ignored_methods`
# class macro.
module Config
attr_accessor :deprecated_key
def ignored_methods(**config)
self.deprecated_key = config[:deprecated_key]
end
end
def self.included(base)
base.extend(Config)
end
def ignored_method?(name)
ignored_methods.any? do |value|
case value
when Regexp
value.match? String(name)
else
value == String(name)
end
end
end
def ignored_methods
keys = %w[IgnoredMethods]
keys << deprecated_key if deprecated_key
cop_config.slice(*keys).values.reduce(&:concat)
end
private
def deprecated_key
return unless self.class.respond_to?(:deprecated_key)
self.class.deprecated_key&.to_s
end
end
end
end