Skip to content
Permalink
Browse files

fix(eslint-plugin): [no-shadow] fix false-positive on enum declaration (

  • Loading branch information
bradzacher committed Aug 29, 2020
1 parent a9cd6fb commit 9de669f339fef62a98f745dc08b833aa5c632e62
@@ -116,6 +116,25 @@ export default util.createRule<Options, MessageIds>({
);
}

/**
* Checks if a variable of the class name in the class scope of ClassDeclaration.
*
* ClassDeclaration creates two variables of its name into its outer scope and its class scope.
* So we should ignore the variable in the class scope.
* @param variable The variable to check.
* @returns Whether or not the variable of the class name in the class scope of ClassDeclaration.
*/
function isDuplicatedEnumNameVariable(
variable: TSESLint.Scope.Variable,
): boolean {
const block = variable.scope.block;

return (
block.type === AST_NODE_TYPES.TSEnumDeclaration &&
block.id === variable.identifiers[0]
);
}

/**
* Checks if a variable is inside the initializer of scopeVar.
*
@@ -233,6 +252,11 @@ export default util.createRule<Options, MessageIds>({
continue;
}

// ignore variables of a class name in the class scope of ClassDeclaration
if (isDuplicatedEnumNameVariable(variable)) {
continue;
}

// ignore configured allowed names
if (isAllowed(variable)) {
continue;
@@ -431,6 +431,13 @@ function foo(cb) {
`,
options: [{ allow: ['cb'] }],
},
// https://github.com/typescript-eslint/typescript-eslint/issues/2360
`
enum Direction {
left = 'left',
right = 'right',
}
`,
],
invalid: [
{

0 comments on commit 9de669f

Please sign in to comment.