Skip to content

LintFix config option disappeared in v6?! (ng generate produces invalid code!) #11034

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

Closed
tx8821 opened this issue May 27, 2018 · 14 comments · Fixed by #11648
Closed

LintFix config option disappeared in v6?! (ng generate produces invalid code!) #11034

tx8821 opened this issue May 27, 2018 · 14 comments · Fixed by #11648

Comments

@tx8821
Copy link

tx8821 commented May 27, 2018

Using Angular CLI v6.0.5. New Project

In pre-v6 projects, in ".angular-cli.json" under "defaults" section we had "lintFix": true setting, which ensured that after generating new component/service/whatever the linting fixes where performed automatically. Now in new "angular.json" (which replaces ".angular-cli.json") I can't find similar option. Which is a HUGE problem!

Suppose I have changed linter defaults to prefer "double quotes" for string (whoever said 'single quotes' should be default for TypeScript needs to be fired IMHO). Now every time I generate new component with ng g component MyNewComponent, it is created with all 'single quote' strings inside, instead of "double quotes"! And I have to manually fix them every time which is a nightmare! lintFix setting solved that in previous CLI versions but now, what is an alternative?!

@probert94
Copy link

I would also like to see this feature back in the CLI. At the moment I have to manually fix all generated files, as I am using a few different configurations then the default.

@ghost
Copy link

ghost commented May 29, 2018

It really needs to be fixed!

@hansl
Copy link
Contributor

hansl commented Jun 7, 2018

I think this is a dupe of #10013 but until investigation I'm not going to close this issue.

@kevinbosman
Copy link

I don't think this is a duplicate of #10013 - this issue is about no longer being able to set the lintFix option at all since 6.0. 10013 is about tslint type checking not working correctly in 1.7.3 with the lintFix option working correctly.

@probert94
Copy link

probert94 commented Jun 18, 2018

I just noticed, that the lintFix option isn't even mentioned in the Angular CLI 1.7.x wiki, but it is part of the Angular CLI 1.7.x schema file.

Also, in the new configuration, there is a fix option in the tslint-configuration, but it does not seem to be used for the ng generate commands.

hansl added a commit to hansl/angular-cli that referenced this issue Jul 24, 2018
@hansl hansl mentioned this issue Jul 24, 2018
@Vaelor
Copy link

Vaelor commented Sep 11, 2018

Is this released? Couldn't find anything in the patchnotes of the @angular/cli project. And is it defined the same as before? Where can I find a proper documentation for the angular.json file anyway? Do I have to read/understand the schema.json?

@probert94
Copy link

probert94 commented Sep 11, 2018

@Vaelor There does not seem to be a documentation for it.
Also the documentation for the angular.json as well as the linked schematic-files don't seem to contain the fix.
However, the lintFix-option is part of the schematics in the master and the 6.2.X branch.
In 6.1.X the lintFix-option seems to be missing.

@Vaelor
Copy link

Vaelor commented Sep 11, 2018

@Springrbua Thanks a lot, at least I now know I can use it with 6.2.X... :-)

@probert94
Copy link

@Vaelor did you test this?
I wanted to use it in one of my projects, but it does not work (see #12480)

@Vaelor
Copy link

Vaelor commented Oct 5, 2018

@Springrbua
Not sure if this is the correct way, but this helped in my case:

In the angular.json scroll to where the schematics section is defined (not sure if it exists by default!) and attach the lintFix option there for every schematic. Sadly, I couldn't find a place like defaults where I could place this.

"schematics": {
		"@schematics/angular:pipe": {
			"lintFix": true
		},
		"@schematics/angular:class": {
			"lintFix": true
		},
		"@schematics/angular:module": {
			"lintFix": true
		},
		"@schematics/angular:service": {
			"lintFix": true
		},
		"@schematics/angular:component": {
			"lintFix": true,
			"prefix": "app",
			"styleext": "css"
		},
		"@schematics/angular:directive": {
			"lintFix": true,
			"prefix": "app"
		}
	}

Now, running ng generate should show something like this:

$ ng g c test
CREATE src/app/test/test.component.css (0 bytes)
CREATE src/app/test/test.component.html (23 bytes)
CREATE src/app/test/test.component.spec.ts (614 bytes)
CREATE src/app/test/test.component.ts (260 bytes)
UPDATE src/app/app.module.ts (2554 bytes)
Warning: The 'deprecation' rule requires type information.
Warning: The 'no-use-before-declare' rule requires type information.
    Fixed 29 error(s) in src/app/test/test.component.spec.ts
    Fixed 7 error(s) in src/app/test/test.component.ts
    Fixed 1 error(s) in src/app/app.module.ts

@probert94
Copy link

Thanks @Vaelor.
Did you add the schematics inside the projects node or at root-level?
Are you using windows?

@Vaelor
Copy link

Vaelor commented Oct 6, 2018

@Springrbua read your other issue, it does sound like it may be windows related?
In my case, I use linux.
schematics is at root level in my config.
Sadly I couldn't get my project to run at all on windows (I am a dumb windows user, I receive some strange npm errors there...) to check if my config works there.

@probert94
Copy link

@Vaelor thanks for your reply. It really sounds like it is a windows related error, because I created a new project and it had the exact same project, while others can't reproduce it.

@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 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants