Class: SCSSLint::Linter::StringQuotes

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

Overview

Checks the type of quotes used in string literals.

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_charset(node) ⇒ Object



26
27
28
29
30
31
# File 'lib/scss_lint/linter/string_quotes.rb', line 26

def visit_charset(node)
  # `@charset` source range includes entire declaration, so exclude that prefix
  source = source_from_range(node.source_range)[('@charset'.length)..-1]

  check_quotes(node, source)
end

#visit_import(node) ⇒ Object



21
22
23
24
# File 'lib/scss_lint/linter/string_quotes.rb', line 21

def visit_import(node)
  # `@import` source range conveniently includes only the quoted string
  check_quotes(node, source_from_range(node.source_range))
end

#visit_script_string(node) ⇒ Object



17
18
19
# File 'lib/scss_lint/linter/string_quotes.rb', line 17

def visit_script_string(node)
  check_quotes(node, source_from_range(node.source_range))
end

#visit_script_stringinterpolation(node) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/scss_lint/linter/string_quotes.rb', line 6

def visit_script_stringinterpolation(node)
  # We can't statically determine what the resultant string looks like when
  # string interpolation is used, e.g. "one #{$var} three" could be a very
  # different string depending on $var = `'" + "'` or $var = `two`.
  #
  # Thus we manually skip the substrings in the string interpolation and
  # visit the expressions in the interpolation itself.
  node.children.reject { |child| child.is_a?(Sass::Script::Tree::Literal) }
               .each { |child| visit(child) }
end