Sha256: 2e9c0686e7c2efb3f481d8349ae4689c3e610996840a1ed1150b01f9f24396ba

Contents?: true

Size: 994 Bytes

Versions: 1

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

require_relative "helpers"
require_relative "argument_mappers/button"

module ERBLint
  module Linters
    # Counts the number of times a HTML button is used instead of the component.
    class ButtonComponentMigrationCounter < Linter
      include Helpers

      TAGS = %w[button summary a].freeze
      CLASSES = %w[btn btn-link].freeze
      MESSAGE = "We are migrating buttons to use [Primer::ButtonComponent](https://primer.style/view-components/components/button), please try to use that instead of raw HTML."

      private

      def map_arguments(tag)
        ArgumentMappers::Button.new(tag).to_s
      rescue ArgumentMappers::ConversionError
        nil
      end

      def message(tag)
        args = map_arguments(tag)

        return MESSAGE if args.nil?

        msg = "#{MESSAGE}\n\nTry using:\n\n<%= render Primer::ButtonComponent.new"
        msg += "(#{args})" if args.present?
        "#{msg} %>\n\nInstead of:\n"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
primer_view_components-0.0.44 lib/primer/view_components/linters/button_component_migration_counter.rb