debian-mirror-gitlab/rubocop/ext/path_util.rb
2022-11-25 23:54:43 +05:30

26 lines
646 B
Ruby

# frozen_string_literal: true
module RuboCop
module PathUtil
def match_path?(pattern, path)
case pattern
when String
matched = if /[*{}]/.match?(pattern)
File.fnmatch?(pattern, path, File::FNM_PATHNAME | File::FNM_EXTGLOB)
else
pattern == path
end
matched || hidden_file_in_not_hidden_dir?(pattern, path)
when Regexp
begin
pattern.match?(path)
rescue ArgumentError => e
return false if e.message.start_with?('invalid byte sequence')
raise e
end
end
end
end
end