Skip to content

Commit

Permalink
Merge pull request #363 from zw963/master
Browse files Browse the repository at this point in the history
Skip all config when use with --gen-config.
  • Loading branch information
veelenga authored Mar 9, 2023
2 parents 3fbbe39 + 239f64c commit adac90c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion spec/ameba/ast/flow_expression_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions spec/ameba/ast/util_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
15 changes: 13 additions & 2 deletions spec/ameba/cli/cmd_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/ameba/cli/cmd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions src/ameba/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit adac90c

Please sign in to comment.