Class: HamlLint::Reporter Abstract

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/haml_lint/reporter.rb,
lib/haml_lint/reporter/hooks.rb,
lib/haml_lint/reporter/utils.rb

Overview

This class is abstract.

Abstract lint reporter. Subclass and override #display_report to implement a custom lint reporter.

Defined Under Namespace

Modules: Hooks, Utils Classes: CheckstyleReporter, DefaultReporter, DisabledConfigReporter, HashReporter, JsonReporter, ProgressReporter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hooks

#added_lint, #finished_file, #start

Constructor Details

#initialize(logger) ⇒ Reporter

Creates the reporter that will display the given report.

Parameters:



41
42
43
# File 'lib/haml_lint/reporter.rb', line 41

def initialize(logger)
  @log = logger
end

Class Method Details

.availableArray<String>

The CLI names of all configured reporters.

Returns:

  • (Array<String>)


16
17
18
19
20
21
22
# File 'lib/haml_lint/reporter.rb', line 16

def self.available
  descendants.flat_map do |reporter|
    available = reporter.available
    available.unshift(reporter) if reporter.available?
    available
  end
end

.available?Boolean

A flag for whether to show the reporter on the command line.

Returns:

  • (Boolean)


27
28
29
# File 'lib/haml_lint/reporter.rb', line 27

def self.available?
  true
end

.cli_nameString

The name of the reporter as passed from the CLI.

Returns:

  • (String)


34
35
36
# File 'lib/haml_lint/reporter.rb', line 34

def self.cli_name
  name.split('::').last.sub(/Reporter$/, '').downcase
end

.descendantsArray<Class>

Keep tracking all the descendants of this class for the list of available reporters.

Returns:

  • (Array<Class>)


57
58
59
# File 'lib/haml_lint/reporter.rb', line 57

def self.descendants
  @descendants ||= []
end

.inherited(descendant) ⇒ Object

Executed when this class is subclassed.

Parameters:

  • descendant (Class)


64
65
66
# File 'lib/haml_lint/reporter.rb', line 64

def self.inherited(descendant)
  descendants << descendant
end

Instance Method Details

#display_report(report) ⇒ Object

Implemented by subclasses to display lints from a HamlLint::Report.

Parameters:

Raises:

  • (NotImplementedError)


48
49
50
51
# File 'lib/haml_lint/reporter.rb', line 48

def display_report(report)
  raise NotImplementedError,
        "Implement `display_report` to display #{report}"
end