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

    the reporter for the report



19
20
21
22
23
24
# File 'lib/haml_lint/report.rb', line 19

def initialize(lints = [], files = [], fail_level = :warning, reporter:)
  @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



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

def fail_level
  @fail_level
end

#filesObject (readonly)

List of files that were linted.



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

def files
  @files
end

#lintsObject

List of lints that were found.



5
6
7
# File 'lib/haml_lint/report.rb', line 5

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:



30
31
32
33
# File 'lib/haml_lint/report.rb', line 30

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

#displayvoid

This method returns an undefined value.

Displays the report via the configured reporter.



38
39
40
# File 'lib/haml_lint/report.rb', line 38

def display
  @reporter.display_report(self)
end

#failed?Boolean

Checks whether any lints were over the fail level

Returns:

  • (Boolean)


45
46
47
# File 'lib/haml_lint/report.rb', line 45

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



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

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



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

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