Refactor building default globs

This commit is contained in:
Stuart Frost 2023-08-05 16:15:50 +01:00
parent 7690074cab
commit eb60b25c4e
2 changed files with 4 additions and 8 deletions

View File

@ -20,7 +20,7 @@ module Ameba
File.touch "lib/shard.cr"
yml = YAML.parse "{}"
config = Config.new(yml)
config.globs.should eq Config::DEFAULT_GLOBS
config.globs.should eq ["**/*.cr", "!lib"]
File.delete "lib/shard.cr"
end
end

View File

@ -55,10 +55,7 @@ class Ameba::Config
Path[XDG_CONFIG_HOME] / "ameba/config.yml",
}
DEFAULT_GLOBS = %w(
**/*.cr
!lib
)
SOURCES_GLOB = "**/*.cr"
getter rules : Array(Rule::Base)
property severity = Severity::Convention
@ -240,9 +237,8 @@ class Ameba::Config
end
private def default_globs
DEFAULT_GLOBS.select do |glob|
!Dir[glob].empty? ||
(glob.starts_with?("!") && !Dir["#{glob[1..-1]}/**/*.cr"].empty?)
[SOURCES_GLOB].tap do |globs|
globs.push("!lib") if !Dir["lib/**/*.cr"].empty?
end
end