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