Class: SCSSLint::Linter::PrivateNamingConvention

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

Overview

Verifies that variables, functions, and mixins that follow the private naming convention are defined and used within the same file.

Constant Summary collapse

DEFINITIONS =
{
  Sass::Tree::FunctionNode => {
    defines: Sass::Script::Tree::Funcall,
    human_name: 'function',
  },
  Sass::Tree::MixinDefNode => {
    defines: Sass::Tree::MixinNode,
    human_name: 'mixin',
  },
  Sass::Tree::VariableNode => {
    defines: Sass::Script::Tree::Variable,
    human_name: 'variable',
  },
}.freeze
HUMAN_NODE_NAMES =
Hash[DEFINITIONS.map { |k, v| [k, v[:human_name]] }].freeze
DEFINED_BYS =
Hash[DEFINITIONS.map { |k, v| [v[:defines], k] }].freeze

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



45
46
47
48
# File 'lib/scss_lint/linter/private_naming_convention.rb', line 45

def visit_mixin(node)
  check_privacy(node)
  yield # Continue into content block of this mixin's block
end

#visit_root(node) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/scss_lint/linter/private_naming_convention.rb', line 25

def visit_root(node)
  # Register all top-level function, mixin, and variable definitions.
  node.children.each do |child_node|
    if DEFINITIONS.key?(child_node.class)
      register_node child_node
    end

    yield
  end

  # After we have visited everything, we want to see if any private things
  # were defined but not used.
  after_visit_all
end

#visit_script_funcall(node) ⇒ Object



40
41
42
43
# File 'lib/scss_lint/linter/private_naming_convention.rb', line 40

def visit_script_funcall(node)
  check_privacy(node)
  yield # Continue linting any arguments of this function call
end

#visit_script_variable(node) ⇒ Object



50
51
52
# File 'lib/scss_lint/linter/private_naming_convention.rb', line 50

def visit_script_variable(node)
  check_privacy(node)
end