From 0d789d2a4173b063a01f1b187117a7909e85d96b Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Mon, 3 Apr 2023 14:53:33 -0400 Subject: [PATCH 1/3] Remove unused disable method --- lib/erblint-github/linters/custom_helpers.rb | 18 ----------------- test/custom_helpers_test.rb | 21 -------------------- 2 files changed, 39 deletions(-) diff --git a/lib/erblint-github/linters/custom_helpers.rb b/lib/erblint-github/linters/custom_helpers.rb index 1dbbc90..b5bb23b 100644 --- a/lib/erblint-github/linters/custom_helpers.rb +++ b/lib/erblint-github/linters/custom_helpers.rb @@ -8,24 +8,6 @@ module Linters module CustomHelpers INTERACTIVE_ELEMENTS = %w[button summary input select textarea a].freeze - def rule_disabled?(processed_source) - 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 diff --git a/test/custom_helpers_test.rb b/test/custom_helpers_test.rb index 0926e50..1a4b7b8 100644 --- a/test/custom_helpers_test.rb +++ b/test/custom_helpers_test.rb @@ -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 %> From 239f4e3483ddec60828f5dd841dd2d8f2152bd28 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Mon, 3 Apr 2023 14:59:21 -0400 Subject: [PATCH 2/3] Suggest adding erblint:disable instead of erblint:counter --- lib/erblint-github/linters/custom_helpers.rb | 4 ++-- .../avoid_both_disabled_and_aria_disabled_test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/erblint-github/linters/custom_helpers.rb b/lib/erblint-github/linters/custom_helpers.rb index b5bb23b..ebab2d2 100644 --- a/lib/erblint-github/linters/custom_helpers.rb +++ b/lib/erblint-github/linters/custom_helpers.rb @@ -34,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 diff --git a/test/linters/accessibility/avoid_both_disabled_and_aria_disabled_test.rb b/test/linters/accessibility/avoid_both_disabled_and_aria_disabled_test.rb index c513f78..340a86f 100644 --- a/test/linters/accessibility/avoid_both_disabled_and_aria_disabled_test.rb +++ b/test/linters/accessibility/avoid_both_disabled_and_aria_disabled_test.rb @@ -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 From cc6a40699a15a170988479d4f08c884925163052 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:15:02 -0400 Subject: [PATCH 3/3] bump to 0.2.1 --- Gemfile.lock | 2 +- erblint-github.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9040dca..b130c77 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - erblint-github (0.2.0) + erblint-github (0.2.1) GEM remote: https://rubygems.org/ diff --git a/erblint-github.gemspec b/erblint-github.gemspec index 0930369..c0db1dd 100644 --- a/erblint-github.gemspec +++ b/erblint-github.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = "erblint-github" - s.version = "0.2.0" + s.version = "0.2.1" s.summary = "erblint GitHub" s.description = "Template style checking for GitHub Ruby repositories" s.homepage = "https://github.com/github/erblint-github"