mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Exclude globs as arguments
Examples: $ ameba path/to/shard/*.cr !path/to/shard/lib $ ameba . !lib
This commit is contained in:
parent
5aa7ee4854
commit
3c5e3cdef4
9 changed files with 125 additions and 32 deletions
|
@ -114,9 +114,9 @@ module Ameba::Cli
|
|||
end
|
||||
end
|
||||
|
||||
it "accepts unknown args as files" do
|
||||
it "accepts unknown args as globs" do
|
||||
c = Cli.parse_args %w(source1.cr source2.cr)
|
||||
c.files.should eq %w(source1.cr source2.cr)
|
||||
c.globs.should eq %w(source1.cr source2.cr)
|
||||
end
|
||||
|
||||
it "accepts one unknown arg as explain location if it has correct format" do
|
||||
|
@ -132,7 +132,7 @@ module Ameba::Cli
|
|||
it "allows args to be blank" do
|
||||
c = Cli.parse_args [] of String
|
||||
c.formatter.should be_nil
|
||||
c.files.should be_nil
|
||||
c.globs.should be_nil
|
||||
c.only.should be_nil
|
||||
c.except.should be_nil
|
||||
c.config.should eq Config::PATH
|
||||
|
|
|
@ -12,28 +12,37 @@ module Ameba
|
|||
it "loads custom config" do
|
||||
config = Config.load config_sample
|
||||
config.should_not be_nil
|
||||
config.files.should_not be_nil
|
||||
config.globs.should_not be_nil
|
||||
config.formatter.should_not be_nil
|
||||
end
|
||||
|
||||
it "loads default config" do
|
||||
config = Config.load
|
||||
config.should_not be_nil
|
||||
config.files.should_not be_nil
|
||||
config.globs.should_not be_nil
|
||||
config.formatter.should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "#files, #files=" do
|
||||
describe "#globs, #globs=" do
|
||||
config = Config.load config_sample
|
||||
|
||||
it "holds source files" do
|
||||
config.files.should contain "spec/ameba/config_spec.cr"
|
||||
it "holds source globs" do
|
||||
config.globs.should contain "spec/ameba/config_spec.cr"
|
||||
end
|
||||
|
||||
it "allows to set files" do
|
||||
config.files = ["file.cr"]
|
||||
config.files.should eq ["file.cr"]
|
||||
it "allows to set globs" do
|
||||
config.globs = ["file.cr"]
|
||||
config.globs.should eq ["file.cr"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#sources" do
|
||||
config = Config.load config_sample
|
||||
|
||||
it "returns list of sources" do
|
||||
config.sources.size.should be > 0
|
||||
config.sources.first.should be_a Source
|
||||
end
|
||||
end
|
||||
|
||||
|
|
38
spec/ameba/glob_utils_spec.cr
Normal file
38
spec/ameba/glob_utils_spec.cr
Normal file
|
@ -0,0 +1,38 @@
|
|||
require "../spec_helper"
|
||||
|
||||
module Ameba
|
||||
struct GlobUtilsClass
|
||||
include GlobUtils
|
||||
end
|
||||
|
||||
subject = GlobUtilsClass.new
|
||||
current_file_basename = File.basename(__FILE__)
|
||||
current_file_path = "spec/ameba/#{current_file_basename}"
|
||||
|
||||
describe GlobUtils do
|
||||
describe "#find_files_by_globs" do
|
||||
it "returns a file by globs" do
|
||||
subject.find_files_by_globs(["**/#{current_file_basename}"])
|
||||
.should eq [current_file_path]
|
||||
end
|
||||
|
||||
it "returns files by globs" do
|
||||
subject.find_files_by_globs(["**/*_spec.cr"])
|
||||
.should contain current_file_path
|
||||
end
|
||||
|
||||
it "doesn't return rejected globs" do
|
||||
subject
|
||||
.find_files_by_globs(["**/*_spec.cr", "!**/#{current_file_basename}"])
|
||||
.should_not contain current_file_path
|
||||
end
|
||||
end
|
||||
|
||||
describe "#expand" do
|
||||
it "expands globs" do
|
||||
subject.expand(["**/#{current_file_basename}"])
|
||||
.should eq [current_file_path]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ module Ameba
|
|||
private def runner(files = [__FILE__], formatter = DummyFormatter.new)
|
||||
config = Config.load
|
||||
config.formatter = formatter
|
||||
config.files = files
|
||||
config.globs = files
|
||||
|
||||
config.update_rule ErrorRule.rule_name, enabled: false
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue