Sha256: 85466ac873753042be49c7baccdffa31f215956f2d0d2e31330a353c9897fd60

Contents?: true

Size: 1.21 KB

Versions: 82

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

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

          MIGRATE_FROM_DETAILS_MENU = "<details-menu> has been deprecated. Please instead use Primer::Alpha::ActionMenu" \
            " https://primer.style/design/components/action-menu/rails/alpha"
          DETAILS_MENU_RUBY_PATTERN = /tag:?\s+:"details-menu"/.freeze

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

              generate_offense(self.class, processed_source, tag, MIGRATE_FROM_DETAILS_MENU) if tag.name == "details-menu"
            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_FROM_DETAILS_MENU) if code.match?(DETAILS_MENU_RUBY_PATTERN)
            end
          end
        end
      end
    end
  end
end

Version data entries

82 entries across 82 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.41.1 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.41.0 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.40.0 lib/primer/view_components/linters/details_menu_migration.rb
primer_view_components-0.30.0 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.39.1 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.39.0 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.38.0 lib/primer/view_components/linters/details_menu_migration.rb
primer_view_components-0.29.0 lib/primer/view_components/linters/details_menu_migration.rb
primer_view_components-0.28.0 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.37.1 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.37.0 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.36.2 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.36.1 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.36.0 lib/primer/view_components/linters/details_menu_migration.rb
primer_view_components-0.27.0 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.35.2 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.35.1 lib/primer/view_components/linters/details_menu_migration.rb
primer_view_components-0.26.1 lib/primer/view_components/linters/details_menu_migration.rb
openproject-primer_view_components-0.35.0 lib/primer/view_components/linters/details_menu_migration.rb
primer_view_components-0.26.0 lib/primer/view_components/linters/details_menu_migration.rb