Module: RuboCop::Cop::IgnoredPattern

Included in:
Layout::IndentationWidth, Metrics::LineLength
Defined in:
lib/rubocop/cop/mixin/ignored_pattern.rb

Overview

This module encapsulates the ability to ignore certain lines when parsing.

Instance Method Summary collapse

Instance Method Details

#ignored_line?(line) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
# File 'lib/rubocop/cop/mixin/ignored_pattern.rb', line 8

def ignored_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_ignored_pattern?(line)
end

#ignored_patternsObject



22
23
24
# File 'lib/rubocop/cop/mixin/ignored_pattern.rb', line 22

def ignored_patterns
  cop_config['IgnoredPatterns'] || []
end

#matches_ignored_pattern?(line) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rubocop/cop/mixin/ignored_pattern.rb', line 18

def matches_ignored_pattern?(line)
  ignored_patterns.any? { |pattern| Regexp.new(pattern).match(line) }
end