-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
allowed_pattern.rb
56 lines (46 loc) · 1.67 KB
/
allowed_pattern.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
53
54
55
56
# frozen_string_literal: true
module RuboCop
module Cop
# This module encapsulates the ability to ignore certain lines when
# parsing.
module AllowedPattern
private
def allowed_line?(line)
line = if line.respond_to?(:source_line)
line.source_line
elsif line.respond_to?(:node)
line.node.source_range.source_line
end
matches_allowed_pattern?(line)
end
# @deprecated Use allowed_line? instead
alias ignored_line? allowed_line?
def matches_allowed_pattern?(line)
allowed_patterns.any? { |pattern| Regexp.new(pattern).match?(line) }
end
# @deprecated Use matches_allowed_pattern?? instead
alias matches_ignored_pattern? matches_allowed_pattern?
def allowed_patterns
# Since there could be a pattern specified in the default config, merge the two
# arrays together.
if cop_config_deprecated_methods_values.any?(Regexp)
cop_config_patterns_values + cop_config_deprecated_methods_values
else
cop_config_patterns_values
end
end
def cop_config_patterns_values
@cop_config_patterns_values ||=
Array(cop_config.fetch('AllowedPatterns', [])) +
Array(cop_config.fetch('IgnoredPatterns', []))
end
def cop_config_deprecated_methods_values
@cop_config_deprecated_methods_values ||=
Array(cop_config.fetch('IgnoredMethods', [])) +
Array(cop_config.fetch('ExcludedMethods', []))
end
end
# @deprecated IgnoredPattern class has been replaced with AllowedPattern.
IgnoredPattern = AllowedPattern
end
end