1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const schematics_1 = require("@angular-devkit/schematics");
|
11 | const tasks_1 = require("@angular-devkit/schematics/tasks");
|
12 | function applyLintFix(path = '/') {
|
13 | return (tree, context) => {
|
14 |
|
15 | let dir = tree.getDir(path.substr(0, path.lastIndexOf('/')));
|
16 | do {
|
17 | if (dir.subfiles.some(f => f === 'tslint.json' || f === 'tslint.yaml')) {
|
18 | break;
|
19 | }
|
20 | dir = dir.parent;
|
21 | } while (dir !== null);
|
22 | if (dir === null) {
|
23 | throw new schematics_1.SchematicsException('Asked to run lint fixes, but could not find a tslint.json or tslint.yaml config file.');
|
24 | }
|
25 |
|
26 | const files = tree.actions.reduce((acc, action) => {
|
27 | const path = action.path.substr(1);
|
28 | if (path.endsWith('.ts') && dir && action.path.startsWith(dir.path)) {
|
29 | acc.add(path);
|
30 | }
|
31 | return acc;
|
32 | }, new Set());
|
33 | context.addTask(new tasks_1.TslintFixTask({
|
34 | ignoreErrors: true,
|
35 | tsConfigPath: 'tsconfig.json',
|
36 | files: [...files],
|
37 | }));
|
38 | };
|
39 | }
|
40 | exports.applyLintFix = applyLintFix;
|