Class: SCSSLint::ControlCommentProcessor
- Inherits:
-
Object
- Object
- SCSSLint::ControlCommentProcessor
- Defined in:
- lib/scss_lint/control_comment_processor.rb
Overview
Tracks which lines have been disabled for a given linter.
Instance Method Summary collapse
-
#after_node_visit(node) ⇒ Object
Executed after a node has been visited.
-
#before_node_visit(node) ⇒ Object
Executed before a node has been visited.
-
#filter_lints(lints) ⇒ Object
Filter lints given the comments that were processed in the document.
-
#initialize(linter) ⇒ ControlCommentProcessor
constructor
A new instance of ControlCommentProcessor.
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.
48 49 50 51 52 |
# File 'lib/scss_lint/control_comment_processor.rb', line 48 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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/scss_lint/control_comment_processor.rb', line 22 def before_node_visit(node) return unless node.is_a?(Sass::Tree::CommentNode) return unless match = /(?x) \*\s* # Comment line start marker scss-lint: (?<command>disable|enable)\s+ (?<linters>.*?) \s*(?:\*\/|\n) # Comment end marker or end of line /.match(node.value.first) linters = match[:linters].split(/\s*,\s*|\s+/) return unless linters.include?('all') || linters.include?(@linter.name) process_command(match[:command], node) # Is the control comment the only thing on this line? return if %r{^\s*(//|/\*)}.match(@linter.engine.lines[node.line - 1]) # If so, pop since we only want the 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.
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 |