Make InlineComments::COMMENT_DIRECTIVE_REGEX more strict (#146)

This commit is contained in:
Sijawusz Pur Rahnama 2020-04-11 08:55:41 +02:00 committed by GitHub
parent 458c492730
commit 1a25583036
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 17 deletions

View file

@ -6,17 +6,22 @@ module Ameba
subject = InlineComments::COMMENT_DIRECTIVE_REGEX
it "allows to parse action and rule name" do
result = subject.match("#ameba:enable Group/RuleName")
result.should_not be_nil
result.not_nil![1].should eq "enable"
result.not_nil![2].should eq "Group/RuleName"
result = subject.match("# ameba:enable Group/RuleName")
result = result.should_not be_nil
result["action"].should eq "enable"
result["rules"].should eq "Group/RuleName"
end
it "ignores the repeatable spaces" do
it "parses multiple rules" do
result = subject.match("# ameba:enable Group/RuleName, OtherRule, Foo/Bar")
result = result.should_not be_nil
result["action"].should eq "enable"
result["rules"].should eq "Group/RuleName, OtherRule, Foo/Bar"
end
it "fails to parse directives with spaces" do
result = subject.match("# ameba : enable Group/RuleName")
result.should_not be_nil
result.not_nil![1].should eq "enable"
result.not_nil![2].should eq "Group/RuleName"
result.should be_nil
end
end

View file

@ -28,7 +28,7 @@ module Ameba::Rule::Lint
it "reports if there are incorrect rule names" do
s = Source.new %(
# ameba:enable BadRule1,BadRule2
# ameba:enable BadRule1, BadRule2
), "source.cr"
subject.catch(s).should_not be_valid
s.issues.size.should eq 1