Skip to content

Bug: --fix ignores defined order and creates a JS error #13899

@darlandemarco

Description

@darlandemarco

Tell us about your environment

  • ESLint Version: 6.8.0
  • Node Version: 8.15
  • npm Version: 6.4.1

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?
default

Please show your full configuration:

Configuration
module.exports = {
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": "eslint:recommended",
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "rules": {
        "prefer-const": "error",
        "no-undef-init": "warn"
    }
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

let foo= undefined; //foo is not reasigned so it will try to transform to const and keep initialization as undefined;

Eslint command:

node node_modules/eslint/bin/eslint.js --fix testfile.js

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 to const 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 :)

eslint

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionautofixThis change is related to ESLint's autofixing capabilitiesbugESLint is working incorrectlyruleRelates to ESLint's core rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions