Class: Linters::LinterSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/linters/linter_settings.rb

Constant Summary collapse

DEFAULT_SETTINGS =
{
  brakeman: {
    default_command: 'brakeman --quiet --skip-libs -f json',
    parse_output: ->(output) { JSON.parse(output)['scan_info']['security_warnings'] }
  },
  bundle_audit: {
    default_command: 'bundle-audit update > /dev/null 2>&1 && bundle-audit',
    parse_output: ->(output) { output.scan(/Name:/).count }
  },
  fasterer: {
    default_command: 'fasterer',
    parse_output: lambda { |output, lines_per_warning = 3|
      output.split("\n").length / lines_per_warning
    }
  },
  reek: {
    default_command: 'reek --format json *',
    parse_output: ->(output) { JSON.parse(output).size }
  },
  rubocop: {
    default_command: 'rubocop --parallel --format json',
    parse_output: ->(output) { JSON.parse(output)['summary']['offense_count'] }
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(name, custom_settings = {}) ⇒ LinterSettings

Returns a new instance of LinterSettings.



31
32
33
34
35
# File 'lib/linters/linter_settings.rb', line 31

def initialize(name, custom_settings = {})
  @name = name
  @settings = DEFAULT_SETTINGS.fetch(name) { {} }
  @settings = @settings.merge(load_settings(name)).merge(custom_settings)
end

Instance Method Details

#commandObject



45
46
47
# File 'lib/linters/linter_settings.rb', line 45

def command
  settings.fetch(:command) { settings.fetch(:default_command) }
end

#nameObject



37
38
39
# File 'lib/linters/linter_settings.rb', line 37

def name
  settings.fetch(:name) { @name }
end

#parse_outputObject



49
50
51
# File 'lib/linters/linter_settings.rb', line 49

def parse_output
  settings[:parse_output]
end

#warnings_numberObject



41
42
43
# File 'lib/linters/linter_settings.rb', line 41

def warnings_number
  ENV.fetch("LINTERS_#{ name.upcase }_NUMBER_WARNINGS", settings.fetch(:warnings_number) { 0 })
end