Sha256: bc3c1710015f8cf810a34f2e9eb9b8f0aa39f958199aaf417bec935b242e5806

Contents?: true

Size: 1.38 KB

Versions: 37

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require_relative "helpers/rule_helpers"
module ERBLint
  module Linters
    module Primer
      module Accessibility
        # Flag when `.tooltipped` is being used and offer alternatives.
        class TooltippedMigration < Linter
          include LinterRegistry
          include Helpers::RuleHelpers

          MIGRATE_TO_NEWER_TOOLTIP = ".tooltipped has been deprecated. Due to major accessibility concerns with using this tooltip, please migrate to a Primer Tooltip component or rework the design to eliminate the tooltip. See https://primer.style/guides/rails/migration-guides/primer-css-tooltipped."
          TOOLTIPPED_RUBY_PATTERN = /classes:.*tooltipped|class:.*tooltipped/.freeze

          def run(processed_source)
            # HTML tags
            tags(processed_source).each do |tag|
              next if tag.closing?

              classes = tag.attributes["class"]&.value
              generate_offense(self.class, processed_source, tag, MIGRATE_TO_NEWER_TOOLTIP) if classes&.include?("tooltipped")
            end

            # ERB nodes
            erb_nodes(processed_source).each do |node|
              code = extract_ruby_from_erb_node(node)
              generate_node_offense(self.class, processed_source, node, MIGRATE_TO_NEWER_TOOLTIP) if code.match?(TOOLTIPPED_RUBY_PATTERN)
            end
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.52.2 lib/primer/view_components/linters/tooltipped_migration.rb
primer_view_components-0.36.4 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.52.1 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.52.0 lib/primer/view_components/linters/tooltipped_migration.rb
primer_view_components-0.36.3 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.51.0 lib/primer/view_components/linters/tooltipped_migration.rb
primer_view_components-0.36.2 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.50.1 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.50.0 lib/primer/view_components/linters/tooltipped_migration.rb
primer_view_components-0.36.1 lib/primer/view_components/linters/tooltipped_migration.rb
primer_view_components-0.36.0 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.49.2 lib/primer/view_components/linters/tooltipped_migration.rb
primer_view_components-0.35.2 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.49.1 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.49.0 lib/primer/view_components/linters/tooltipped_migration.rb
primer_view_components-0.35.1 lib/primer/view_components/linters/tooltipped_migration.rb
primer_view_components-0.35.0 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.48.2 lib/primer/view_components/linters/tooltipped_migration.rb
openproject-primer_view_components-0.48.1 lib/primer/view_components/linters/tooltipped_migration.rb