UNPKG

1.59 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.applyLintFix = void 0;
4/**
5 * @license
6 * Copyright Google Inc. All Rights Reserved.
7 *
8 * Use of this source code is governed by an MIT-style license that can be
9 * found in the LICENSE file at https://angular.io/license
10 */
11const schematics_1 = require("@angular-devkit/schematics");
12const tasks_1 = require("@angular-devkit/schematics/tasks");
13function applyLintFix(path = '/') {
14 return (tree, context) => {
15 // Find the closest tslint.json or tslint.yaml
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 // Only include files that have been touched.
27 const files = tree.actions.reduce((acc, action) => {
28 const path = action.path.substr(1); // Remove the starting '/'.
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}
41exports.applyLintFix = applyLintFix;