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

HEADING =
['# This configuration was generated by',
 '# `haml-lint --auto-gen-config`',
 "# on #{Time.now} using Haml-Lint version #{HamlLint::VERSION}.",
 '# 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: 15) ⇒ DisabledConfigReporter

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

Parameters:



28
29
30
31
32
33
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 28

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

Instance Attribute Details

#exclude_limitInteger (readonly)

Number of offenses to allow before simply disabling the linter

Returns:

  • (Integer)

    file exclude limit



50
51
52
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 50

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



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

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



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

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)


21
22
23
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 21

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:



56
57
58
59
60
61
62
63
64
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 56

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:



71
72
73
74
75
76
77
78
79
80
# File 'lib/haml_lint/reporter/disabled_config_reporter.rb', line 71

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