mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Conditionally add !lib to default globs
This commit is contained in:
parent
b2069ea4ff
commit
7690074cab
3 changed files with 24 additions and 8 deletions
|
@ -9,10 +9,20 @@ module Ameba
|
|||
end
|
||||
|
||||
describe ".new" do
|
||||
it "loads default globs when config is empty" do
|
||||
yml = YAML.parse "{}"
|
||||
config = Config.new(yml)
|
||||
config.globs.should eq Config::DEFAULT_GLOBS
|
||||
context "when config is empty" do
|
||||
it "loads default globs" do
|
||||
yml = YAML.parse "{}"
|
||||
config = Config.new(yml)
|
||||
config.globs.should eq ["**/*.cr"]
|
||||
end
|
||||
|
||||
it "only sets !lib as a default glob when there are .cr files in lib" do
|
||||
File.touch "lib/shard.cr"
|
||||
yml = YAML.parse "{}"
|
||||
config = Config.new(yml)
|
||||
config.globs.should eq Config::DEFAULT_GLOBS
|
||||
File.delete "lib/shard.cr"
|
||||
end
|
||||
end
|
||||
|
||||
it "initializes globs as string" do
|
||||
|
@ -102,7 +112,7 @@ module Ameba
|
|||
config = Config.load config_sample
|
||||
|
||||
it "holds source globs" do
|
||||
config.globs.should eq Config::DEFAULT_GLOBS
|
||||
config.globs.should eq ["**/*.cr"]
|
||||
end
|
||||
|
||||
it "allows to set globs" do
|
||||
|
|
|
@ -95,7 +95,7 @@ class Ameba::Config
|
|||
@rules = Rule.rules.map &.new(config).as(Rule::Base)
|
||||
@rule_groups = @rules.group_by &.group
|
||||
@excluded = load_array_section(config, "Excluded")
|
||||
@globs = load_array_section(config, "Globs", DEFAULT_GLOBS)
|
||||
@globs = load_array_section(config, "Globs", default_globs)
|
||||
|
||||
return unless formatter_name = load_formatter_name(config)
|
||||
self.formatter = formatter_name
|
||||
|
@ -239,6 +239,13 @@ class Ameba::Config
|
|||
end
|
||||
end
|
||||
|
||||
private def default_globs
|
||||
DEFAULT_GLOBS.select do |glob|
|
||||
!Dir[glob].empty? ||
|
||||
(glob.starts_with?("!") && !Dir["#{glob[1..-1]}/**/*.cr"].empty?)
|
||||
end
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
module RuleConfig
|
||||
# Define rule properties
|
||||
|
|
|
@ -21,9 +21,8 @@ module Ameba
|
|||
# ```
|
||||
def expand(globs)
|
||||
globs.flat_map do |glob|
|
||||
raise ArgumentError.new("No files found matching #{glob}") if Dir[glob].empty?
|
||||
|
||||
glob += "/**/*.cr" if File.directory?(glob)
|
||||
raise ArgumentError.new("No files found matching #{glob}") if Dir[glob].empty?
|
||||
Dir[glob]
|
||||
end.uniq!
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue