Class: SCSSLint::Linter::SingleLinePerProperty

Inherits:
SCSSLint::Linter
  • Object
show all
Includes:
SCSSLint::LinterRegistry
Defined in:
lib/scss_lint/linter/single_line_per_property.rb

Overview

Checks that all properties in a rule set are on their own distinct lines.

Constant Summary

Constants included from Utils

Utils::COLOR_REGEX

Instance Attribute Summary

Attributes inherited from SCSSLint::Linter

#config, #engine, #lints

Instance Method Summary collapse

Methods included from SCSSLint::LinterRegistry

extract_linters_from, included

Methods inherited from SCSSLint::Linter

#initialize, #name, #run

Methods included from Utils

#color?, #color_hex?, #color_keyword?, #color_keyword_to_code, #extract_string_selectors, #node_ancestor, #node_siblings, #pluralize, #previous_node, #remove_quoted_strings, #same_position?

Methods included from SelectorVisitor

#visit_selector

Constructor Details

This class inherits a constructor from SCSSLint::Linter

Instance Method Details

#visit_rule(node) ⇒ Object

rubocop:disable CyclomaticComplexity



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/scss_lint/linter/single_line_per_property.rb', line 6

def visit_rule(node) # rubocop:disable CyclomaticComplexity
  single_line = single_line_rule_set?(node)
  return if single_line && config['allow_single_line_rule_sets']

  properties = node.children.select { |child| child.is_a?(Sass::Tree::PropNode) }
  return unless properties.any?

  # Special case: if single line rule sets aren't allowed, we want to report
  # when the first property isn't on a separate line from the selector
  if single_line && !config['allow_single_line_rule_sets']
    add_lint(properties.first,
             "Property '#{properties.first.name.join}' should be placed " \
             'on separate line from selector')
  end

  check_adjacent_properties(properties)
end