Class: Maximus::Lint

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/maximus/lint.rb

Overview

Parent class for all lints (inherited by children)

Since:

  • 0.1.0

Direct Known Subclasses

Brakeman, Jshint, Railsbp, Rubocop, Scsslint

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#check_default_config_path, #edit_yaml, #file_count, #file_list, #is_rails?, #lines_added_to_range, #node_module_exists, #path_exists?, #prompt, #reporter_path, #root_dir, #truthy?

Constructor Details

#initialize(opts = {}) ⇒ void

Perform a lint of relevant code

All defined lints require a “result” method Inherits settings from Config#initialize

Examples:

the result method in the child class

def result
  @task = __method__.to_s
  @path ||= 'path/or/**/glob/to/files''
  lint_data = JSON.parse(`some-command-line-linter`)
  @output[:files_inspected] ||= files_inspected(extension, delimiter, base_path_replacement)
  refine data_from_output
end

Parameters:

  • opts (Hash) (defaults to: {})

    ({}) options passed directly to the lint

Options Hash (opts):

  • :git_files (Hash)

    filename: file location @see GitControl#lints_and_stats

  • :file_paths (Array, String)

    lint only specific files or directories Accepts globs too which is used to define paths from the URL

  • :config (Config object)

    custom Maximus::Config object

See Also:

Since:

  • 0.1.0



36
37
38
39
40
41
42
43
44
45
# File 'lib/maximus/lint.rb', line 36

def initialize(opts = {})

  # Only run the config once
  @config = opts[:config] || Maximus::Config.new(opts)
  @settings = @config.settings

  @git_files = opts[:git_files]
  @path = opts[:file_paths] || @settings[:file_paths]
  @output = {}
end

Instance Attribute Details

#outputObject

Since:

  • 0.1.0



9
10
11
# File 'lib/maximus/lint.rb', line 9

def output
  @output
end

Instance Method Details

#refine(data) ⇒ Hash

Convert raw data into warnings, errors, conventions or refactors. Use this wisely.

Parameters:

  • data (Hash)

    unfiltered lint data

Returns:

  • (Hash)

    refined lint data and all the other bells and whistles

Since:

  • 0.1.0



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/maximus/lint.rb', line 50

def refine(data)

  # Prevent abortive empty JSON.parse error
  data = '{}' if data.blank?
  return puts "Error from #{@task}: #{data}" if data.is_a?(String) && data.include?('No such')

  data = data.is_a?(String) ? JSON.parse(data) : data

  @output[:relevant_lints] = relevant_lints( data, @git_files ) unless @git_files.blank?
  unless @settings[:commit].blank?
    data = @output[:relevant_lints]
  end

  evaluate_severities(data)

  lint_count = (@output[:lint_errors].length + @output[:lint_warnings].length + @output[:lint_conventions].length + @output[:lint_refactors].length)

  puts lint_summarize

  if @config.is_dev?
    puts lint_dev_format(data) unless data.blank?
    lint_ceiling lint_count
  else
    # Because this should be returned in the format it was received
    @output[:raw_data] = data.to_json
  end
  @output
end