Skip to content

Commit 0715beb

Browse files
alan-agius4mgechev
authored andcommitted
feat(@schematics/angular): add lintFix to several other schematics
At the moment some schematics contain this options for instance the `guard`, `component` etc.. But some others don't such as `module` Fixes #12894 and Fixes #6272
1 parent b40dc77 commit 0715beb

File tree

8 files changed

+32
-1
lines changed

8 files changed

+32
-1
lines changed

packages/schematics/angular/application/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from '../utility/config';
3232
import { NodeDependencyType, addPackageJsonDependency } from '../utility/dependencies';
3333
import { latestVersions } from '../utility/latest-versions';
34+
import { applyLintFix } from '../utility/lint-fix';
3435
import { validateProjectName } from '../utility/validation';
3536
import {
3637
Builders,
@@ -372,6 +373,7 @@ export default function (options: ApplicationOptions): Rule {
372373
]), MergeStrategy.Overwrite),
373374
options.minimal ? noop() : schematic('e2e', e2eOptions),
374375
options.skipPackageJson ? noop() : addDependenciesToPackageJson(options),
376+
options.lintFix ? applyLintFix(sourceDir) : noop(),
375377
]);
376378
};
377379
}

packages/schematics/angular/application/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@
7878
"description": "Skip installing dependency packages.",
7979
"type": "boolean",
8080
"default": false
81+
},
82+
"lintFix": {
83+
"type": "boolean",
84+
"default": false,
85+
"description": "When true, applies lint fixes after generating the application."
8186
}
8287
},
8388
"required": [

packages/schematics/angular/class/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import {
1313
Tree,
1414
apply,
1515
branchAndMerge,
16+
chain,
1617
filter,
1718
mergeWith,
1819
move,
1920
noop,
2021
template,
2122
url,
2223
} from '@angular-devkit/schematics';
24+
import { applyLintFix } from '../utility/lint-fix';
2325
import { parseName } from '../utility/parse-name';
2426
import { buildDefaultPath, getProject } from '../utility/project';
2527
import { Schema as ClassOptions } from './schema';
@@ -54,6 +56,9 @@ export default function (options: ClassOptions): Rule {
5456
move(parsedPath.path),
5557
]);
5658

57-
return branchAndMerge(mergeWith(templateSource));
59+
return chain([
60+
branchAndMerge(mergeWith(templateSource)),
61+
options.lintFix ? applyLintFix(options.path) : noop(),
62+
]);
5863
};
5964
}

packages/schematics/angular/class/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
"type": "string",
4343
"description": "Adds a developer-defined type to the filename, in the format \"name.type.ts\".",
4444
"default": ""
45+
},
46+
"lintFix": {
47+
"type": "boolean",
48+
"default": false,
49+
"description": "When true, applies lint fixes after generating the class."
4550
}
4651
},
4752
"required": [

packages/schematics/angular/library/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from '../utility/config';
2828
import { NodeDependencyType, addPackageJsonDependency } from '../utility/dependencies';
2929
import { latestVersions } from '../utility/latest-versions';
30+
import { applyLintFix } from '../utility/lint-fix';
3031
import { validateProjectName } from '../utility/validation';
3132
import {
3233
Builders,
@@ -246,6 +247,7 @@ export default function (options: LibraryOptions): Rule {
246247
path: sourceDir,
247248
project: options.name,
248249
}),
250+
options.lintFix ? applyLintFix(sourceDir) : noop(),
249251
(_tree: Tree, context: SchematicContext) => {
250252
if (!options.skipPackageJson && !options.skipInstall) {
251253
context.addTask(new NodePackageInstallTask());

packages/schematics/angular/library/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
"type": "boolean",
4343
"default": false,
4444
"description": "When true, does not update \"tsconfig.json\" to add a path mapping for the new library. The path mapping is needed to use the library in an app, but can be disabled here to simplify development."
45+
},
46+
"lintFix": {
47+
"type": "boolean",
48+
"default": false,
49+
"description": "When true, applies lint fixes after generating the library."
4550
}
4651
},
4752
"required": []

packages/schematics/angular/module/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as ts from 'typescript';
2424
import { addImportToModule } from '../utility/ast-utils';
2525
import { InsertChange } from '../utility/change';
2626
import { buildRelativePath, findModuleFromOptions } from '../utility/find-module';
27+
import { applyLintFix } from '../utility/lint-fix';
2728
import { parseName } from '../utility/parse-name';
2829
import { buildDefaultPath, getProject } from '../utility/project';
2930
import { Schema as ModuleOptions } from './schema';
@@ -102,6 +103,7 @@ export default function (options: ModuleOptions): Rule {
102103
addDeclarationToNgModule(options),
103104
mergeWith(templateSource),
104105
])),
106+
options.lintFix ? applyLintFix(options.path) : noop(),
105107
]);
106108
};
107109
}

packages/schematics/angular/module/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"type": "string",
5454
"description": "The declaring NgModule.",
5555
"alias": "m"
56+
},
57+
"lintFix": {
58+
"type": "boolean",
59+
"default": false,
60+
"description": "When true, applies lint fixes after generating the module."
5661
}
5762
},
5863
"required": [

0 commit comments

Comments
 (0)