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
Bug: --fix ignores defined order and creates a JS error #13899
Bug: --fix ignores defined order and creates a JS error #13899
Comments
Hi @darlandemarco, thanks for the issue! I can confirm that You're using an old ESLint version, but this happens in the actual version as well: Online Demo |
That would be great, thanks! I think the "fix range" of There's fix-tracker helper for this purpose. We should call retainRange and then replaceTextRange. You can find some examples of use in rules such as A test case for // https://github.com/eslint/eslint/issues/13899
{
code: "/*eslint no-undef-init:error*/ let foo = undefined;",
output: "/*eslint no-undef-init:error*/ const foo = undefined;",
errors: 2
} |
Can I work on this issue? |
@snitin315 sure, thanks! It doesn't seem anyone is working on this at the moment. |
Tell us about your environment
What parser (default,
@babel/eslint-parser
,@typescript-eslint/parser
, etc.) are you using?default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
Eslint command:
What did you expect to happen?
transform variable to constant but not remove the undefined init as it will become a constant.
What actually happened? Please include the actual, raw output from ESLint.
I have runned an autofix in a legacy code with more than 10k files. When it finds a variable that should be a constant (because it is not reasigned) and is initialized as
undefined
it fix the code transforming it toconst foo;
causing errors over the code. I tried to change the rules order to first turns it to a constant and them check the undefined init so it should be fixed (as per: https://eslint.org/docs/rules/no-undef-init). But is still happening.Are you willing to submit a pull request to fix this bug?
Yes, need some guidance but I can do this :)
The text was updated successfully, but these errors were encountered: