Class: SCSSLint::Linter::DisableLinterReason

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

Overview

Checks for “reason” comments above linter-disabling comments.

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

inherited, #initialize, #name, #run

Methods included from Utils

#color?, #color_hex?, #color_keyword?, #color_keyword_to_code, #else_node?, #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_comment(node) ⇒ Object



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

def visit_comment(node)
  # No lint if the first line of the comment is not a command (because then
  # either this comment has no commands, or the first line serves as a the
  # reason for a command on a later line).
  return unless comment_lines(node).first.match(COMMAND_REGEX)

  # Maybe the previous node is the "reason" comment.
  prev = previous_node(node)

  if prev && prev.is_a?(Sass::Tree::CommentNode)
    # No lint if the last line of the previous comment is not a command.
    return unless comment_lines(prev).last.match(COMMAND_REGEX)
  end

  add_lint(node,
           'scss-lint:disable control comments should be preceded by a ' \
           'comment explaining why the linters need to be disabled.')
end