Class: Pipeline::ESLint

Inherits:
BaseTask show all
Includes:
Util
Defined in:
lib/pipeline/tasks/eslint.rb

Instance Attribute Summary

Attributes inherited from BaseTask

#appname, #description, #findings, #labels, #name, #stage, #trigger, #warnings

Instance Method Summary collapse

Methods included from Util

#fingerprint, #relative_path, #runsystem, #strip_archive_path

Methods inherited from BaseTask

#directories_with?, #report, #severity, #warn

Constructor Details

#initialize(trigger, tracker) ⇒ ESLint

Returns a new instance of ESLint.



10
11
12
13
14
15
16
# File 'lib/pipeline/tasks/eslint.rb', line 10

def initialize(trigger, tracker)
  super(trigger,tracker)
  @name = "ESLint/ScanJS"
  @description = "Source analysis for JavaScript"
  @stage = :code
  @labels << "code" << "javascript"
end

Instance Method Details

#analyzeObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pipeline/tasks/eslint.rb', line 25

def analyze
  # puts @result
  begin
    parsed = JSON.parse(@result)
    parsed.each do |result|
      findings = {}
      prints = []
      messages = []
      result['messages'].each do |msg|
        message = msg['message']
        findings[message] = {} if findings[message].nil?
        findings[message][:detail] = msg['ruleId']
        if messages.include?(message)
          findings[message][:source] = "#{findings[message][:source]},#{msg['line']}" unless findings[message][:source].include?(",#{msg['line']}")
        else
          findings[message][:source] = "#{result['filePath']} Line: #{msg['line']}"
          messages << message
        end
        findings[message][:severity] = severity(msg['severity'].to_s)
      end
      findings.each do |key, value|
        print = fingerprint("#{key}#{value[:detail]}#{value[:source]}#{value[:sev]}")
        unless prints.include?(print)
          prints << print
          report key, value[:detail], value[:source], value[:severity], print
        end
      end
    end
  rescue Exception => e
    Pipeline.warn e.message
    Pipeline.warn e.backtrace
  end
end

#runObject



18
19
20
21
22
23
# File 'lib/pipeline/tasks/eslint.rb', line 18

def run
  rootpath = @trigger.path
  currentpath = File.expand_path File.dirname(__FILE__)
  Pipeline.debug "ESLint Config Path: #{currentpath}"
  @result = `eslint -c #{currentpath}/scanjs-eslintrc --no-color --quiet --format json #{rootpath}`
end

#supported?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
# File 'lib/pipeline/tasks/eslint.rb', line 59

def supported?
  supported=runsystem(true, "eslint", "-c", "~/.scanjs-eslintrc")
  if supported =~ /command not found/
    Pipeline.notify "Install eslint and the scanjs .eslintrc"
    return false
  else
    return true
  end
end