Make config loading more flexible

This commit is contained in:
Vitalii Elenhaupt 2017-11-22 08:44:29 +02:00
parent b5c9f4dff6
commit f4f401d56f
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
33 changed files with 243 additions and 92 deletions

28
spec/ameba/base_spec.cr Normal file
View file

@ -0,0 +1,28 @@
require "../spec_helper"
module Ameba::Rule
struct NoProperties < Rule::Base
def test(source)
end
end
describe Base do
context "properties" do
subject = DummyRule.new
it "is enabled by default" do
subject.enabled.should be_true
end
it "has a description property" do
subject.description.should_not be_nil
end
end
describe "when a rule does not have defined properties" do
it "is enabled by default" do
NoProperties.new.enabled.should be_true
end
end
end
end

View file

@ -112,7 +112,7 @@ module Ameba::Rule
error = s.errors.first
error.rule.should_not be_nil
error.location.to_s.should eq "source.cr:2:9"
error.message.should eq "Duplicated when conditions in case."
error.message.should eq "Duplicated when conditions in case"
end
end
end

View file

@ -116,5 +116,14 @@ module Ameba
error.location.to_s.should eq "source.cr:2:10"
error.message.should match /1_200_000/
end
context "properties" do
it "allows to configure integer min digits" do
s = Source.new %q(1200000)
rule = Rule::LargeNumbers.new
rule.int_min_digits = 10
rule.catch(s).should be_valid
end
end
end
end

View file

@ -29,5 +29,14 @@ module Ameba::Rule
error.location.to_s.should eq "source.cr:1:81"
error.message.should eq "Line too long"
end
context "properties" do
it "allows to configure max length of the line" do
source = Source.new long_line
rule = LineLength.new
rule.max_length = long_line.size
rule.catch(source).should be_valid
end
end
end
end

View file

@ -65,5 +65,21 @@ module Ameba::Rule
"Symbols `,\"` may be unwanted in %w array literals"
)
end
context "properties" do
it "allows to configure string_array_unwanted_symbols" do
rule = PercentArrays.new
rule.string_array_unwanted_symbols = ","
s = Source.new %( %w("one") )
rule.catch(s).should be_valid
end
it "allows to configure symbol_array_unwanted_symbols" do
rule = PercentArrays.new
rule.symbol_array_unwanted_symbols = ","
s = Source.new %( %i(:one) )
rule.catch(s).should be_valid
end
end
end
end

View file

@ -207,7 +207,7 @@ module Ameba::Rule
error = s.errors.first
error.rule.should_not be_nil
error.location.to_s.should eq "source.cr:2:9"
error.message.should eq "Redundant `begin` block detected."
error.message.should eq "Redundant `begin` block detected"
end
end
end

View file

@ -3,6 +3,10 @@ require "../src/ameba"
module Ameba
struct DummyRule < Rule::Base
properties do
description : String = "Dummy rule that does nothing."
end
def test(source)
end
end