Class: SCSSLint::Linter::ElsePlacement

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

Overview

Checks where `@else` and `@else if` directives are placed with respect to the previous curly brace.

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

#extract_string_selectors, #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_else(if_node, else_node) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/scss_lint/linter/else_placement.rb', line 11

def visit_else(if_node, else_node)
  # Check each @else branch if there are multiple `@else if`s
  visit_else(else_node, else_node.else) if else_node.else

  # Skip @else statements on the same line as the previous @if, since we
  # don't care about placement in that case
  return if if_node.line == else_node.line

  spaces = 0
  while (char = character_at(else_node.source_range.start_pos, - (spaces + 1)))
    if char == '}'
      curly_on_same_line = true
      break
    end
    spaces += 1
  end

  check_placement(else_node, curly_on_same_line)
end

#visit_if(node) ⇒ Object


7
8
9
# File 'lib/scss_lint/linter/else_placement.rb', line 7

def visit_if(node)
  visit_else(node, node.else) if node.else
end