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, GithubReporter, HashReporter, JsonReporter, OffenseCountReporter, 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:



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

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
37
38
39
40
41
42
# File 'lib/haml_lint/reporter.rb', line 34

def self.cli_name
  name
    .split('::')
    .last
    .sub(/Reporter$/, '')
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2')
    .gsub(/([a-z\d])([A-Z])/, '\1-\2')
    .downcase
end

.descendantsArray<Class>

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

Returns:

  • (Array<Class>)


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

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

.inherited(descendant) ⇒ Object

Executed when this class is subclassed.

Parameters:

  • descendant (Class)


70
71
72
# File 'lib/haml_lint/reporter.rb', line 70

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)


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

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