Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-plugin): [no-unused-vars] fork the base rule
I wanted to avoid doing this, but not doing this restricts our logic too much - it causes problems when we want to consider reporting on things that the base rule wouldn't report on. Fixes #2714 Fixes #2648 Closes #2679
- Loading branch information
1 parent
c2dde58
commit 8062050
Showing
8 changed files
with
1,196 additions
and
222 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
729 changes: 729 additions & 0 deletions
729
packages/eslint-plugin/src/util/collectUnusedVariables.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,51 @@ | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
|
||
import * as scopeManager from '@typescript-eslint/scope-manager'; | ||
import { TSESTree } from '@typescript-eslint/types'; | ||
|
||
namespace Scope { | ||
// ESLint defines global variables using the eslint-scope Variable class | ||
// So a variable in the scope may be either of these | ||
declare class ESLintScopeVariable { | ||
public readonly defs: Definition[]; | ||
public readonly identifiers: TSESTree.Identifier[]; | ||
public readonly name: string; | ||
public readonly references: Reference[]; | ||
public readonly scope: Scope; | ||
|
||
/** | ||
* Written to by ESLint. | ||
* If this key exists, this variable is a global variable added by ESLint. | ||
* If this is `true`, this variable can be assigned arbitrary values. | ||
* If this is `false`, this variable is readonly. | ||
*/ | ||
public writeable?: boolean; // note that this isn't a typo - ESlint uses this spelling here | ||
|
||
/** | ||
* Written to by ESLint. | ||
* This property is undefined if there are no globals directive comments. | ||
* The array of globals directive comments which defined this global variable in the source code file. | ||
*/ | ||
public eslintExplicitGlobal?: boolean; | ||
|
||
/** | ||
* Written to by ESLint. | ||
* The configured value in config files. This can be different from `variable.writeable` if there are globals directive comments. | ||
*/ | ||
public eslintImplicitGlobalSetting?: 'readonly' | 'writable'; | ||
|
||
/** | ||
* Written to by ESLint. | ||
* If this key exists, it is a global variable added by ESLint. | ||
* If `true`, this global variable was defined by a globals directive comment in the source code file. | ||
*/ | ||
public eslintExplicitGlobalComments?: TSESTree.Comment[]; | ||
} | ||
|
||
export type ScopeManager = scopeManager.ScopeManager; | ||
export type Reference = scopeManager.Reference; | ||
export type Variable = scopeManager.Variable | ESLintScopeVariable; | ||
export type Variable = | ||
| scopeManager.Variable | ||
| scopeManager.ESLintScopeVariable; | ||
export type Scope = scopeManager.Scope; | ||
export const ScopeType = scopeManager.ScopeType; | ||
// TODO - in the next major, clean this up with a breaking change | ||
export type DefinitionType = scopeManager.Definition; | ||
export type Definition = scopeManager.Definition; | ||
export const DefinitionType = scopeManager.DefinitionType; | ||
|
||
export namespace Definitions { | ||
export type CatchClauseDefinition = scopeManager.CatchClauseDefinition; | ||
export type ClassNameDefinition = scopeManager.ClassNameDefinition; | ||
export type FunctionNameDefinition = scopeManager.FunctionNameDefinition; | ||
export type ImplicitGlobalVariableDefinition = scopeManager.ImplicitGlobalVariableDefinition; | ||
export type ImportBindingDefinition = scopeManager.ImportBindingDefinition; | ||
export type ParameterDefinition = scopeManager.ParameterDefinition; | ||
export type TSEnumMemberDefinition = scopeManager.TSEnumMemberDefinition; | ||
export type TSEnumNameDefinition = scopeManager.TSEnumNameDefinition; | ||
export type TSModuleNameDefinition = scopeManager.TSModuleNameDefinition; | ||
export type TypeDefinition = scopeManager.TypeDefinition; | ||
export type VariableDefinition = scopeManager.VariableDefinition; | ||
} | ||
export namespace Scopes { | ||
export type BlockScope = scopeManager.BlockScope; | ||
export type CatchScope = scopeManager.CatchScope; | ||
export type ClassScope = scopeManager.ClassScope; | ||
export type ConditionalTypeScope = scopeManager.ConditionalTypeScope; | ||
export type ForScope = scopeManager.ForScope; | ||
export type FunctionExpressionNameScope = scopeManager.FunctionExpressionNameScope; | ||
export type FunctionScope = scopeManager.FunctionScope; | ||
export type FunctionTypeScope = scopeManager.FunctionTypeScope; | ||
export type GlobalScope = scopeManager.GlobalScope; | ||
export type MappedTypeScope = scopeManager.MappedTypeScope; | ||
export type ModuleScope = scopeManager.ModuleScope; | ||
export type SwitchScope = scopeManager.SwitchScope; | ||
export type TSEnumScope = scopeManager.TSEnumScope; | ||
export type TSModuleScope = scopeManager.TSModuleScope; | ||
export type TypeScope = scopeManager.TypeScope; | ||
export type WithScope = scopeManager.WithScope; | ||
} | ||
} | ||
|
||
export { Scope }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters