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

Auto Fix on Save does not fix unused disable directives unless there are other lint problems #1585

Closed
shawnmcknight opened this issue Jan 20, 2023 · 3 comments · Fixed by #1588
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@shawnmcknight
Copy link

In my eslint config, I've got the following activated:

reportUnusedDisableDirectives: true,

This causes eslint to emit a warning for unused disable directives and it properly shows as a warning in vscode:
image

In my vscode settings I've got code actions on save enabled:

"editor.codeActionsOnSave": {
  "source.fixAll": true
},

However, upon save, this warning is not autofixed. Additionally, there is no "quick fix" shown in vscode as there would be for other fixable errors.

This warning is autofixable at command line by eslint using the --fix flag.

I have found that if there are other errors in the file then upon save both the other error as well as the unused directive will be autofixed. Additionally, if I choose the quick fix "Fix all auto-fixable problems" for the other error, it will automatically fix the unused directive. It appears that automatic fixing will only not occur if this is the only problem in the file.

It's possible I'm missing a configuration somewhere that would allow this to be fixed and if that is the case would appreciate guidance on how to configure it. If that is not the case then please consider a feature request to the extension to treat this as a fixable error.

Thanks!

@MariaSolOs
Copy link
Member

I debugged this a bit and the issue is that ESLint does not assign a ruleId to disable directive reports, and this extension uses that ID for generating items for the "quick fix" menu:

if (fixTypes !== undefined && problem.ruleId !== undefined && problem.fix !== undefined) {
const type = RuleMetaData.getType(problem.ruleId);
if (type !== undefined && fixTypes.has(type)) {
CodeActions.record(document, diagnostic, problem);
}
} else {
CodeActions.record(document, diagnostic, problem);
}

I think we could have a special treatment of these errors to enable the requested functionality...

@dbaeumer
Copy link
Member

@MariaSolOs thanks for debugging this. I agree that we should have special treatment for this. Are you willing to provide a PR?

@dbaeumer dbaeumer added the bug Issue identified by VS Code Team member as probable bug label Jan 23, 2023
@dbaeumer dbaeumer added this to the On Deck milestone Jan 23, 2023
@MariaSolOs
Copy link
Member

@MariaSolOs thanks for debugging this. I agree that we should have special treatment for this. Are you willing to provide a PR?

I would be happy to :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants