Sha256: 755c2e5ef292af8909c4d722fda20594438e503296ac8bb163848737e6e27b61

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module SCSSLint
  # Checks for capitalized letters in IDs, classes, types, etc. in selectors.
  class Linter::CapitalizationInSelector < Linter
    include LinterRegistry

    def visit_root(_node)
      @ignored_names = Array(config['ignored_names']).to_set
      @ignored_types = Array(config['ignored_types']).to_set
      yield
    end

    def visit_attribute(attribute)
      check(attribute) unless @ignored_types.include?('attribute')
    end

    def visit_class(klass)
      check(klass) unless @ignored_types.include?('class')
    end

    def visit_element(element)
      check(element) unless @ignored_types.include?('element')
    end

    def visit_id(id)
      check(id) unless @ignored_types.include?('id')
    end

    def visit_placeholder(placeholder)
      check(placeholder) unless @ignored_types.include?('placeholder')
    end

    def visit_pseudo(pseudo)
      check(pseudo, 'Pseudo-selector') unless @ignored_types.include?('pseudo-selector')
    end

  private

    def check(node, selector_name = nil)
      name = node.name

      return if @ignored_names.include?(name)
      return unless name =~ /[A-Z]/

      selector_name ||= node.class.name.split('::').last
      add_lint(node, "#{selector_name} `#{name}` in selector should be " \
                     "written in all lowercase as `#{name.downcase}`")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scss-lint-0.28.0 lib/scss_lint/linter/capitalization_in_selector.rb