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

prefer-const not work with mutiple functions #12514

Closed
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion autofix This change is related to ESLint's autofixing capabilities bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@rupertqin
Copy link

Tell us about your environment

Node version: v10.16.3
npm version: v6.12.0
Local ESLint version: v6.6.0
Global ESLint version: v6.6.0

What did you expect to happen?

rule of prefer-const mess up in multiple function.
the config is:

"prefer-const": [
      "warn",
      {
        "destructuring": "all",
        "ignoreReadBeforeAssign": true
      }
    ],

file a.js

function a (){
  let foo =0;
  foo = 1;
}
function b (){
  let foo =0;
  foo = 1;
}
function c (){
  let foo =0;
  foo = 1;
}

will eslint --fix output as

function a (){
  let foo =0;
  foo = 1;
}
function b (){
  const foo =0;
  foo = 1;
}
function c (){
  const foo =0;
  foo = 1;
}

Are you willing to submit a pull request to fix this bug?

Can't help with resolution.

@rupertqin rupertqin added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Oct 31, 2019
@g-plane
Copy link
Member

g-plane commented Oct 31, 2019

It seems that I can't reproduce via online demo.

Can you tell us more detail?

@rupertqin
Copy link
Author

@g-plane try this

function a() {
  let foo = 0,
    bar = 1;
  foo = 1;
}
function b() {
  let foo = 0,
    bar = 1;
  foo = 1;
}
function c() {
  let foo = 0,
    bar = 1;
  foo = 1;
}

@g-plane
Copy link
Member

g-plane commented Oct 31, 2019

Reproduced. Online demo.

@g-plane g-plane added accepted There is consensus among the team that this change meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Oct 31, 2019
@yeonjuan
Copy link
Member

May I try this on?

@g-plane
Copy link
Member

g-plane commented Oct 31, 2019

Feel free to do this!

@kaicataldo
Copy link
Member

@g-plane Can you explain what the bug here is? I'm not sure I understand why the above code being flagged is incorrect.

@g-plane g-plane added the autofix This change is related to ESLint's autofixing capabilities label Nov 2, 2019
@g-plane
Copy link
Member

g-plane commented Nov 2, 2019

The bug is about autofix, while problem reports work as intended.

@kaicataldo
Copy link
Member

Oh, I see - yes, that does look like a bug.

@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.