angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Add automatic style fixing for `ng new` and all generators.

Open filipesilva opened this issue 9 years ago • 16 comments

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.

filipesilva avatar May 11 '17 11:05 filipesilva

Related https://github.com/angular/angular-cli/issues/5599, should probably be addressed in the same PR (but separate commit).

filipesilva avatar May 11 '17 11:05 filipesilva

Currently blocked waiting for [email protected] to be released.

filipesilva avatar May 16 '17 15:05 filipesilva

tslint v5.3.0 has just released

imcotton avatar May 23 '17 00:05 imcotton

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.

filipesilva avatar May 23 '17 10:05 filipesilva

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.

rsheptolut avatar Jul 16 '17 14:07 rsheptolut

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 .

danyg avatar Dec 17 '17 11:12 danyg

Tslint does not provide a fixer for the indent rule. See here for details: https://palantir.github.io/tslint/rules/

clydin avatar Dec 17 '17 13:12 clydin

@clydin , the docs say "hasFixer".. so... ?

tommck avatar Jan 15 '18 19:01 tommck

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/)

tommck avatar Jan 15 '18 19:01 tommck

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.

studds avatar Jan 16 '18 00:01 studds

maybe just have some custom post-processor that can be run on all files?

tommck avatar Jan 17 '18 18:01 tommck

ab fab

@studds 😂 after figuring out what this means to abbreviate

michahell avatar Feb 19 '18 13:02 michahell

@filipesilva Since CLI v6, --lintFix option looks disappeared. There is no way to fix generated code automatically. Was it removed on purpose?

lacolaco avatar May 18 '18 12:05 lacolaco

https://github.com/angular/angular-cli/issues/11034

tx8821 avatar May 27 '18 19:05 tx8821

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.

buchmiller avatar Jun 13 '18 17:06 buchmiller

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.