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

#discover_path, #edit_yaml, #file_count, #file_list, #is_middleman?, #is_rails?, #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



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

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



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

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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/maximus/lint.rb', line 51

def refine(data)
  @task ||= ''

  data = parse_data(data)
  return puts data if data.is_a?(String)

  evaluate_severities(data)

  puts summarize

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