Add automatic style fixing for `ng new` and all generators.
With https://github.com/palantir/tslint/pull/2723 merged, TS Lint will allow both quotemark and indentation auto-fix. This, together with https://github.com/angular/angular-cli/pull/6213, allows generators to automatically fix such style issues in generated files.
A flag to always auto-fix should be added to .angular-cli.json to always fix on generators:
"defaults": {
"lintFix": true,
"styleExt": "css",
"component": {}
}
To allow this functionality for new projects, the global .angular-cli.json needs to be include some style information that will be used to override tstlint and .editorconfig settings, and linting must run post install.
Related https://github.com/angular/angular-cli/issues/5599, should probably be addressed in the same PR (but separate commit).
Currently blocked waiting for [email protected] to be released.
tslint v5.3.0 has just released
https://github.com/angular/angular-cli/pull/6415 is updating to the new tslint.
Meanwhile, https://github.com/angular/angular-cli/pull/6213 already added lintFix to the CLI json file. It can be set on a project with ng set defaults.lintFix true.
I'm not as confident on how we should automatically do it for new projects though... https://github.com/angular/angular-cli/issues/3966 requests trailing-comma as well, so it might be a slippery slope to just add some lint properties to the CLI config.
Perhaps a path to a .tslint could be provided instead, and we copy it over for new projects, then run ng lint --fix.
Doesn't do it for me when I want to specify 4 spaces per indentation level, instead of the 2 spaces generated by Angular CLI. But I guess it's a bug in tslint.
does this work at all? I cannot make it work, using latest angular-cli
Angular CLI: 1.6.1
Node: 6.11.3
OS: win32 x64
Angular: 5.1.1
with
"tslint": "~5.7.0",
"typescript": "~2.4.2"
With indent setting
"indent": [true, "tabs"],
and the feature lintFix to true
I've tried to also use the command ng lint --fix and does nothing, and also tried node_modules/tslint/bin/tslint --fix --project .
Tslint does not provide a fixer for the indent rule. See here for details: https://palantir.github.io/tslint/rules/
@clydin , the docs say "hasFixer".. so... ?
oh... but "NOTE: auto-fixing will only convert invalid indent whitespace to the desired type, it will not fix invalid whitespace sizes."
(from https://palantir.github.io/tslint/rules/indent/)
Not sure if this is the place for this, but I think it would be ab fab if before running lint --fix on the altered files, prettier was also run (if installed / configured). See also https://github.com/angular/angular-cli/issues/7379 which seems to be mostly about adding prettier during ng new, as opposed to style fixing.
maybe just have some custom post-processor that can be run on all files?
ab fab
@studds 😂 after figuring out what this means to abbreviate
@filipesilva Since CLI v6, --lintFix option looks disappeared. There is no way to fix generated code automatically. Was it removed on purpose?
https://github.com/angular/angular-cli/issues/11034
The following should help those using tab indentation.
Angular cli code generation currently defaults to 2 space indentation. The indent setting in tslint.json needs to be set to 2 spaces to pick up the indentation in the generated angular cli files.
// tslint.json
"indent": [
true,
"tabs",
2
]
//.angular-cli.json
"defaults": {
"lintFix": true
}
The part that I needed from the tslint rules page was
Indentation size is required for auto-fixing, but not for rule checking.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.