Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using erb_lint in inline config comments #385

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading