class RuboCop::FilePatterns
@api private
the costly patterns check, if needed.
of the patterns. This way we can firstly do a cheap check in the set and then proceed via
This class partitions an array of patterns into a set of exact match strings and the rest
to check if the file is relevant to the cop.
are exact file names. It is wasteful to linearly check the list of patterns over and over
For projects with a large set of rubocop todo files, most items in ‘Exclude`/`Include`
A wrapper around patterns array to perform optimized search.
def self.from(patterns)
def self.from(patterns) @cache[patterns] ||= new(patterns) end
def initialize(patterns)
def initialize(patterns) @strings = Set.new @patterns = [] partition_patterns(patterns) end
def match?(path)
def match?(path) @strings.include?(path) || @patterns.any? { |pattern| PathUtil.match_path?(pattern, path) } end
def partition_patterns(patterns)
def partition_patterns(patterns) patterns.each do |pattern| if pattern.is_a?(String) && !pattern.match?(/[*{\[?]/) @strings << pattern else @patterns << pattern end end end