mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Load list of rules dynamically
This commit is contained in:
parent
1822b2b0a2
commit
dcc0be892a
4 changed files with 12 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -4,4 +4,4 @@ require "../src/ameba"
|
|||
struct DummyRule < Ameba::Rule
|
||||
def test(source)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue