-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Rule Change: no-console could be fixable #17493
Comments
For the moment I will continue removing my console.log manually, it is just (a bit) annoying when you do it twice a day for 5 minutes and you know you will do so in the future 5-10 years) |
Hi @edi9999, thanks for the proposal! We can't implement this as autofix, because autofixes should never change the runtime behavior of code. This is the policy for core rules and general advice for plugins (though, you can find an equivalent but autofixable no-console rule in eslint-plugin-autofix). We could only consider implementing this in the core |
Interesting, how can I access the suggestions ? Is there a way to access them from the command line ? If yes, I would be interested in first having an example output in the command line, then I could write the code for the suggestion of the console.log rule. |
Removing console with autofix should be a standalone plugin |
So you mean you wouldn't be open to add the "suggestion" to console.logs ? I'm using neovim as my editor so I'm not sure whether I can use suggestions at all, that's why I asked whether I could do something from the command line. |
The ESLint team would be open to evaluating adding suggestions to the
Not sure either, but you could try with a code example where suggestions are expected to appear: /* eslint no-useless-escape: "error" */
"\a"; The expected suggestions are as in this demo. |
Marking as accepted. |
* feat: Add suggestions to no-console Fixes #17493 * Fix method of when to show safe suggestions and fix tests. * improved formatting of tests with suggestions by breaking them into multiple lines * Updated function name to canProvideSuggestions. Added better description for the function. * Fixed code that fails when AST is not deep enough. * Added suggestions:null for test cases that will not provide a suggestion. * test to make sure console statement with semicolon is removed via suggestion * dont provide suggestions if removing console.log() will lead to ASI breaking * missing period * renamed regexps variable names for better understanding * updated passing in expressionstatement node instead of memberexpression node to maybeAsiHazard * ++ or -- in the token before is not always safe.
What rule do you want to change?
no-console
What change to do you want to make?
Implement autofix
How do you think the change should be implemented?
A new option
Example code
I debug a lot with console.log, and have to remove them all afterwards.
Some console.log I write are multiline, like this :
What does the rule currently do for this code?
It will simply report the error
What will the rule do after it's changed?
It could fix the error, removing the console.log alltogether
Participation
Additional comments
I know this has not been implemented on purpose, probably people don't want all their console.logs dropped by eslint by default, I would also like to be able to make this rule fix only on certain conditions.
The text was updated successfully, but these errors were encountered: