class HamlLint::Reporter::DisabledConfigReporter

Outputs a YAML configuration file based on existing violations.

def self.available?

Returns:
  • (false) -
def self.available?
  false
end

def config_file_contents

Returns:
  • (String) - a Yaml-formatted configuration file's contents
def config_file_contents
  output = []
  output << HEADING
  output << 'linters:' if linters_with_lints.any?
  linters_with_lints.sort.each do |linter, files|
    output << generate_config_for_linter(linter, files)
  end
  output.join("\n\n") + "\n"
end

def display_report(report)

Returns:
  • (void) -

Parameters:
  • report (HamlLint::Report) --
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

def finished_file(file, lints)

Returns:
  • (void) -

Parameters:
  • lints (Array) --
  • file (String) --
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

def generate_config_for_linter(linter, files)

Returns:
  • (String) - a Yaml-formatted configuration

Parameters:
  • files (Array) -- the files in which the linter is excluded
  • linter (String) -- the name of the linter to exclude
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

def initialize(log, limit: 15)

Parameters:
  • _log (HamlLint::Logger) --
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