Sha256: 94d83bc48ed9d1c6fae39279e8d4d4b6a668d6ea628016da288ecf88081a6fbc

Contents?: true

Size: 762 Bytes

Versions: 5

Compression:

Stored size: 762 Bytes

Contents

require 'sass'

module SCSSLint
  class Linter::TypeInIdSelectorLinter < Linter
    include LinterRegistry

    class << self
      def run(engine)
        lints = []
        engine.tree.each do |node|
          if node.is_a?(Sass::Tree::RuleNode)
            lints << check_type_in_selector(node)
          end
        end
        lints.compact
      end

      def description
        'Avoid ID names with unnecessary type selectors (e.g. prefer `#id` over `p#id`)'
      end

    private

      def check_type_in_selector(rule_node)
        selectors = rule_node.rule.first.to_s.split(',')

        selectors.each do |selector|
          return create_lint(rule_node) if selector.strip =~ /^[a-z0-9]+#.*/i
        end

        nil
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scss-lint-0.6 lib/scss_lint/linter/type_in_id_selector_linter.rb
scss-lint-0.5.2 lib/scss_lint/linter/type_in_id_selector_linter.rb
scss-lint-0.5.1 lib/scss_lint/linter/type_in_id_selector_linter.rb
scss-lint-0.5 lib/scss_lint/linter/type_in_id_selector_linter.rb
scss-lint-0.4 lib/scss_lint/linter/type_in_id_selector_linter.rb