Sha256: e47ac912184132d421423a0d951af8fdb75da4c5066fd07fd391de0bf050fdf5

Contents?: true

Size: 975 Bytes

Versions: 14

Compression:

Stored size: 975 Bytes

Contents

module SCSSLint
  # Checks that selector sequences are split over multiple lines by comma.
  class Linter::SingleLinePerSelector < Linter
    include LinterRegistry

    MESSAGE = 'Each selector in a comma sequence should be on its own line'

    def visit_comma_sequence(node)
      return unless node.members.count > 1

      check_comma_on_own_line(node)

      node.members[1..-1].each_with_index do |sequence, index|
        check_sequence_commas(node, sequence, index)
      end
    end

  private

    def check_comma_on_own_line(node)
      return unless node.members[0].members[1] == "\n"
      add_lint(node, MESSAGE)
    end

    def check_sequence_commas(node, sequence, index)
      if sequence.members[0] != "\n"
        # Next sequence doesn't reside on its own line
        add_lint(node.line + index, MESSAGE)
      elsif sequence.members[1] == "\n"
        # Comma is on its own line
        add_lint(node.line + index, MESSAGE)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
scss_lint-0.40.1 lib/scss_lint/linter/single_line_per_selector.rb
scss_lint-0.40.0 lib/scss_lint/linter/single_line_per_selector.rb
scss_lint-0.39.0 lib/scss_lint/linter/single_line_per_selector.rb
scss_lint-0.38.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.38.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-bliss-1.0.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.37.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.36.1 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.36.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.35.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.34.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.33.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.32.0 lib/scss_lint/linter/single_line_per_selector.rb
scss-lint-0.31.0 lib/scss_lint/linter/single_line_per_selector.rb