Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Suggest adding native disable instead of counter #61

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

Merged
merged 2 commits into from
Apr 3, 2023
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
22 changes: 2 additions & 20 deletions lib/erblint-github/linters/custom_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@ module Linters
module CustomHelpers
INTERACTIVE_ELEMENTS = %w[button summary input select textarea a].freeze

def rule_disabled?(processed_source)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused!

processed_source.parser.ast.descendants(:erb).each do |node|
indicator_node, _, code_node, = *node
indicator = indicator_node&.loc&.source
comment = code_node&.loc&.source&.strip
rule_name = simple_class_name

if indicator == "#" && comment.start_with?("erblint:disable") && comment.match(rule_name)
if @offenses.any?
clear_offenses
else
add_offense(processed_source.to_source_range(code_node.loc),
"Unused erblint:disable comment for #{rule_name}")
end
end
end
end

def counter_correct?(processed_source)
comment_node = nil
expected_count = 0
Expand All @@ -52,10 +34,10 @@ def counter_correct?(processed_source)
first_offense = @offenses[0]

if comment_node.nil?
add_offense(processed_source.to_source_range(first_offense.source_range), "#{rule_name}: If you must, add <%# erblint:counter #{rule_name} #{offenses_count} %> to bypass this check.", "<%# erblint:counter #{rule_name} #{offenses_count} %>")
add_offense(processed_source.to_source_range(first_offense.source_range), "#{rule_name}: If you must, add <%# erblint:disable #{rule_name} %> at the end of the offending line to bypass this check. See https://github.com/shopify/erb-lint#disable-rule-at-offense-level", "<%# erblint:disable #{rule_name} %>")
else
clear_offenses
add_offense(processed_source.to_source_range(comment_node.loc), "Incorrect erblint:counter number for #{rule_name}. Expected: #{expected_count}, actual: #{offenses_count}.", "<%# erblint:counter #{rule_name} #{offenses_count} %>") if expected_count != offenses_count
add_offense(processed_source.to_source_range(comment_node.loc), "Incorrect erblint:counter number for #{rule_name}. Expected: #{expected_count}, actual: #{offenses_count}.", "<%# erblint:counter #{rule_name}Counter #{offenses_count} %>") if expected_count != offenses_count
end
end

Expand Down
21 changes: 0 additions & 21 deletions test/custom_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,6 @@ def extended_linter
@linter.extend(ERBLint::Linters::CustomHelpers)
end

def test_rule_disabled_clears_offenses_if_rule_is_disabled
@file = <<~HTML
<%# erblint:disable CustomHelpersTest::FakeLinter %>
HTML
@linter.offenses = ["fake offense"]
assert_equal @linter.offenses.length, 1

extended_linter.rule_disabled?(processed_source)
assert_empty @linter.offenses
end

def test_rule_disabled_adds_offense_if_disable_comment_is_present_but_no_offense
@file = <<~HTML
<%# erblint:disable CustomHelpersTest::FakeLinter %>
HTML
assert_empty @linter.offenses

extended_linter.rule_disabled?(processed_source)
assert_equal "Unused erblint:disable comment for CustomHelpersTest::FakeLinter", @linter.offenses.first.message
end

def test_counter_correct_does_not_add_offense_if_counter_matches_offense_count
@file = <<~HTML
<%# erblint:counter CustomHelpersTest::FakeLinter 1 %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_adds_extra_offense_to_add_counter_comment_if_counter_config_enabled
@linter.run(processed_source)

assert_equal @linter.offenses.count, 8
assert_match(/If you must, add <%# erblint:counter GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled 7 %> to bypass this check/, @linter.offenses.last.message)
assert_match(/If you must, add <%# erblint:disable GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled %> at the end of the offending line to bypass this check./, @linter.offenses.last.message)
end

def test_does_not_raise_when_ignore_comment_with_correct_count_if_counter_enabled
Expand Down