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"
|
require "../../spec/spec_helper"
|
||||||
|
|
||||||
module Ameba
|
module Ameba
|
||||||
describe RULES do
|
|
||||||
it "contains available rules" do
|
|
||||||
Ameba::RULES.empty?.should be_false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe Rule do
|
describe Rule do
|
||||||
describe "#catch" do
|
describe "#catch" do
|
||||||
it "accepts and returns source" do
|
it "accepts and returns source" do
|
||||||
|
@ -20,5 +14,11 @@ module Ameba
|
||||||
DummyRule.new.name.should eq "DummyRule"
|
DummyRule.new.name.should eq "DummyRule"
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,4 +4,4 @@ require "../src/ameba"
|
||||||
struct DummyRule < Ameba::Rule
|
struct DummyRule < Ameba::Rule
|
||||||
def test(source)
|
def test(source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
|
|
||||||
def catch(source : Source)
|
def catch(source : Source)
|
||||||
RULES.each do |rule|
|
Rule.rules.each do |rule|
|
||||||
rule.new.test(source)
|
rule.new.test(source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
module Ameba
|
module Ameba
|
||||||
RULES = [
|
|
||||||
Rules::ComparisonToBoolean,
|
|
||||||
Rules::LineLength,
|
|
||||||
Rules::TrailingBlankLines,
|
|
||||||
Rules::TrailingWhitespace,
|
|
||||||
Rules::UnlessElse,
|
|
||||||
]
|
|
||||||
|
|
||||||
abstract struct Rule
|
abstract struct Rule
|
||||||
abstract def test(source : Source)
|
abstract def test(source : Source)
|
||||||
|
|
||||||
|
@ -21,5 +13,9 @@ module Ameba
|
||||||
def name
|
def name
|
||||||
self.class.name.gsub("Ameba::Rules::", "")
|
self.class.name.gsub("Ameba::Rules::", "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.rules
|
||||||
|
{{ @type.subclasses }}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue