Class: HamlLint::Reporter::DisabledConfigReporter

Inherits:
ProgressReporter show all
Defined in:
lib/haml_lint/reporter/disabled_config_reporter.rb

Overview

Outputs a YAML configuration file based on existing violations.

Constant Summary collapse

DEFAULT_EXCLUDE_LIMIT =
15
HEADING_TEMPLATE =
['# This configuration was generated by',
 '# `%<command>s`',
 '# on %<timestamp>s using Haml-Lint version %<version>s.',
 '# The point is for the user to remove these configuration records',
 '# one by one as the lints are removed from the code base.',
 '# Note that changes in the inspected code, or installation of new',
 '# versions of Haml-Lint, may require this file to be generated again.']
.join("\n")

Constants inherited from ProgressReporter

ProgressReporter::DOT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ProgressReporter

#start

Methods included from Utils

#pluralize, #print_lint, #print_location, #print_message, #print_summary, #print_summary_corrected_lints, #print_summary_files, #print_summary_lints, #print_type

Methods inherited from HamlLint::Reporter

available, cli_name, descendants, inherited

Methods included from Hooks

#added_lint, #start

Constructor Details

#initialize(log, limit: DEFAULT_EXCLUDE_LIMIT, options: {}) ⇒ DisabledConfigReporter

Create the reporter that will display the report and write the config.

Parameters:



30
31
32
33
34
35
36
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 30

def initialize(log, limit: DEFAULT_EXCLUDE_LIMIT, options: {})
  super(log)
  @linters_with_lints = Hash.new { |hash, key| hash[key] = [] }
  @linters_lint_count = Hash.new(0)
  @exclude_limit = limit
  @options = options
end

Instance Attribute Details

#exclude_limitInteger (readonly)

Number of offenses to allow before simply disabling the linter

Returns:

  • (Integer)

    file exclude limit



53
54
55
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 53

def exclude_limit
  @exclude_limit
end

#linters_lint_countHash<String, Integer] a Hash with linter name keys and lint count values (readonly)

A hash of linters with the files that have that type of lint.

Returns:

  • (Hash<String, Integer] a Hash with linter name keys and lint count values)

    Hash<String, Integer] a Hash with linter name keys and lint count values



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

def linters_lint_count
  @linters_lint_count
end

#linters_with_lintsHash<String, Array<String>> (readonly)

A hash of linters with the files that have that type of lint.

Returns:

  • (Hash<String, Array<String>>)

    a Hash with linter name keys and file name list values



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

def linters_with_lints
  @linters_with_lints
end

Class Method Details

.available?false

Disables this reporter on the CLI since it doesn’t output anything.

Returns:

  • (false)


23
24
25
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 23

def self.available?
  false
end

Instance Method Details

#display_report(report) ⇒ void

This method returns an undefined value.

Prints the standard progress reporter output and writes the new config file.

Parameters:



59
60
61
62
63
64
65
66
67
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 59

def display_report(report)
  super

  File.write(ConfigurationLoader::AUTO_GENERATED_FILE, config_file_contents)
  log.log "Created #{ConfigurationLoader::AUTO_GENERATED_FILE}."
  log.log "Run `haml-lint --config #{ConfigurationLoader::AUTO_GENERATED_FILE}`" \
    ", or add `inherits_from: #{ConfigurationLoader::AUTO_GENERATED_FILE}` in a " \
    '.haml-lint.yml file.'
end

#finished_file(file, lints) ⇒ void

This method returns an undefined value.

Prints the standard progress report marks and tracks files with lint.

Parameters:



74
75
76
77
78
79
80
81
82
83
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 74

def finished_file(file, lints)
  super

  if lints.any?
    lints.each do |lint|
      linters_with_lints[lint.linter.name] |= [lint.filename]
      linters_lint_count[lint.linter.name] += 1
    end
  end
end