Class: HamlLint::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/haml_lint/report.rb

Overview

Contains information about all lints detected during a scan.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lints: [], files: [], fail_level: :warning, reporter: nil) ⇒ Report

Creates a report.

Parameters:

  • lints (Array<HamlLint::Lint>) (defaults to: [])

    lints that were found

  • files (Array<String>) (defaults to: [])

    files that were linted

  • fail_level (Symbol) (defaults to: :warning)

    the severity level to fail on

  • reporter (HamlLint::Reporter) (defaults to: nil)

    the reporter for the report



21
22
23
24
25
26
# File 'lib/haml_lint/report.rb', line 21

def initialize(lints: [], files: [], fail_level: :warning, reporter: nil)
  @lints = lints.sort_by { |l| [l.filename, l.line] }
  @files = files
  @fail_level = Severity.new(fail_level)
  @reporter = reporter
end

Instance Attribute Details

#fail_levelObject (readonly)

The level of lint to fail after detecting



10
11
12
# File 'lib/haml_lint/report.rb', line 10

def fail_level
  @fail_level
end

#filesObject (readonly)

List of files that were linted.



13
14
15
# File 'lib/haml_lint/report.rb', line 13

def files
  @files
end

#lintsObject

List of lints that were found.



7
8
9
# File 'lib/haml_lint/report.rb', line 7

def lints
  @lints
end

Instance Method Details

#add_lint(lint) ⇒ void

This method returns an undefined value.

Adds a lint to the report and notifies the reporter.

Parameters:



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

def add_lint(lint)
  lints << lint
  @reporter.added_lint(lint, self)
end

#displayvoid

This method returns an undefined value.

Displays the report via the configured reporter.



40
41
42
# File 'lib/haml_lint/report.rb', line 40

def display
  @reporter.display_report(self)
end

#failed?Boolean

Checks whether any lints were at or above the fail level

Returns:

  • (Boolean)


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

def failed?
  @lints.any? { |lint| lint.severity >= fail_level }
end

#finish_file(file, lints) ⇒ void

This method returns an undefined value.

Adds a file to the list of linted files and notifies the reporter.

Parameters:

  • file (String)

    the name of the file that was finished

  • lints (Array<HamlLint::Lint>)

    the lints for the finished file



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

def finish_file(file, lints)
  files << file
  @reporter.finished_file(file, lints)
end

#start(files) ⇒ void

This method returns an undefined value.

Notifies the reporter that the report has started.

Parameters:

  • files (Array<String>)

    the files to lint



65
66
67
# File 'lib/haml_lint/report.rb', line 65

def start(files)
  @reporter.start(files)
end