Load list of rules dynamically

This commit is contained in:
Vitalii Elenhaupt 2017-11-01 12:49:03 +02:00
parent 1822b2b0a2
commit dcc0be892a
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
4 changed files with 12 additions and 16 deletions

View file

@ -1,12 +1,6 @@
require "../../spec/spec_helper"
module Ameba
describe RULES do
it "contains available rules" do
Ameba::RULES.empty?.should be_false
end
end
describe Rule do
describe "#catch" do
it "accepts and returns source" do
@ -20,5 +14,11 @@ module Ameba
DummyRule.new.name.should eq "DummyRule"
end
end
describe ".rules" do
it "returns a list of all defined rules" do
Rule.rules.includes?(DummyRule).should be_true
end
end
end
end

View file

@ -25,7 +25,7 @@ module Ameba
end
def catch(source : Source)
RULES.each do |rule|
Rule.rules.each do |rule|
rule.new.test(source)
end
end

View file

@ -1,12 +1,4 @@
module Ameba
RULES = [
Rules::ComparisonToBoolean,
Rules::LineLength,
Rules::TrailingBlankLines,
Rules::TrailingWhitespace,
Rules::UnlessElse,
]
abstract struct Rule
abstract def test(source : Source)
@ -21,5 +13,9 @@ module Ameba
def name
self.class.name.gsub("Ameba::Rules::", "")
end
def self.rules
{{ @type.subclasses }}
end
end
end