Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@schematics/angular): add lintFix to several other schematics #12938

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -51,6 +53,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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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