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

Lost ability to auto fix linting errors #10656

Closed
samherrmann opened this issue May 4, 2018 · 9 comments
Closed

Lost ability to auto fix linting errors #10656

samherrmann opened this issue May 4, 2018 · 9 comments

Comments

@samherrmann
Copy link

Versions

Angular CLI: 6.0.0
Node: 8.11.1
OS: linux x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

Repro steps

Run the following command in a Angular v6 project:

ng lint --fix

Observed behavior

Terminal output:

Architect commands with multiple targets cannot specify overrides.

Desired behavior

As a developer I would like to use the fix flag to lint my code on the development machine. I am aware that I am able to add the fix option in angular.json per Angular workspace documentation and @angular-devkit/build-angular:tslint. Doing so will cause the CI machine to also "auto fix" linting errors. The desired functionality is to allow developers to easily auto fix linting errors while the CI machine should simply fail upon encountering linting errors.

@tsvetan-ganev
Copy link

I have exactly the same issue. I have two npm scripts:

"lint": "ng lint",
"lint-fix": "ng lint --fix",

lint is used in a CI script, while lint-fix is used as a Git pre-commit hook.

@isaackwan
Copy link

I think per this SO solution we need to specify the 'library' first, before any 'overrides', i.e. --fix. So for my project it's either web2 or web2-e2e. I was able to fix my source file with:

$ ng lint web2 --fix
Fixed 7 error(s) in /home/isaac/Development/csci4140/web2/src/app/components/bill-new/bill-new.component.ts
<...>

All files pass linting.

@samherrmann
Copy link
Author

samherrmann commented May 6, 2018

Awesome! :) I guess the documentation needs an update then. The following is what I have in my scripts now:

"lint": "ng lint project-foo && ng lint project-foo-e2e",
"lint-fix":  "ng lint project-foo --fix && ng lint project-foo-e2e --fix",

@kvincent3
Copy link

This works for me :
"lint" : "ng run <your_project>:lint" in the package.json

And then in your angular.json in the lint section, do the following :
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
....
"fix": true // Use this line
}

Hope it will help

@samherrmann
Copy link
Author

@kvincent3 the problem with using the fix option in angular.json is that your CI pipeline will now use that option as well when you have it check for linting errors. The fix option is in my view only for the developers before they Git-commit their work.

@kevincaradant
Copy link

Hi

I think, I have the same issue as you

I tried this code:

"lint:check": "ng run paul:lint --type-check",
"lint:fix": "yarn-or-npm run lint:check -- --fix",

But this is the output:
(I guess the linter try to lint the node_modules folder ?)

The 'curly' rule threw an error in 'C:/Users/AAA/Documents/projets/paul/paul-cs/src/app/shared/helper
TypeError: Cannot read property 'pos' of undefined

The 'no-string-throw' rule threw an error in 'C:/Users/AAA/Documents/projets/paul/paul-cs/src/app/sha
TypeError: Cannot read property 'kind' of undefined

The 'no-arg' rule threw an error in 'C:/Users/AAA/Documents/projets/paul/paul-cs/src/app/shared/state         
TypeError: Cannot read property 'text' of undefined                                                               
                                                                                                                 
<--- Last few GCs --->                                                                                            
                                                                                                                  
[12280:0000000000458B60]    14500 ms: Mark-sweep 705.1 (754.5) -> 705.0 (754.5) MB, 362.5 / 0.0 ms  alloc         
[12280:0000000000458B60]    14945 ms: Mark-sweep 705.0 (754.5) -> 704.9 (714.5) MB, 444.7 / 0.0 ms  last          
[12280:0000000000458B60]    15333 ms: Mark-sweep 704.9 (714.5) -> 704.9 (714.5) MB, 388.1 / 0.0 ms  last          
                                                                                                                
<--- JS stacktrace --->                                                                                                                                                                                                
==== JS stack trace =========================================                                                                                                                                                              
Security context: 000002DDA35257C1 <JSObject>                                                                     
    1: _loop_1(aka _loop_1) [C:\Users\AAA\Documents\projets\paul\paul-cs\node_modules\tslint\lib\rule         
 <undefined>,identifier=000000F7F0DEE979 <IdentifierObject map = 000002EDAEEC6C49>)                               
    2: /* anonymous */(aka /* anonymous */) [C:\Users\AAA\Documents\projets\paul\paul-cs\node_modules         
                                                                                                                  
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory                                
 1: node_module_register                                                                                          
 2: v8::internal::FatalProcessOutOfMemory                                                                         
 3: v8::internal::FatalProcessOutOfMemory                                                                         
 4: v8::internal::Factory::NewUninitializedFixedArray                                                             
 5: v8::internal::WasmDebugInfo::SetupForTesting                                                                  
 6: v8::internal::interpreter::BytecodeArrayRandomIterator::UpdateOffsetFromIndex                                 
 7: 000000BFF98843C1                                                                                              
error Command failed with exit code 3.                                                                            

antonnikprelaj pushed a commit to antonnikprelaj/grand-material that referenced this issue Jun 4, 2018
mnahkies added a commit to mnahkies/angular-cli that referenced this issue Oct 21, 2018
When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by making a shallow clone of the array.
This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes angular#10657, angular#10656, angular#11005
mnahkies added a commit to mnahkies/angular-cli that referenced this issue Nov 20, 2018
When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by not mutating the array.

This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes angular#10657, angular#10656, angular#11005
alexeagle pushed a commit that referenced this issue Dec 6, 2018
When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by not mutating the array.

This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes #10657, #10656, #11005
alexeagle pushed a commit that referenced this issue Dec 6, 2018
When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by not mutating the array.

This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes #10657, #10656, #11005
@alan-agius4
Copy link
Collaborator

Closing via
7d88182

@winni4eva
Copy link

ng lint is set to false by default
ng lint --fix=true
worked for me

@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.
Projects
None yet
Development

No branches or pull requests

9 participants