Sha256: 7e2f4b0c002f5e3b9dae52af8ef79f4976237f671cd80e6f344f418ca3deceb8

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module ERBLint
  module Linters
    module Helpers
      # Helpers to share between DeprecatedComponents ERB lint and Rubocop cop
      module DeprecatedComponentsHelpers
        # If there is no alternative to suggest, set the value to nil
        COMPONENT_TO_USE_INSTEAD = {
          "Primer::ButtonGroup" => "Primer::Beta::ButtonGroup",
          "Primer::CloseButton" => "Primer::Beta::CloseButton",
          "Primer::CounterComponent" => "Primer::Beta::Counter",
          "Primer::Alpha::AutoComplete::Item" => "Primer::Beta::AutoComplete::Item",
          "Primer::Alpha::AutoComplete" => "Primer::Beta::AutoComplete",
          "Primer::BlankslateComponent" => "Primer::Beta::Blankslate",
          "Primer::BorderBoxComponent" => "Primer::Beta::BorderBox",
          "Primer::BoxComponent" => "Primer::Box",
          "Primer::DropdownMenuComponent" => nil,
          "Primer::Tooltip" => "Primer::Alpha::Tooltip",
          "Primer::FlexComponent" => nil,
          "Primer::FlexItemComponent" => nil
        }.freeze

        def message(component)
          message = "#{component} has been deprecated and should not be used."
          message += " Try #{COMPONENT_TO_USE_INSTEAD[component]} instead." if COMPONENT_TO_USE_INSTEAD.fetch(component).present?
          message
        end

        def statuses_json
          JSON.parse(
            File.read(
              File.join(File.dirname(__FILE__), "../../../../../static/statuses.json")
            )
          ).freeze
        end

        def deprecated_components
          @deprecated_components ||= statuses_json.select { |_, value| value == "deprecated" }.keys
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
primer_view_components-0.0.90 lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb