Add --all cli flag that enables all available rules

This commit is contained in:
Vitalii Elenhaupt 2018-07-04 15:20:35 +03:00
parent 970ca4be1b
commit 248c5a656b
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
5 changed files with 25 additions and 8 deletions

View file

@ -16,4 +16,4 @@ bin: build
cp ./bin/ameba $(SHARD_BIN)
test: build
$(CRYSTAL_BIN) spec
./bin/ameba
./bin/ameba --all

View file

@ -42,6 +42,16 @@ module Ameba::Cli
c.except.should eq %w(RULE1 RULE2)
end
it "defaults all? flag to false" do
c = Cli.parse_args %w(file.cr)
c.all?.should eq false
end
it "accepts --all flag" do
c = Cli.parse_args %w(--all)
c.all?.should eq true
end
it "accepts --gen-config flag" do
c = Cli.parse_args %w(--gen-config)
c.formatter.should eq :todo

View file

@ -2,20 +2,20 @@ require "../../../spec_helper"
module Ameba::Rule::Layout
subject = LineLength.new
long_line = "*" * 81
long_line = "*" * (subject.max_length + 1)
describe LineLength do
it "passes if all lines are shorter than 80 symbols" do
it "passes if all lines are shorter than MaxLength symbols" do
source = Source.new "short line"
subject.catch(source).should be_valid
end
it "passes if line consists of 79 symbols" do
source = Source.new "*" * 80
it "passes if line consists of MaxLength symbols" do
source = Source.new "*" * subject.max_length
subject.catch(source).should be_valid
end
it "fails if there is at least one line longer than 79 symbols" do
it "fails if there is at least one line longer than MaxLength symbols" do
source = Source.new long_line
subject.catch(source).should_not be_valid
end
@ -26,7 +26,7 @@ module Ameba::Rule::Layout
issue = source.issues.first
issue.rule.should eq subject
issue.location.to_s.should eq "source.cr:1:81"
issue.location.to_s.should eq "source.cr:1:#{subject.max_length + 1}"
issue.message.should eq "Line too long"
end

View file

@ -25,6 +25,7 @@ module Ameba::Cli
property files : Array(String)?
property only : Array(String)?
property except : Array(String)?
property? all = false
end
def parse_args(args, opts = Opts.new)
@ -56,6 +57,10 @@ module Ameba::Cli
opts.except = rules.split ","
end
parser.on("--all", "Enables all available rules") do
opts.all = true
end
parser.on("--gen-config",
"Generate a configuration file acting as a TODO list") do
opts.formatter = :todo
@ -70,6 +75,8 @@ module Ameba::Cli
if only = opts.only
config.rules.map! { |r| r.enabled = false; r }
config.update_rules(only, enabled: true)
elsif opts.all?
config.rules.map! { |r| r.enabled = true; r }
end
config.update_rules(opts.except, enabled: false)

View file

@ -13,7 +13,7 @@ module Ameba::Rule::Layout
properties do
enabled false
description "Disallows lines longer than `MaxLength` number of symbols"
max_length 80
max_length 140
end
MSG = "Line too long"