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

Comments

@rupertqin
Copy link

@rupertqin rupertqin commented Oct 31, 2019

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.

@g-plane

This comment has been minimized.

Copy link
Member

@g-plane g-plane commented Oct 31, 2019

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

Can you tell us more detail?

@rupertqin

This comment has been minimized.

Copy link
Author

@rupertqin rupertqin commented Oct 31, 2019

@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

This comment has been minimized.

Copy link
Member

@g-plane g-plane commented Oct 31, 2019

Reproduced. Online demo.

@g-plane g-plane added accepted rule and removed triage labels Oct 31, 2019
@yeonjuan

This comment has been minimized.

Copy link
Member

@yeonjuan yeonjuan commented Oct 31, 2019

May I try this on?

@g-plane

This comment has been minimized.

Copy link
Member

@g-plane g-plane commented Oct 31, 2019

Feel free to do this!

@kaicataldo

This comment has been minimized.

Copy link
Member

@kaicataldo kaicataldo commented Nov 1, 2019

@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 label Nov 2, 2019
@g-plane

This comment has been minimized.

Copy link
Member

@g-plane g-plane commented Nov 2, 2019

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

@kaicataldo

This comment has been minimized.

Copy link
Member

@kaicataldo kaicataldo commented Nov 4, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.