Class: SCSSLint::Linter::Shorthand

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

Overview

Checks for the use of the shortest form for properties that can be written in shorthand.

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

Parameters:



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

def visit_prop(node)
  property_name = node.name.join
  return unless SHORTHANDABLE_PROPERTIES.include?(property_name)

  if @shorthands_forbidden
    add_lint(node, "The `#{property_name}` shorthand property is " \
                   'forbidden since the `allowed_shorthands` option ' \
                   'is set to an empty list.')

  end

  case node.value.first
  when Sass::Script::Tree::Literal
    check_script_literal(property_name, node.value.first)
  when Sass::Script::Tree::ListLiteral
    check_script_list(property_name, node.value.first)
  end
end

#visit_rootObject



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

def visit_root(*)
  @shorthands_forbidden = @config['allowed_shorthands'] == []
  yield # Continue linting children
end