Skip to content

Commit

Permalink
Fix: Remove warning in initialized variables (fixes #12687)
Browse files Browse the repository at this point in the history
  • Loading branch information
boutahlilsoufiane committed Sep 5, 2021
1 parent bbf1dcc commit d6f1a33
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-shadow.js
Expand Up @@ -260,7 +260,7 @@ module.exports = {

if (shadowed &&
(shadowed.identifiers.length > 0 || (options.builtinGlobals && "writeable" in shadowed)) &&
!isOnInitializer(variable, shadowed) && !isInitPatternNode(variable, shadowed) &&
!isOnInitializer(variable, shadowed) && (!isInitPatternNode(variable, shadowed) || options.hoist === "all") &&
!(options.hoist !== "all" && isInTdz(variable, shadowed))
) {
const location = getDeclaredLocation(shadowed);
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/rules/no-shadow.js
Expand Up @@ -725,6 +725,31 @@ ruleTester.run("no-shadow", rule, {
line: 1,
column: 31
}]
},
{
code: "let x = foo((x,y) => {});\nlet y;",
options: [{ hoist: "all" }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "noShadow",
data: {
name: "x",
shadowedLine: 1,
shadowedColumn: 5
},
type: "Identifier"
},
{
messageId: "noShadow",
data: {
name: "y",
shadowedLine: 2,
shadowedColumn: 5
},
type: "Identifier"
}
]
}
]
});

0 comments on commit d6f1a33

Please sign in to comment.