diff options
Diffstat (limited to 'rubocop/ext/path_util.rb')
-rw-r--r-- | rubocop/ext/path_util.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/rubocop/ext/path_util.rb b/rubocop/ext/path_util.rb new file mode 100644 index 00000000000..3b54f046c7b --- /dev/null +++ b/rubocop/ext/path_util.rb @@ -0,0 +1,26 @@ +# 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 |