class HamlLint::Reporter::DisabledConfigReporter
Outputs a YAML configuration file based on existing violations.
Constants
- HEADING
Attributes
Number of offenses to allow before simply disabling the linter
@return [Integer] file exclude limit
A hash of linters with the files that have that type of lint.
@return [Hash<String, Integer] a Hash with linter name keys and lint
count values
A hash of linters with the files that have that type of lint.
@return [Hash<String, Array<String>>] a Hash with linter name keys and file
name list values
Public Class Methods
Disables this reporter on the CLI
since it doesn’t output anything.
@return [false]
# File lib/haml_lint/reporter/disabled_config_reporter.rb, line 21 def self.available? false end
Create the reporter that will display the report and write the config.
@param _log [HamlLint::Logger]
HamlLint::Reporter::new
# 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
Public Instance Methods
Prints the standard progress reporter output and writes the new config file.
@param report [HamlLint::Report] @return [void]
HamlLint::Reporter::ProgressReporter#display_report
# 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
Prints the standard progress report marks and tracks files with lint.
@param file [String] @param lints [Array<HamlLint::Lint>] @return [void]
HamlLint::Reporter::ProgressReporter#finished_file
# 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
Private Instance Methods
The contents of the generated configuration file based on captured lint.
@return [String] a Yaml-formatted configuration file’s contents
# File lib/haml_lint/reporter/disabled_config_reporter.rb, line 87 def config_file_contents output = [] output << HEADING output << 'linters:' if linters_with_lints.any? linters_with_lints.each do |linter, files| output << generate_config_for_linter(linter, files) end output.join("\n\n") end
Constructs the configuration for excluding a linter in some files.
@param linter [String] the name of the linter to exclude @param files [Array<String>] the files in which the linter is excluded @return [String] a Yaml-formatted configuration
# File lib/haml_lint/reporter/disabled_config_reporter.rb, line 102 def generate_config_for_linter(linter, files) [].tap do |output| output << " # Offense count: #{linters_lint_count[linter]}" output << " #{linter}:" # disable the linter when there are many files with offenses. # exclude the affected files otherwise. if files.count > exclude_limit output << ' enabled: false' else output << ' exclude:' files.each do |filename| output << %{ - "#{filename}"} end end end.join("\n") end