Skip to content

Commit

Permalink
Use erblint:disable not erblint:disable-line to align with Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 committed Mar 24, 2023
1 parent f52fc0f commit 0afcd51
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ You can disable a rule by placing a disable comment in the following format:

Comment on offending lines
```.erb
<hr /> <%# erblint:disable-line SelfClosingTag %>
<hr /> <%# erblint:disable SelfClosingTag %>
```

To raise an error when there is a useless disable comment, enable `NoUnusedDisable`.
Expand Down
2 changes: 1 addition & 1 deletion lib/erb_lint/linters/no_unused_disable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run(processed_source, offenses)
disabled_rules_and_line_number.each do |rule, line_numbers|
line_numbers.each do |line_number|
add_offense(processed_source.source_buffer.line_range(line_number),
"Unused erblint:disable-line comment for #{rule}")
"Unused erblint:disable comment for #{rule}")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/erb_lint/utils/inline_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module ERBLint
module Utils
class InlineConfigs
def self.rule_disable_comment_for_lines?(rule, lines)
lines.match?(/# erblint:disable-line (?<rules>.*#{rule}).*/)
lines.match?(/# erblint:disable (?<rules>.*#{rule}).*/)
end

def self.disabled_rules(line)
line.match(/# erblint:disable-line (?<rules>.*) %>/)&.named_captures&.fetch("rules")
line.match(/# erblint:disable (?<rules>.*) %>/)&.named_captures&.fetch("rules")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/erb_lint/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def run(processed_source)
end
let(:linted_file) { "app/views/template.html.erb" }
let(:args) { ["--disable-inline-configs", "--enable-linter", "fake_linter", linted_file] }
let(:file_content) { "<violation></violation> <%# erblint:disable-line FakeLinter %>" }
let(:file_content) { "<violation></violation> <%# erblint:disable FakeLinter %>" }

before do
allow(ERBLint::LinterRegistry).to(receive(:linters)
Expand Down
20 changes: 10 additions & 10 deletions spec/erb_lint/linters/no_unused_disable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ class Fake < ERBLint::Linter
describe "offenses" do
subject { offenses }
context "when file has unused disable comment" do
let(:file) { "<span></span><%# erblint:disable-line Fake %>" }
let(:file) { "<span></span><%# erblint:disable Fake %>" }
before { linter.run(processed_source, []) }
it do
expect(subject.size).to(eq(1))
expect(subject.first.message).to(eq("Unused erblint:disable-line comment for Fake"))
expect(subject.first.message).to(eq("Unused erblint:disable comment for Fake"))
end
end

context "when file has a disable comment and a corresponding offense" do
let(:file) { "<span></span><%# erblint:disable-line Fake %>" }
let(:file) { "<span></span><%# erblint:disable Fake %>" }
before do
offense = ERBLint::Offense.new(ERBLint::Linters::Fake.new(file_loader, linter_config),
SpecUtils.source_range_for_code(processed_source, "<span></span>"),
Expand All @@ -47,7 +47,7 @@ class Fake < ERBLint::Linter

context "when file has a disable comment in wrong place and a corresponding offense" do
let(:file) { <<~FILE }
<%# erblint:disable-line Fake %>
<%# erblint:disable Fake %>
<span>bad content</span>
FILE
before do
Expand All @@ -62,12 +62,12 @@ class Fake < ERBLint::Linter

it "reports the unused inline comment" do
expect(subject.size).to(eq(1))
expect(subject.first.message).to(eq("Unused erblint:disable-line comment for Fake"))
expect(subject.first.message).to(eq("Unused erblint:disable comment for Fake"))
end
end

context "when file has disable comment for multiple rules" do
let(:file) { "<span></span><%# erblint:disable-line Fake, Fake2 %>" }
let(:file) { "<span></span><%# erblint:disable Fake, Fake2 %>" }
before do
offense = ERBLint::Offense.new(
ERBLint::Linters::Fake.new(file_loader, linter_config),
Expand All @@ -80,14 +80,14 @@ class Fake < ERBLint::Linter

it "reports the unused inline comment" do
expect(subject.size).to(eq(1))
expect(subject.first.message).to(eq("Unused erblint:disable-line comment for Fake2"))
expect(subject.first.message).to(eq("Unused erblint:disable comment for Fake2"))
end
end

context "when file has multiple disable comments for one offense" do
let(:file) { <<~ERB }
<%# erblint:disable-line Fake %>
<span></span><%# erblint:disable-line Fake %>
<%# erblint:disable Fake %>
<span></span><%# erblint:disable Fake %>
ERB
before do
offense = ERBLint::Offense.new(
Expand All @@ -101,7 +101,7 @@ class Fake < ERBLint::Linter

it "reports the unused inline comment" do
expect(subject.size).to(eq(1))
expect(subject.first.message).to(eq("Unused erblint:disable-line comment for Fake"))
expect(subject.first.message).to(eq("Unused erblint:disable comment for Fake"))
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/erb_lint/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class FakeLinter4 < FakeLinter3; end
let(:file) { <<~FILE }
<div>something</div>
<span>bad content</span>
<%# erblint:disable-line FakeLinter3 %>
<%# erblint:disable FakeLinter3 %>
FILE
let(:processed_source) { ERBLint::ProcessedSource.new(filename, file) }

Expand All @@ -188,7 +188,7 @@ class FakeLinter4 < FakeLinter3; end
let(:filename) { "somefolder/otherfolder/dummyfile.html.erb" }
let(:file) { <<~FILE }
<div>something</div>
<span>bad content</span><%# erblint:disable-line FakeLinter3 %>
<span>bad content</span><%# erblint:disable FakeLinter3 %>
FILE
let(:processed_source) { ERBLint::ProcessedSource.new(filename, file) }

Expand All @@ -203,7 +203,7 @@ class FakeLinter4 < FakeLinter3; end
let(:filename) { "somefolder/otherfolder/dummyfile.html.erb" }
let(:file) { <<~FILE }
<div>something</div>
<span>bad content</span> <%# erblint:disable-line FakeLinter3, FakeLinter4 %>
<span>bad content</span> <%# erblint:disable FakeLinter3, FakeLinter4 %>
FILE
let(:processed_source) { ERBLint::ProcessedSource.new(filename, file) }

Expand Down
20 changes: 10 additions & 10 deletions spec/lib/erb_lint/utils/inline_configs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@
let(:utils) { described_class }

context "rule_disable_comment_for_lines?" do
it "true when lines contain a erblint:disable-line comment for rule in ERB" do
offending_lines = '<a href="#"></a><%# erblint:disable-line AnchorRule %>'
it "true when lines contain a erblint:disable comment for rule in ERB" do
offending_lines = '<a href="#"></a><%# erblint:disable AnchorRule %>'
expect(utils.rule_disable_comment_for_lines?("AnchorRule", offending_lines)).to(be(true))
end

it "true lines when lines contain a erblint:disable-line comment for rule in Ruby comment" do
it "true lines when lines contain a erblint:disable comment for rule in Ruby comment" do
offending_lines = '<%
button = {
role: "img" # erblint:disable-line IncorrectRoleRule
role: "img" # erblint:disable IncorrectRoleRule
}
%>'
expect(utils.rule_disable_comment_for_lines?("IncorrectRoleRule", offending_lines)).to(be(true))
end

it "true lines when lines contain matching erblint:disable-line comment for rule in Ruby comment" do
it "true lines when lines contain matching erblint:disable comment for rule in Ruby comment" do
offending_lines = '<%
button = {
role: "img" # erblint:disable-line IncorrectRoleRule, AnotherRule
role: "img" # erblint:disable IncorrectRoleRule, AnotherRule
}
%>'
expect(utils.rule_disable_comment_for_lines?("AnotherRule", offending_lines)).to(be(true))
end

it "false when lines contain erblint:disable-line comment that does not contain specified rule" do
offending_lines = '<a href="#"></a><%# erblint:disable-line AnchorRule %>'
it "false when lines contain erblint:disable comment that does not contain specified rule" do
offending_lines = '<a href="#"></a><%# erblint:disable AnchorRule %>'
expect(utils.rule_disable_comment_for_lines?("AnotherRule", offending_lines)).to(be(false))
end
end

context "disabled_rules" do
it "returns rule in ERB" do
lines = '<a href="#"></a><%# erblint:disable-line AnchorRule %>'
lines = '<a href="#"></a><%# erblint:disable AnchorRule %>'
expect(utils.disabled_rules(lines)).to(eq("AnchorRule"))
end

it "returns rules in ERB" do
lines = '<a href="#"></a><%# erblint:disable-line Rule1, Rule2, Rule3 %>'
lines = '<a href="#"></a><%# erblint:disable Rule1, Rule2, Rule3 %>'
expect(utils.disabled_rules(lines)).to(eq("Rule1, Rule2, Rule3"))
end
end
Expand Down

0 comments on commit 0afcd51

Please sign in to comment.