File tree 3 files changed +60
-1
lines changed
3 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 3
3
## Rule Details
4
4
5
5
This rule extends the base [ ` eslint/no-shadow ` ] ( https://eslint.org/docs/rules/no-shadow ) rule.
6
- It adds support for TypeScript's ` this ` parameters, and adds options for TypeScript features.
6
+ It adds support for TypeScript's ` this ` parameters and global augmentation , and adds options for TypeScript features.
7
7
8
8
## How to use
9
9
Original file line number Diff line number Diff line change 3
3
TSESLint ,
4
4
AST_NODE_TYPES ,
5
5
} from '@typescript-eslint/experimental-utils' ;
6
+ import { ScopeType } from '@typescript-eslint/scope-manager' ;
6
7
import * as util from '../util' ;
7
8
8
9
type MessageIds = 'noShadow' ;
@@ -67,6 +68,16 @@ export default util.createRule<Options, MessageIds>({
67
68
} ,
68
69
] ,
69
70
create ( context , [ options ] ) {
71
+ /**
72
+ * Check if a scope is a TypeScript module augmenting the global namespace.
73
+ */
74
+ function isGlobalAugmentation ( scope : TSESLint . Scope . Scope ) : boolean {
75
+ return (
76
+ ( scope . type === ScopeType . tsModule && ! ! scope . block . global ) ||
77
+ ( ! ! scope . upper && isGlobalAugmentation ( scope . upper ) )
78
+ ) ;
79
+ }
80
+
70
81
/**
71
82
* Check if variable is a `this` parameter.
72
83
*/
@@ -261,6 +272,11 @@ export default util.createRule<Options, MessageIds>({
261
272
* @param {Scope } scope Fixme
262
273
*/
263
274
function checkForShadows ( scope : TSESLint . Scope . Scope ) : void {
275
+ // ignore global augmentation
276
+ if ( isGlobalAugmentation ( scope ) ) {
277
+ return ;
278
+ }
279
+
264
280
const variables = scope . variables ;
265
281
266
282
for ( const variable of variables ) {
Original file line number Diff line number Diff line change @@ -116,6 +116,49 @@ type Fn = (Foo: string) => typeof Foo;
116
116
Foo : 'writable' ,
117
117
} ,
118
118
} ,
119
+ // https://github.com/typescript-eslint/typescript-eslint/issues/2724
120
+ {
121
+ code : `
122
+ declare global {
123
+ interface ArrayConstructor {}
124
+ }
125
+ export {};
126
+ ` ,
127
+ options : [ { builtinGlobals : true } ] ,
128
+ } ,
129
+ `
130
+ declare global {
131
+ const a: string;
132
+
133
+ namespace Foo {
134
+ const a: number;
135
+ }
136
+ }
137
+ export {};
138
+ ` ,
139
+ {
140
+ code : `
141
+ declare global {
142
+ type A = 'foo';
143
+
144
+ namespace Foo {
145
+ type A = 'bar';
146
+ }
147
+ }
148
+ export {};
149
+ ` ,
150
+ options : [ { ignoreTypeValueShadow : false } ] ,
151
+ } ,
152
+ {
153
+ code : `
154
+ declare global {
155
+ const foo: string;
156
+ type Fn = (foo: number) => void;
157
+ }
158
+ export {};
159
+ ` ,
160
+ options : [ { ignoreFunctionTypeParameterNameValueShadow : false } ] ,
161
+ } ,
119
162
] ,
120
163
invalid : [
121
164
{
You can’t perform that action at this time.
0 commit comments