mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Merge pull request #363 from zw963/master
Skip all config when use with --gen-config.
This commit is contained in:
commit
adac90c7c6
5 changed files with 37 additions and 20 deletions
|
@ -7,7 +7,7 @@ module Ameba::AST
|
|||
node = as_node("return 22")
|
||||
flow_expression = FlowExpression.new node, false
|
||||
flow_expression.node.should_not be_nil
|
||||
flow_expression.in_loop?.should eq false
|
||||
flow_expression.in_loop?.should be_false
|
||||
end
|
||||
|
||||
describe "#delegation" do
|
||||
|
|
|
@ -93,7 +93,7 @@ module Ameba::AST
|
|||
|
||||
it "returns false if this is a break out of loop" do
|
||||
node = as_node("break")
|
||||
subject.flow_command?(node, false).should eq false
|
||||
subject.flow_command?(node, false).should be_false
|
||||
end
|
||||
|
||||
it "returns true if this is a next in a loop" do
|
||||
|
@ -103,7 +103,7 @@ module Ameba::AST
|
|||
|
||||
it "returns false if this is a next out of loop" do
|
||||
node = as_node("next")
|
||||
subject.flow_command?(node, false).should eq false
|
||||
subject.flow_command?(node, false).should be_false
|
||||
end
|
||||
|
||||
it "returns true if this is raise" do
|
||||
|
@ -123,7 +123,7 @@ module Ameba::AST
|
|||
|
||||
it "returns false otherwise" do
|
||||
node = as_node("foobar")
|
||||
subject.flow_command?(node, false).should eq false
|
||||
subject.flow_command?(node, false).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -195,7 +195,7 @@ module Ameba::AST
|
|||
break
|
||||
end
|
||||
CRYSTAL
|
||||
subject.flow_expression?(node).should eq false
|
||||
subject.flow_expression?(node).should be_false
|
||||
end
|
||||
|
||||
it "returns true if this until consumed by flow expressions" do
|
||||
|
@ -213,7 +213,7 @@ module Ameba::AST
|
|||
break
|
||||
end
|
||||
CRYSTAL
|
||||
subject.flow_expression?(node).should eq false
|
||||
subject.flow_expression?(node).should be_false
|
||||
end
|
||||
|
||||
it "returns true if this expressions consumed by flow expressions" do
|
||||
|
@ -230,7 +230,7 @@ module Ameba::AST
|
|||
exp1
|
||||
exp2
|
||||
CRYSTAL
|
||||
subject.flow_expression?(node).should eq false
|
||||
subject.flow_expression?(node).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -242,12 +242,12 @@ module Ameba::AST
|
|||
|
||||
it "returns false if it has a receiver" do
|
||||
node = as_node "obj.raise e"
|
||||
subject.raise?(node).should eq false
|
||||
subject.raise?(node).should be_false
|
||||
end
|
||||
|
||||
it "returns false if size of the arguments doesn't match" do
|
||||
node = as_node "raise"
|
||||
subject.raise?(node).should eq false
|
||||
subject.raise?(node).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -264,12 +264,12 @@ module Ameba::AST
|
|||
|
||||
it "returns false if it has a receiver" do
|
||||
node = as_node "obj.exit"
|
||||
subject.exit?(node).should eq false
|
||||
subject.exit?(node).should be_false
|
||||
end
|
||||
|
||||
it "returns false if size of the arguments doesn't match" do
|
||||
node = as_node "exit 1, 1"
|
||||
subject.exit?(node).should eq false
|
||||
subject.exit?(node).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -291,12 +291,12 @@ module Ameba::AST
|
|||
|
||||
it "returns false if it has a receiver" do
|
||||
node = as_node "obj.abort"
|
||||
subject.abort?(node).should eq false
|
||||
subject.abort?(node).should be_false
|
||||
end
|
||||
|
||||
it "returns false if size of the arguments doesn't match" do
|
||||
node = as_node "abort 1, 1, 1"
|
||||
subject.abort?(node).should eq false
|
||||
subject.abort?(node).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -308,12 +308,12 @@ module Ameba::AST
|
|||
|
||||
it "returns false if it has a receiver" do
|
||||
node = as_node "obj.loop"
|
||||
subject.loop?(node).should eq false
|
||||
subject.loop?(node).should be_false
|
||||
end
|
||||
|
||||
it "returns false if size of the arguments doesn't match" do
|
||||
node = as_node "loop 1"
|
||||
subject.loop?(node).should eq false
|
||||
subject.loop?(node).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -44,7 +44,12 @@ module Ameba::Cli
|
|||
|
||||
it "defaults rules? flag to false" do
|
||||
c = Cli.parse_args %w(file.cr)
|
||||
c.rules?.should eq false
|
||||
c.rules?.should be_false
|
||||
end
|
||||
|
||||
it "defaults skip_reading_config? flag to false" do
|
||||
c = Cli.parse_args %w(file.cr)
|
||||
c.skip_reading_config?.should be_false
|
||||
end
|
||||
|
||||
it "accepts --rules flag" do
|
||||
|
@ -54,7 +59,7 @@ module Ameba::Cli
|
|||
|
||||
it "defaults all? flag to false" do
|
||||
c = Cli.parse_args %w(file.cr)
|
||||
c.all?.should eq false
|
||||
c.all?.should be_false
|
||||
end
|
||||
|
||||
it "accepts --all flag" do
|
||||
|
@ -82,6 +87,12 @@ module Ameba::Cli
|
|||
c.colors?.should be_true
|
||||
end
|
||||
|
||||
it "ignores --config if --gen-config flag passed" do
|
||||
c = Cli.parse_args %w(--gen-config --config my_config.yml)
|
||||
c.formatter.should eq :todo
|
||||
c.skip_reading_config?.should be_true
|
||||
end
|
||||
|
||||
describe "-e/--explain" do
|
||||
it "configures file/line/column" do
|
||||
c = Cli.parse_args %w(--explain src/file.cr:3:5)
|
||||
|
|
|
@ -14,7 +14,7 @@ module Ameba::Cli
|
|||
raise "Invalid usage: Cannot explain an issue and autocorrect at the same time."
|
||||
end
|
||||
|
||||
config = Config.load opts.config, opts.colors?
|
||||
config = Config.load opts.config, opts.colors?, opts.skip_reading_config?
|
||||
config.autocorrect = autocorrect
|
||||
|
||||
if globs = opts.globs
|
||||
|
@ -51,6 +51,7 @@ module Ameba::Cli
|
|||
property except : Array(String)?
|
||||
property location_to_explain : NamedTuple(file: String, line: Int32, column: Int32)?
|
||||
property fail_level : Severity?
|
||||
property? skip_reading_config = false
|
||||
property? rules = false
|
||||
property? all = false
|
||||
property? colors = true
|
||||
|
@ -105,6 +106,7 @@ module Ameba::Cli
|
|||
parser.on("--gen-config",
|
||||
"Generate a configuration file acting as a TODO list") do
|
||||
opts.formatter = :todo
|
||||
opts.skip_reading_config = true
|
||||
end
|
||||
|
||||
parser.on("--fail-level SEVERITY",
|
||||
|
|
|
@ -106,9 +106,13 @@ class Ameba::Config
|
|||
# ```
|
||||
# config = Ameba::Config.load
|
||||
# ```
|
||||
def self.load(path = nil, colors = true)
|
||||
def self.load(path = nil, colors = true, skip_reading_config = false)
|
||||
Colorize.enabled = colors
|
||||
content = read_config(path) || "{}"
|
||||
content = if skip_reading_config
|
||||
"{}"
|
||||
else
|
||||
read_config(path) || "{}"
|
||||
end
|
||||
Config.new YAML.parse(content)
|
||||
rescue e
|
||||
raise "Config file is invalid: #{e.message}"
|
||||
|
|
Loading…
Reference in a new issue