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

Add automatic style fixing for ng new and all generators. #6272

Closed
filipesilva opened this issue May 11, 2017 · 16 comments · Fixed by #12938
Closed

Add automatic style fixing for ng new and all generators. #6272

filipesilva opened this issue May 11, 2017 · 16 comments · Fixed by #12938
Labels
effort1: easy (hours) feature Issue that requests a new feature P5 The team acknowledges the request but does not plan to address it, it remains open for discussion

Comments

@filipesilva
Copy link
Contributor

filipesilva commented May 11, 2017

With palantir/tslint#2723 merged, TS Lint will allow both quotemark and indentation auto-fix. This, together with #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 filipesilva self-assigned this May 11, 2017
@filipesilva filipesilva added feature Issue that requests a new feature P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful effort1: easy (hours) labels May 11, 2017
@filipesilva
Copy link
Contributor Author

Related #5599, should probably be addressed in the same PR (but separate commit).

@filipesilva
Copy link
Contributor Author

Currently blocked waiting for tslint@5.3.0 to be released.

@imcotton
Copy link
Contributor

tslint v5.3.0 has just released

@filipesilva
Copy link
Contributor Author

#6415 is updating to the new tslint.

Meanwhile, #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... #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 filipesilva added P5 The team acknowledges the request but does not plan to address it, it remains open for discussion and removed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful labels Jul 3, 2017
@rsheptolut
Copy link

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.

@danyg
Copy link

danyg commented Dec 17, 2017

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 .

@clydin
Copy link
Member

clydin commented Dec 17, 2017

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

@tommck
Copy link

tommck commented Jan 15, 2018

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

@tommck
Copy link

tommck commented Jan 15, 2018

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

@studds
Copy link

studds commented Jan 16, 2018

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 #7379 which seems to be mostly about adding prettier during ng new, as opposed to style fixing.

@tommck
Copy link

tommck commented Jan 17, 2018

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

@michahell
Copy link

michahell commented Feb 19, 2018

ab fab

@studds 😂 after figuring out what this means to abbreviate

@lacolaco
Copy link
Contributor

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

@tx8821
Copy link

tx8821 commented May 27, 2018

#11034

@buchmiller
Copy link

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.

mgechev pushed a commit that referenced this issue Dec 13, 2018
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
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort1: easy (hours) feature Issue that requests a new feature P5 The team acknowledges the request but does not plan to address it, it remains open for discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.