Class: SCSSLint::Linter

Inherits:
Sass::Tree::Visitors::Base
  • Object
show all
Includes:
SelectorVisitor, Utils
Defined in:
lib/scss_lint/linter.rb

Overview

Defines common functionality available to all linters.

Defined Under Namespace

Classes: BangFormat, BemDepth, BorderZero, ChainedClasses, ColorKeyword, ColorVariable, Comment, Compass, DebugStatement, DeclarationOrder, DisableLinterReason, DuplicateProperty, ElsePlacement, EmptyLineBetweenBlocks, EmptyRule, Encoding, ExtendDirective, FinalNewline, HexLength, HexNotation, HexValidation, IdSelector, ImportPath, ImportantRule, Indentation, LeadingZero, LengthVariable, MergeableSelector, NameFormat, NestingDepth, PlaceholderInExtend, PrivateNamingConvention, PropertyCount, PropertySortOrder, PropertySpelling, PropertyUnits, PseudoElement, QualifyingElement, SelectorDepth, SelectorFormat, Shorthand, SingleLinePerProperty, SingleLinePerSelector, SpaceAfterComma, SpaceAfterComment, SpaceAfterPropertyColon, SpaceAfterPropertyName, SpaceAfterVariableColon, SpaceAfterVariableName, SpaceAroundOperator, SpaceBeforeBrace, SpaceBetweenParens, StringQuotes, Syntax, TrailingSemicolon, TrailingWhitespace, TrailingZero, TransitionAll, UnnecessaryMantissa, UnnecessaryParentReference, UrlFormat, UrlQuotes, VariableForProperty, VendorPrefix, ZeroUnit

Constant Summary

Constants included from Utils

Utils::COLOR_REGEX

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#initializeLinter

Create a linter.



26
27
28
# File 'lib/scss_lint/linter.rb', line 26

def initialize
  @lints = []
end

Class Attribute Details

.simple_nameObject

Returns the value of attribute simple_name.



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

def simple_name
  @simple_name
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/scss_lint/linter.rb', line 23

def config
  @config
end

#engineObject (readonly)

Returns the value of attribute engine.



23
24
25
# File 'lib/scss_lint/linter.rb', line 23

def engine
  @engine
end

#lintsObject (readonly)

Returns the value of attribute lints.



23
24
25
# File 'lib/scss_lint/linter.rb', line 23

def lints
  @lints
end

Class Method Details

.inherited(linter) ⇒ Object

When defining a Linter class, define its simple name as well. This assumes that the module hierarchy of every linter starts with ‘SCSSLint::Linter::`, and removes this part of the class name.

‘SCSSLint::Linter::Foo.simple_name` #=> “Foo” `SCSSLint::Linter::Compass::Bar.simple_name` #=> “Compass::Bar”



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

def inherited(linter)
  name_parts = linter.name.split('::')
  name = name_parts.length < 3 ? '' : name_parts[2..-1].join('::')
  linter.simple_name = name
end

Instance Method Details

#nameObject

Return the human-friendly name of this linter as specified in the configuration file and in lint descriptions.



47
48
49
# File 'lib/scss_lint/linter.rb', line 47

def name
  self.class.simple_name
end

#run(engine, config) ⇒ Array<Lint>

Run this linter against a parsed document with the given configuration, returning the lints that were found.

Parameters:

Returns:



36
37
38
39
40
41
42
43
# File 'lib/scss_lint/linter.rb', line 36

def run(engine, config)
  @lints = []
  @config = config
  @engine = engine
  @comment_processor = ControlCommentProcessor.new(self)
  visit(engine.tree)
  @lints = @comment_processor.filter_lints(@lints)
end