forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlint.ts
61 lines (49 loc) · 1.94 KB
/
lint.ts
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
const Task = require('../ember-cli/lib/models/task');
import * as chalk from 'chalk';
import * as path from 'path';
import { requireDependency } from '../utilities/require-project-module';
import { CliConfig } from '../models/config';
import { LintCommandOptions } from '../commands/lint';
import { oneLine } from 'common-tags';
export default Task.extend({
run: function (commandOptions: LintCommandOptions) {
const ui = this.ui;
const projectRoot = this.project.root;
return new Promise(function (resolve, reject) {
const tslint = requireDependency(projectRoot, 'tslint');
const Linter = tslint.Linter;
const Configuration = tslint.Configuration;
const lintConfigs = CliConfig.fromProject().config.lint || [];
if (lintConfigs.length === 0) {
ui.writeLine(chalk.yellow(oneLine`
No lint config(s) found.
If this is not intended, run "ng update".
`));
return resolve(0);
}
let errors = 0;
lintConfigs.forEach((config) => {
const program = Linter.createProgram(config.project);
const files: string[] = Linter.getFileNames(program);
const linter = new Linter({
fix: commandOptions.fix,
formatter: commandOptions.format
}, program);
files.forEach((file) => {
const fileContents = program.getSourceFile(file).getFullText();
const configLoad = Configuration.findConfiguration(config.tslintConfig, file);
linter.lint(file, fileContents, configLoad.results);
});
const result = linter.getResult();
errors += result.failureCount;
ui.writeLine(result.output.trim().concat('\n'));
});
if (errors > 0) {
ui.writeLine(chalk.red('Lint errors found in the listed files.'));
return commandOptions.force ? resolve(0) : resolve(2);
}
ui.writeLine(chalk.green('All files pass linting.'));
return resolve(0);
});
}
});