-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (71 loc) · 2.03 KB
/
index.js
File metadata and controls
83 lines (71 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"use strict";
const sidekickAnalyser = require("@sidekick/analyser-common");
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const linter = require('standard');
const stripJsonComments = require("strip-json-comments");
const annotationDefaults = {analyserName: 'sidekick-standard'};
const LOG_FILE = path.join(__dirname, '/debug.log');
//log to file as any stdout will be reported to the analyser runner
function logger(message) {
fs.appendFile(LOG_FILE, message + '\n');
}
if(require.main === module) {
execute();
}
module.exports = exports = execute;
function execute() {
sidekickAnalyser(function(setup) {
var config;
var conf = setup.configFiles || {};
if(conf) {
try {
config = JSON.parse(stripJsonComments(conf));
} catch(e) {
// FIXME need some way of signalling
console.error("can't parse config");
console.error(e);
}
}
if(!config) {
config = {};
}
run(setup.content)
.then((results) => {
console.log(JSON.stringify({ meta: results }));
}, (err) => {
process.exit(1);
})
});
}
module.exports._testRun = run;
function run(content) {
return new Promise(function(resolve, reject){
linter.lintText(content, {}, function(err, result){
if(err){
console.error("failed to analyse");
console.log({ error: err });
reject(err);
}
const formattedResults = result.results.map(format);
resolve(formattedResults[0]); //we passed single file contents, so all errors are per-file
});
});
}
function format(error) {
//iterate over error.messages (multiple issues per file)
return _.map(error.messages, function(error) {
return {
analyser: annotationDefaults.analyserName,
location: {
startLine: error.line - 1, //standard is 1 based :-|
endLine: error.line -1,
startCharacter: error.column,
endCharacter: error.column,
},
message: error.message,
kind: error.ruleId,
};
});
}