Sha256: a490854988d0e9aa36955fa4e518a04e9fc914d4c6959bc699332a0c0d9d634d

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require_relative "base_linter"

# Load all the other linters so we can filter out their restricted
# CLASSES—they will be responsible for complaining about the use of
# those HTML classes.
Dir[File.join(__dir__, "*.rb")].sort.each do |file|
  require file unless file == __FILE__
end

module ERBLint
  module Linters
    # Counts the number of times a class reserved for ViewComponents is used
    class DisallowComponentCssCounter < BaseLinter
      CLASSES = (
        JSON.parse(
          File.read(
            File.join(__dir__, "..", "..", "..", "..", "static", "classes.json")
          )
        ) - BaseLinter.subclasses.reduce([]) do |html_classes, klass|
          html_classes.concat(klass.const_get(:CLASSES))
        end
      ).freeze

      TAGS = nil
      MESSAGE = "Primer ViewComponents defines some HTML classes with associated styles that should not be used outside those components. (These classes might have their styles changed or even disappear in the future.) Instead of using this class directly, please use its component if appropriate or define the styles you need some other way."
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
primer_view_components-0.1.4 lib/primer/view_components/linters/disallow_component_css_counter.rb
primer_view_components-0.1.3 lib/primer/view_components/linters/disallow_component_css_counter.rb
primer_view_components-0.1.2 lib/primer/view_components/linters/disallow_component_css_counter.rb
primer_view_components-0.1.1 lib/primer/view_components/linters/disallow_component_css_counter.rb
primer_view_components-0.1.0 lib/primer/view_components/linters/disallow_component_css_counter.rb