Skip to content

Commit 189162d

Browse files
authored
fix(eslint-plugin): [no-use-before-define] false positive for function type arguments (typescript-eslint#2554)
Fixes typescript-eslint#2527
1 parent 02d72d4 commit 189162d

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

packages/eslint-plugin/src/rules/no-use-before-define.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ export default util.createRule<Options, MessageIds>({
260260
variable.identifiers.length === 0 ||
261261
(variable.identifiers[0].range[1] <= reference.identifier.range[1] &&
262262
!isInInitializer(variable, reference)) ||
263-
!isForbidden(variable, reference)
263+
!isForbidden(variable, reference) ||
264+
reference.from.type === TSESLint.Scope.ScopeType.functionType
264265
) {
265266
return;
266267
}

packages/eslint-plugin/tests/rules/no-use-before-define.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ const React = require('react');
343343
},
344344
},
345345
},
346+
// https://github.com/typescript-eslint/typescript-eslint/issues/2527
347+
`
348+
type T = (value: unknown) => value is Id;
349+
`,
346350
],
347351
invalid: [
348352
{

packages/experimental-utils/src/ts-eslint/Scope.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ namespace Scope {
4646
export type Reference = scopeManager.Reference;
4747
export type Variable = scopeManager.Variable | ESLintScopeVariable;
4848
export type Scope = scopeManager.Scope;
49+
export const ScopeType = scopeManager.ScopeType;
4950
// TODO - in the next major, clean this up with a breaking change
5051
export type DefinitionType = scopeManager.Definition;
5152
export type Definition = scopeManager.Definition;
53+
export const DefinitionType = scopeManager.DefinitionType;
5254
}
5355

5456
export { Scope };

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy