diff --git a/lib/rules/prefer-const.js b/lib/rules/prefer-const.js index 8b3bc5e0e436..3109b81c0a29 100644 --- a/lib/rules/prefer-const.js +++ b/lib/rules/prefer-const.js @@ -378,14 +378,6 @@ module.exports = { if (nodes.length && (shouldMatchAnyDestructuredVariable || nodesToReport.length === nodes.length)) { const varDeclParent = findUp(nodes[0], "VariableDeclaration", parentNode => parentNode.type.endsWith("Statement")); const shouldFix = varDeclParent && - - /* - * If there are multiple variable declarations, like {let a = 1, b = 2}, then - * do not attempt to fix if one of the declarations should be `const`. It's - * too hard to know how the developer would want to automatically resolve the issue. - */ - varDeclParent.declarations.length === 1 && - // Don't do a fix unless the variable is initialized (or it's in a for-in or for-of loop) (varDeclParent.parent.type === "ForInStatement" || varDeclParent.parent.type === "ForOfStatement" || varDeclParent.declarations[0].init) && diff --git a/tests/lib/rules/prefer-const.js b/tests/lib/rules/prefer-const.js index f97320234616..92840c09822a 100644 --- a/tests/lib/rules/prefer-const.js +++ b/tests/lib/rules/prefer-const.js @@ -357,7 +357,7 @@ ruleTester.run("prefer-const", rule, { }, { code: "let {a = 0, b} = obj, c = a; b = a;", - output: null, + output: "const {a = 0, b} = obj, c = a; b = a;", options: [{ destructuring: "any" }], errors: [ { message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" }, @@ -366,7 +366,7 @@ ruleTester.run("prefer-const", rule, { }, { code: "let {a = 0, b} = obj, c = a; b = a;", - output: null, + output: "const {a = 0, b} = obj, c = a; b = a;" , options: [{ destructuring: "all" }], errors: [{ message: "'c' is never reassigned. Use 'const' instead.", type: "Identifier" }] },