Class: SlimLint::Linter Abstract

Inherits:
Object
  • Object
show all
Extended by:
SexpVisitor::DSL
Includes:
SexpVisitor
Defined in:
lib/slim_lint/linter.rb

Overview

This class is abstract.

Base implementation for all lint checks.

Defined Under Namespace

Classes: CommentControlStatement, ConsecutiveControlStatements, ControlStatementSpacing, EmptyControlStatement, EmptyLines, FileLength, LineLength, RedundantDiv, RuboCop, Tab, TagCase, TrailingBlankLines, TrailingWhitespace

Instance Attribute Summary collapse

Attributes included from SexpVisitor::DSL

#captures, #patterns

Instance Method Summary collapse

Methods included from SexpVisitor::DSL

anything, capture, on, on_start

Methods included from SexpVisitor

#captures, #on_start, #patterns, #traverse, #traverse_children, #trigger_pattern_callbacks

Constructor Details

#initialize(config) ⇒ Linter

Initializes a linter with the specified configuration.

Parameters:

  • config (Hash)

    configuration for this linter



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

def initialize(config)
  @config = config
  @lints = []
end

Instance Attribute Details

#lintsObject (readonly)

TODO:

Remove once spec/support/shared_linter_context returns an array of lints for the subject instead of the linter itself.

List of lints reported by this linter.



16
17
18
# File 'lib/slim_lint/linter.rb', line 16

def lints
  @lints
end

Instance Method Details

#nameString

Returns the simple name for this linter.

Returns:

  • (String)


39
40
41
# File 'lib/slim_lint/linter.rb', line 39

def name
  self.class.name.split('::').last
end

#run(document) ⇒ Object

Runs the linter against the given Slim document.

Parameters:



29
30
31
32
33
34
# File 'lib/slim_lint/linter.rb', line 29

def run(document)
  @document = document
  @lints = []
  trigger_pattern_callbacks(document.sexp)
  @lints
end