Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 1 commit intov4from2360-no-shadow-bug
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletionspackages/eslint-plugin/src/rules/no-shadow.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
*
Expand DownExpand Up@@ -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;
Expand Down
7 changes: 7 additions & 0 deletionspackages/eslint-plugin/tests/rules/no-shadow.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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: [
{
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp