Skip to content

Commit

Permalink
Bump erblint-github and make sure it is actually running. (#2067)
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 authored Jun 12, 2023
1 parent c0fa71e commit aa8b1e2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 39 deletions.
25 changes: 3 additions & 22 deletions .erb-lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
EnableDefaultLinters: true
inherit_gem:
erblint-github:
- config/accessibility.yml
linters:
DeprecatedComponentsCounter:
enabled: true
Expand All @@ -9,28 +12,6 @@ linters:
enabled: true
LabelComponentMigrationCounter:
enabled: true
GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled:
enabled: true
GitHub::Accessibility::AvoidGenericLinkTextCounter:
enabled: true
GitHub::Accessibility::DisabledAttributeCounter:
enabled: true
GitHub::Accessibility::IframeHasTitle:
enabled: true
GitHub::Accessibility::ImageHasAlt:
enabled: true
GitHub::Accessibility::LinkHasHrefCounter:
enabled: true
GitHub::Accessibility::NoAriaLabelMisuseCounter:
enabled: true
GitHub::Accessibility::NoPositiveTabIndex:
enabled: true
GitHub::Accessibility::NoRedundantImageAlt:
enabled: true
GitHub::Accessibility::NoTitleAttributeCounter:
enabled: true
GitHub::Accessibility::SvgHasAccessibleTextCounter:
enabled: true
Rubocop:
enabled: true
rubocop_config:
Expand Down
1 change: 1 addition & 0 deletions .erb-linters/erblint-github.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "erblint-github/linters"
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ GEM
rainbow
rubocop
smart_properties
erblint-github (0.1.0)
erblint-github (0.4.0)
erubi (1.12.0)
ferrum (0.11)
addressable (~> 2.5)
Expand Down Expand Up @@ -248,7 +248,7 @@ DEPENDENCIES
capybara (~> 3)
cuprite (= 0.13)
erb_lint (~> 0.4.0)
erblint-github (= 0.1.0)
erblint-github (= 0.4.0)
listen (~> 3.0)
lookbook (~> 2.0.0)
matrix (~> 0.4.2)
Expand Down
2 changes: 1 addition & 1 deletion app/components/primer/alpha/octicon_symbols.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" hidden>
<svg xmlns="http://www.w3.org/2000/svg" hidden> <%# erblint:disable GitHub::Accessibility::SvgHasAccessibleText %>
<%= symbol_tags %>
</svg>
50 changes: 37 additions & 13 deletions lib/primer/view_components/linters/deprecated_components_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
require_relative "helpers/deprecated_components_helpers"
require_relative "severity_schema"

require "erblint-github/linters/custom_helpers"

module ERBLint
module Linters
# Lints against deprecated components
class DeprecatedComponentsCounter < Linter
include CustomHelpers
class DeprecatedComponentsCounter < BaseLinter
include ERBLint::LinterRegistry
include Helpers::DeprecatedComponentsHelpers

Expand All @@ -25,7 +22,7 @@ def run(processed_source)
deprecated_components.each do |component|
next unless code.include?(component)

add_offense(erb_node.loc, message(component))
add_offense_with_severity(erb_node.loc, message(component))
end
end

Expand All @@ -46,14 +43,41 @@ def autocorrect(processed_source, offense)
end
end

# this override is necessary because of the github/erblint-github `CustomHelpers`
# module. `counter_correct?` is provided by this module, and calls `add_offense`
# directly. there is no simple way to modify this without updating the gem and
# creating what would likely be an API that is non-standard and/or difficult to use
#
# https://github.com/github/erblint-github/blob/main/lib/erblint-github/linters/custom_helpers.rb
def add_offense(source_range, message, context = nil, severity = nil)
super(source_range, message, context, severity || @config.severity)
def counter_correct?(processed_source)
comment_node = nil
expected_count = 0
rule_name = self.class.name.gsub("ERBLint::Linters::", "")
offenses_count = @offenses.length

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

if indicator == "#" && comment.start_with?("erblint:counter") && comment.match(rule_name)
comment_node = node
expected_count = comment.match(/\s(\d+)\s?$/)[1].to_i
end
end

if offenses_count.zero?
# have to adjust to get `\n` so we delete the whole line
add_offense_with_severity(processed_source.to_source_range(comment_node.loc.adjust(end_pos: 1)), "Unused erblint:counter comment for #{rule_name}", "") if comment_node
return
end

first_offense = @offenses[0]

if comment_node.nil?
add_offense_with_severity(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} %>")
else
clear_offenses
add_offense_with_severity(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
end
end

def add_offense_with_severity(source_range, message, context = nil, severity = nil)
add_offense(source_range, message, context, severity || @config.severity)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion primer_view_components.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "capybara", "~> 3"
spec.add_development_dependency "cuprite", "= 0.13"
spec.add_development_dependency "erb_lint", "~> 0.4.0"
spec.add_development_dependency "erblint-github", "0.1.0"
spec.add_development_dependency "erblint-github", "0.4.0"
spec.add_development_dependency "listen", "~> 3.0"
spec.add_development_dependency "matrix", "~> 0.4.2"
spec.add_development_dependency "minitest", "~> 5.0"
Expand Down

0 comments on commit aa8b1e2

Please sign in to comment.