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:



39
40
41
# File 'lib/haml_lint/reporter.rb', line 39

def initialize(logger)
  @log = logger
end

Class Method Details

.availableArray<String>

The CLI names of all configured reporters.

Returns:

  • (Array<String>)


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

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)


25
26
27
# File 'lib/haml_lint/reporter.rb', line 25

def self.available?
  true
end

.cli_nameString

The name of the reporter as passed from the CLI.

Returns:

  • (String)


32
33
34
# File 'lib/haml_lint/reporter.rb', line 32

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>)


55
56
57
# File 'lib/haml_lint/reporter.rb', line 55

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

.inherited(descendant) ⇒ Object

Executed when this class is subclassed.

Parameters:

  • descendant (Class)


62
63
64
# File 'lib/haml_lint/reporter.rb', line 62

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)


46
47
48
49
# File 'lib/haml_lint/reporter.rb', line 46

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