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?!
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.
It really needs to be fixed!
I think this is a dupe of https://github.com/angular/angular-cli/issues/10013 but until investigation I'm not going to close this issue.
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.
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.
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?
@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.
@Springrbua Thanks a lot, at least I now know I can use it with 6.2.X... :-)
@Vaelor did you test this?
I wanted to use it in one of my projects, but it does not work (see #12480)
@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
Thanks @Vaelor.
Did you add the schematics inside the projects node or at root-level?
Are you using windows?
@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.
@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.
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._
Most helpful comment
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.