Sha256: ab514b81c345ec5aa822d33280f34bd61db6d4ac2b8aa49e523bff329ecea01f

Contents?: true

Size: 1.33 KB

Versions: 4

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.join

      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

4 entries across 4 versions & 1 rubygems

Version Path
scss-lint-0.27.0 lib/scss_lint/linter/capitalization_in_selector.rb
scss-lint-0.26.2 lib/scss_lint/linter/capitalization_in_selector.rb
scss-lint-0.26.1 lib/scss_lint/linter/capitalization_in_selector.rb
scss-lint-0.26.0 lib/scss_lint/linter/capitalization_in_selector.rb