From 5403aee89945a803c79a672c23dc92c253c49ca3 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 17 Apr 2024 12:07:44 +0200 Subject: [PATCH 1/3] Make sure we only return files from `GlobUtils#expand` method --- src/ameba/glob_utils.cr | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ameba/glob_utils.cr b/src/ameba/glob_utils.cr index 71cd0cb5..2ff2a119 100644 --- a/src/ameba/glob_utils.cr +++ b/src/ameba/glob_utils.cr @@ -20,10 +20,13 @@ module Ameba # expand(["spec/*.cr", "src"]) # => all files in src folder + first level specs # ``` def expand(globs) - globs.flat_map do |glob| - glob += "/**/*.cr" if File.directory?(glob) - Dir[glob] - end.uniq! + globs + .flat_map do |glob| + glob += "/**/*.cr" if File.directory?(glob) + Dir[glob] + end + .uniq! + .select! { |path| File.file?(path) } end private def rejected_globs(globs) From 1bd59c1bf05a37d28c4c1e8c23c0626a59c25ece Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 17 Apr 2024 23:42:05 +0200 Subject: [PATCH 2/3] Make `GlobUtils` extend `self` for easier access --- spec/ameba/glob_utils_spec.cr | 6 +----- src/ameba/glob_utils.cr | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/spec/ameba/glob_utils_spec.cr b/spec/ameba/glob_utils_spec.cr index 41309195..5c6f289e 100644 --- a/spec/ameba/glob_utils_spec.cr +++ b/spec/ameba/glob_utils_spec.cr @@ -1,11 +1,7 @@ require "../spec_helper" module Ameba - struct GlobUtilsClass - include GlobUtils - end - - subject = GlobUtilsClass.new + subject = GlobUtils current_file_basename = File.basename(__FILE__) current_file_path = "spec/ameba/#{current_file_basename}" diff --git a/src/ameba/glob_utils.cr b/src/ameba/glob_utils.cr index 2ff2a119..63dd67cc 100644 --- a/src/ameba/glob_utils.cr +++ b/src/ameba/glob_utils.cr @@ -1,6 +1,8 @@ module Ameba # Helper module that is utilizes helpers for working with globs. module GlobUtils + extend self + # Returns all files that match specified globs. # Globs can have wildcards or be rejected: # From f12e7f6c5d4c3783fd72b92927906c0b87a49cc9 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 17 Apr 2024 23:43:03 +0200 Subject: [PATCH 3/3] Add spec --- spec/ameba/glob_utils_spec.cr | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/ameba/glob_utils_spec.cr b/spec/ameba/glob_utils_spec.cr index 5c6f289e..153b7909 100644 --- a/spec/ameba/glob_utils_spec.cr +++ b/spec/ameba/glob_utils_spec.cr @@ -41,6 +41,12 @@ module Ameba subject.expand(["**/#{current_file_basename}", "**/#{current_file_basename}"]) .should eq [current_file_path] end + + it "does not list folders" do + subject.expand(["**/*"]).each do |path| + fail "#{path.inspect} should be a file" unless File.file?(path) + end + end end end end