-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (66 loc) · 1.93 KB
/
index.js
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
"use strict";
const sidekickAnalyser = require("@sidekick/analyser-common");
const fs = require('fs');
const path = require('path');
const stripJsonComments = require("strip-json-comments");
const Linter = require('tslint');
const configFileName = 'tslint.json';
const annotationDefaults = {analyserName: 'sidekick-tslint'};
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 || {})[configFileName];
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 = {};
}
var results = run(setup.content, config, setup.filePath);
console.log(JSON.stringify({ meta: results }));
});
}
module.exports._testRun = run;
function run(content, configObj, fileName) {
try {
var options = {
formatter: "json",
configuration: configObj
};
var tslint = new Linter(fileName, content, options);
var errors = tslint.lint();
return errors.failures.map(format);
} catch (err) {
console.error("failed to analyse");
console.log({ error: err });
process.exit(1);
}
}
function format(error) {
return {
analyser: annotationDefaults.analyserName,
location: {
startLine: error.startPosition.lineAndCharacter.line,
endLine: error.endPosition.lineAndCharacter.line,
startCharacter: error.startPosition.lineAndCharacter.character,
endCharacter: error.endPosition.lineAndCharacter.character,
},
message: error.failure,
kind: error.ruleName,
};
}