Sha256: 8ec89a102bc0d42c9a117212f9c99641f46e62e4b905be1470d2e185230d0d44

Contents?: true

Size: 800 Bytes

Versions: 9

Compression:

Stored size: 800 Bytes

Contents

module SCSSLint
  # Checks for a selector with an ID combined with some other selector.
  class Linter::IdWithExtraneousSelector < Linter
    include LinterRegistry

    def visit_simple_sequence(seq)
      id_sel = seq.members.find { |simple| simple.is_a?(Sass::Selector::Id) }
      return unless id_sel

      can_be_simplified = seq.members.any? do |simple|
        !simple.is_a?(Sass::Selector::Id) &&
          !simple.is_a?(Sass::Selector::Pseudo)
      end
      return unless can_be_simplified

      # TODO: Sass::Selector::SimpleSequence#source_range sometimes lies about
      # its line, so reference `#line` directly
      add_lint(seq.line, "Selector `#{seq}` can be simplified to `#{id_sel}`, " \
                         'since IDs should be uniquely identifying')
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
scss-lint-0.28.0 lib/scss_lint/linter/id_with_extraneous_selector.rb
scss-lint-0.27.0 lib/scss_lint/linter/id_with_extraneous_selector.rb
scss-lint-0.26.2 lib/scss_lint/linter/id_with_extraneous_selector.rb
scss-lint-0.26.1 lib/scss_lint/linter/id_with_extraneous_selector.rb
scss-lint-0.26.0 lib/scss_lint/linter/id_with_extraneous_selector.rb
scss-lint-0.25.1 lib/scss_lint/linter/id_with_extraneous_selector.rb
scss-lint-0.25.0 lib/scss_lint/linter/id_with_extraneous_selector.rb
scss-lint-0.24.1 lib/scss_lint/linter/id_with_extraneous_selector.rb
scss-lint-0.24.0 lib/scss_lint/linter/id_with_extraneous_selector.rb