Module: RuboCop::Cop::AllowedPattern
Overview
This module encapsulates the ability to ignore certain lines when parsing.
Instance Attribute Summary
-
#ignored_line? ⇒ Boolean
readonly
private
deprecated
Deprecated.
Use allowed_line? instead
-
#matches_ignored_pattern? ⇒ Boolean
readonly
private
deprecated
Deprecated.
Use matches_allowed_pattern? instead
Instance Method Summary
- #allowed_line?(line) ⇒ Boolean private
- #allowed_patterns private
- #cop_config_deprecated_methods_values private
- #cop_config_patterns_values private
- #matches_allowed_pattern?(line) ⇒ Boolean private
Instance Attribute Details
#ignored_line? ⇒ Boolean
(readonly, private)
Deprecated.
Use allowed_line? instead
# File 'lib/rubocop/cop/mixin/allowed_pattern.rb', line 21
def ignored_line? warn Rainbow(<<~WARNING).yellow, uplevel: 1 `ignored_line?` is deprecated. Use `allowed_line?` instead. WARNING allowed_line? end
#matches_ignored_pattern? ⇒ Boolean
(readonly, private)
Deprecated.
Use matches_allowed_pattern? instead
# File 'lib/rubocop/cop/mixin/allowed_pattern.rb', line 34
def matches_ignored_pattern? warn Rainbow(<<~WARNING).yellow, uplevel: 1 `matches_ignored_pattern?` is deprecated. Use `matches_allowed_pattern?` instead. WARNING matches_allowed_pattern? end
Instance Method Details
#allowed_line?(line) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/mixin/allowed_pattern.rb', line 10
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
#allowed_patterns (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/allowed_pattern.rb', line 42
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
#cop_config_deprecated_methods_values (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/allowed_pattern.rb', line 58
def cop_config_deprecated_methods_values @cop_config_deprecated_methods_values ||= Array(cop_config.fetch('IgnoredMethods', [])) + Array(cop_config.fetch('ExcludedMethods', [])) end
#cop_config_patterns_values (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/allowed_pattern.rb', line 52
def cop_config_patterns_values @cop_config_patterns_values ||= Array(cop_config.fetch('AllowedPatterns', [])) + Array(cop_config.fetch('IgnoredPatterns', [])) end
#matches_allowed_pattern?(line) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/mixin/allowed_pattern.rb', line 29
def matches_allowed_pattern?(line) allowed_patterns.any? { |pattern| Regexp.new(pattern).match?(line) } end