UNPKG

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