mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Check for unneeded directives when all other rules are done
This commit is contained in:
parent
6fb483a2dd
commit
eda5960b0f
8 changed files with 53 additions and 17 deletions
|
@ -14,10 +14,6 @@ module Ameba::Rule
|
|||
rules.should contain DummyRule
|
||||
rules.should contain NoProperties
|
||||
end
|
||||
|
||||
it "should not include syntax rule" do
|
||||
Rule.rules.should_not contain Rule::Syntax
|
||||
end
|
||||
end
|
||||
|
||||
context "properties" do
|
||||
|
|
|
@ -66,14 +66,14 @@ module Ameba
|
|||
config = Config.load config_sample
|
||||
|
||||
it "updates enabled property" do
|
||||
name = DummyRule.class_name
|
||||
name = DummyRule.rule_name
|
||||
config.update_rule name, enabled: false
|
||||
rule = config.rules.find(&.name.== name).not_nil!
|
||||
rule.enabled.should be_false
|
||||
end
|
||||
|
||||
it "updates excluded property" do
|
||||
name = DummyRule.class_name
|
||||
name = DummyRule.rule_name
|
||||
excluded = %w(spec/source.cr)
|
||||
config.update_rule name, excluded: excluded
|
||||
rule = config.rules.find(&.name.== name).not_nil!
|
||||
|
|
|
@ -44,7 +44,7 @@ module Ameba
|
|||
end
|
||||
|
||||
it "creates a todo with run details" do
|
||||
create_todo.should contain "Run `ameba --only #{DummyRule.class_name}`"
|
||||
create_todo.should contain "Run `ameba --only #{DummyRule.rule_name}`"
|
||||
end
|
||||
|
||||
it "excludes source from this rule" do
|
||||
|
|
|
@ -67,7 +67,7 @@ module Ameba::Rule
|
|||
|
||||
it "fails if there is disabled UnneededDisableDirective" do
|
||||
s = Source.new %Q(
|
||||
# ameba:disable #{UnneededDisableDirective.class_name}
|
||||
# ameba:disable #{UnneededDisableDirective.rule_name}
|
||||
a = 1
|
||||
), "source.cr"
|
||||
s.error UnneededDisableDirective.new, 3, 1, "Alarm!", :disabled
|
||||
|
|
|
@ -6,7 +6,7 @@ module Ameba
|
|||
config.formatter = formatter
|
||||
config.files = files
|
||||
|
||||
config.update_rule ErrorRule.class_name, enabled: false
|
||||
config.update_rule ErrorRule.rule_name, enabled: false
|
||||
|
||||
Runner.new(config)
|
||||
end
|
||||
|
@ -59,7 +59,7 @@ module Ameba
|
|||
|
||||
Runner.new(rules, [source], formatter).run
|
||||
source.should_not be_valid
|
||||
source.errors.first.rule.name.should eq "Syntax"
|
||||
source.errors.first.rule.name.should eq Rule::Syntax.rule_name
|
||||
end
|
||||
|
||||
it "does not run other rules" do
|
||||
|
@ -75,6 +75,19 @@ module Ameba
|
|||
source.errors.size.should eq 1
|
||||
end
|
||||
end
|
||||
|
||||
context "unneeded disables" do
|
||||
it "reports an error if such disable exists" do
|
||||
rules = [Rule::UnneededDisableDirective.new] of Rule::Base
|
||||
source = Source.new %(
|
||||
a = 1 # ameba:disable LineLength
|
||||
)
|
||||
|
||||
Runner.new(rules, [source], formatter).run
|
||||
source.should_not be_valid
|
||||
source.errors.first.rule.name.should eq Rule::UnneededDisableDirective.rule_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#success?" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue