Skip to content

Commit

Permalink
Add support for using erb_lint in inline config comments (#385)
Browse files Browse the repository at this point in the history
* Add support for using `erb_lint` in inline config comments

* Tweak readme to update inline config format
  • Loading branch information
stevegeek authored Oct 17, 2024
1 parent 67e9f5c commit 2423fc0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 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 SelfClosingTag %>
<hr /> <%# erb_lint:disable SelfClosingTag %>
```

To raise an error when there is a useless disable comment, enable `NoUnusedDisable`.
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 (?<rules>.*#{rule}).*/)
lines.match?(/# erb_?lint:disable (?<rules>.*#{rule}).*/)
end

def self.disabled_rules(line)
line.match(/# erblint:disable (?<rules>.*) %>/)&.named_captures&.fetch("rules")
line.match(/# erb_?lint:disable (?<rules>.*) %>/)&.named_captures&.fetch("rules")
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/erb_lint/utils/inline_configs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
expect(utils.rule_disable_comment_for_lines?("AnchorRule", offending_lines)).to(be(true))
end

it "supports both erb_lint and erblint naming" do
offending_lines = '<a href="#"></a><%# erb_lint: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 comment for rule in Ruby comment" do
offending_lines = '<%
button = {
Expand Down

0 comments on commit 2423fc0

Please sign in to comment.