Class: SCSSLint::ControlCommentProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/scss_lint/control_comment_processor.rb

Overview

Tracks which lines have been disabled for a given linter.

Instance Method Summary collapse

Constructor Details

#initialize(linter) ⇒ ControlCommentProcessor

Returns a new instance of ControlCommentProcessor.



6
7
8
9
10
# File 'lib/scss_lint/control_comment_processor.rb', line 6

def initialize(linter)
  @disable_stack = []
  @disabled_lines = Set.new
  @linter = linter
end

Instance Method Details

#after_node_visit(node) ⇒ Object

Executed after a node has been visited.

Parameters:



41
42
43
44
45
# File 'lib/scss_lint/control_comment_processor.rb', line 41

def after_node_visit(node)
  while @disable_stack.any? && @disable_stack.last.node_parent == node
    pop_control_comment_stack(node)
  end
end

#before_node_visit(node) ⇒ Object

Executed before a node has been visited.

Parameters:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/scss_lint/control_comment_processor.rb', line 22

def before_node_visit(node)
  return unless command = extract_command(node)

  linters = command[:linters]
  return unless linters.include?('all') || linters.include?(@linter.name)

  process_command(command[:action], node)

  # Is the control comment the only thing on this line?
  return if node.is_a?(Sass::Tree::RuleNode) ||
            %r{^\s*(//|/\*)}.match(@linter.engine.lines[node.line - 1])

  # Otherwise, pop since we only want comment to apply to the single line
  pop_control_comment_stack(node)
end

#filter_lints(lints) ⇒ Object

Filter lints given the comments that were processed in the document.

Parameters:



15
16
17
# File 'lib/scss_lint/control_comment_processor.rb', line 15

def filter_lints(lints)
  lints.reject { |lint| @disabled_lines.include?(lint.location.line) }
end