Class: Pipeline::ESLint
- 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
- #analyze ⇒ Object
-
#initialize(trigger, tracker) ⇒ ESLint
constructor
A new instance of ESLint.
- #run ⇒ Object
- #supported? ⇒ Boolean
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
#analyze ⇒ Object
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 = [] = [] result['messages'].each do |msg| = msg['message'] findings[] = {} if findings[].nil? findings[][:detail] = msg['ruleId'] if .include?() findings[][:source] = "#{findings[][:source]},#{msg['line']}" unless findings[][:source].include?(",#{msg['line']}") else findings[][:source] = "#{result['filePath']} Line: #{msg['line']}" << end findings[][: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. Pipeline.warn e.backtrace end end |
#run ⇒ Object
18 19 20 21 22 23 |
# File 'lib/pipeline/tasks/eslint.rb', line 18 def run rootpath = @trigger.path currentpath = File. File.dirname(__FILE__) Pipeline.debug "ESLint Config Path: #{currentpath}" @result = `eslint -c #{currentpath}/scanjs-eslintrc --no-color --quiet --format json #{rootpath}` end |
#supported? ⇒ 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 |