Skip to content

Commit

Permalink
feat(@schematics/angular): add lintFix to several other schematics
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alan-agius4 authored and mgechev committed Dec 13, 2018
1 parent b40dc77 commit 0715beb
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/schematics/angular/application/index.ts
Expand Up @@ -31,6 +31,7 @@ import {
} from '../utility/config';
import { NodeDependencyType, addPackageJsonDependency } from '../utility/dependencies';
import { latestVersions } from '../utility/latest-versions';
import { applyLintFix } from '../utility/lint-fix';
import { validateProjectName } from '../utility/validation';
import {
Builders,
Expand Down Expand Up @@ -372,6 +373,7 @@ export default function (options: ApplicationOptions): Rule {
]), MergeStrategy.Overwrite),
options.minimal ? noop() : schematic('e2e', e2eOptions),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(options),
options.lintFix ? applyLintFix(sourceDir) : noop(),
]);
};
}
5 changes: 5 additions & 0 deletions packages/schematics/angular/application/schema.json
Expand Up @@ -78,6 +78,11 @@
"description": "Skip installing dependency packages.",
"type": "boolean",
"default": false
},
"lintFix": {
"type": "boolean",
"default": false,
"description": "When true, applies lint fixes after generating the application."
}
},
"required": [
Expand Down
7 changes: 6 additions & 1 deletion packages/schematics/angular/class/index.ts
Expand Up @@ -13,13 +13,15 @@ import {
Tree,
apply,
branchAndMerge,
chain,
filter,
mergeWith,
move,
noop,
template,
url,
} from '@angular-devkit/schematics';
import { applyLintFix } from '../utility/lint-fix';
import { parseName } from '../utility/parse-name';
import { buildDefaultPath, getProject } from '../utility/project';
import { Schema as ClassOptions } from './schema';
Expand Down Expand Up @@ -54,6 +56,9 @@ export default function (options: ClassOptions): Rule {
move(parsedPath.path),
]);

return branchAndMerge(mergeWith(templateSource));
return chain([
branchAndMerge(mergeWith(templateSource)),
options.lintFix ? applyLintFix(options.path) : noop(),
]);
};
}
5 changes: 5 additions & 0 deletions packages/schematics/angular/class/schema.json
Expand Up @@ -42,6 +42,11 @@
"type": "string",
"description": "Adds a developer-defined type to the filename, in the format \"name.type.ts\".",
"default": ""
},
"lintFix": {
"type": "boolean",
"default": false,
"description": "When true, applies lint fixes after generating the class."
}
},
"required": [
Expand Down
2 changes: 2 additions & 0 deletions packages/schematics/angular/library/index.ts
Expand Up @@ -27,6 +27,7 @@ import {
} from '../utility/config';
import { NodeDependencyType, addPackageJsonDependency } from '../utility/dependencies';
import { latestVersions } from '../utility/latest-versions';
import { applyLintFix } from '../utility/lint-fix';
import { validateProjectName } from '../utility/validation';
import {
Builders,
Expand Down Expand Up @@ -246,6 +247,7 @@ export default function (options: LibraryOptions): Rule {
path: sourceDir,
project: options.name,
}),
options.lintFix ? applyLintFix(sourceDir) : noop(),
(_tree: Tree, context: SchematicContext) => {
if (!options.skipPackageJson && !options.skipInstall) {
context.addTask(new NodePackageInstallTask());
Expand Down
5 changes: 5 additions & 0 deletions packages/schematics/angular/library/schema.json
Expand Up @@ -42,6 +42,11 @@
"type": "boolean",
"default": false,
"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."
},
"lintFix": {
"type": "boolean",
"default": false,
"description": "When true, applies lint fixes after generating the library."
}
},
"required": []
Expand Down
2 changes: 2 additions & 0 deletions packages/schematics/angular/module/index.ts
Expand Up @@ -24,6 +24,7 @@ import * as ts from 'typescript';
import { addImportToModule } from '../utility/ast-utils';
import { InsertChange } from '../utility/change';
import { buildRelativePath, findModuleFromOptions } from '../utility/find-module';
import { applyLintFix } from '../utility/lint-fix';
import { parseName } from '../utility/parse-name';
import { buildDefaultPath, getProject } from '../utility/project';
import { Schema as ModuleOptions } from './schema';
Expand Down Expand Up @@ -102,6 +103,7 @@ export default function (options: ModuleOptions): Rule {
addDeclarationToNgModule(options),
mergeWith(templateSource),
])),
options.lintFix ? applyLintFix(options.path) : noop(),
]);
};
}
5 changes: 5 additions & 0 deletions packages/schematics/angular/module/schema.json
Expand Up @@ -53,6 +53,11 @@
"type": "string",
"description": "The declaring NgModule.",
"alias": "m"
},
"lintFix": {
"type": "boolean",
"default": false,
"description": "When true, applies lint fixes after generating the module."
}
},
"required": [
Expand Down

0 comments on commit 0715beb

Please sign in to comment.