forked from spryker-shop/suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtslint.js
58 lines (47 loc) · 1.7 KB
/
tslint.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
const path = require('path');
const { Linter, Configuration } = require('tslint');
const { globalSettings } = require('../settings');
const colors = require('colors');
const expectedFormatterArgument = 2;
/**
* List of output formatters for the tslint.
* https://palantir.github.io/tslint/formatters/
*/
const outputFormatter = () => {
const formatterName = process.argv.slice(expectedFormatterArgument)[0];
const defaultFormatter = 'codeFrame';
return formatterName ? formatterName : defaultFormatter;
};
const linterOptions = {
fix: false,
formatter: outputFormatter(),
};
const runTSLint = () => {
const program = Linter.createProgram('tsconfig.json', globalSettings.context);
const configurationFilename = path.join(globalSettings.context, 'tslint.json');
const linter = new Linter(linterOptions, program);
const files = Linter.getFileNames(program);
lintFiles(program, configurationFilename, linter, files);
};
const lintFiles = (program, configurationFilename, linter, files) => {
files.forEach(file => {
const fileContents = program.getSourceFile(file).getFullText();
const configuration = Configuration.findConfiguration(configurationFilename, file).results;
linter.lint(file, fileContents, configuration);
});
showLintOutput(linter);
};
const showLintOutput = linter => {
const lintingResult = linter.getResult();
console.log(
lintingResult.output,
`Errors count: ${colors.red.underline(lintingResult.errorCount)}\n`
);
exitProcess(lintingResult.errorCount);
};
const exitProcess = errorCount => {
if (errorCount > 0 && process.env.NODE_ENV !== 'development') {
process.exit(1);
}
};
runTSLint();