mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 21:07:52 -05:00
Don't add diagnostic on unused import starting with underscore (#24958)
* Don't add diagnostic on unused import starting with underscore * Fix lint
This commit is contained in:
@@ -22895,7 +22895,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
for (const declaration of local.declarations) {
|
||||
if (isAmbientModule(declaration)) continue;
|
||||
if (isAmbientModule(declaration) ||
|
||||
(isVariableDeclaration(declaration) && isForInOrOfStatement(declaration.parent.parent) || isImportedDeclaration(declaration)) && isIdentifierThatStartsWithUnderScore(declaration.name!)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isImportedDeclaration(declaration)) {
|
||||
addToGroup(unusedImports, importClauseFromImported(declaration), declaration, getNodeId);
|
||||
}
|
||||
@@ -22907,9 +22911,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else if (isVariableDeclaration(declaration)) {
|
||||
if (!isIdentifierThatStartsWithUnderScore(declaration.name) || !isForInOrOfStatement(declaration.parent.parent)) {
|
||||
addToGroup(unusedVariables, declaration.parent, declaration, getNodeId);
|
||||
}
|
||||
addToGroup(unusedVariables, declaration.parent, declaration, getNodeId);
|
||||
}
|
||||
else {
|
||||
const parameter = local.valueDeclaration && tryGetRootParameterDeclaration(local.valueDeclaration);
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
tests/cases/compiler/unusedLocalsStartingWithUnderscore.ts(6,9): error TS6133: '_' is declared but its value is never read.
|
||||
/a.ts(7,11): error TS6133: '_ns' is declared but its value is never read.
|
||||
/a.ts(8,9): error TS6133: '_' is declared but its value is never read.
|
||||
|
||||
|
||||
==== tests/cases/compiler/unusedLocalsStartingWithUnderscore.ts (1 errors) ====
|
||||
==== /a.ts (2 errors) ====
|
||||
import * as _ from "./a";
|
||||
|
||||
for (const _ of []) { }
|
||||
|
||||
for (const _ in []) { }
|
||||
|
||||
namespace M {
|
||||
namespace _ns {
|
||||
~~~
|
||||
!!! error TS6133: '_ns' is declared but its value is never read.
|
||||
let _;
|
||||
~
|
||||
!!! error TS6133: '_' is declared but its value is never read.
|
||||
@@ -14,4 +19,4 @@ tests/cases/compiler/unusedLocalsStartingWithUnderscore.ts(6,9): error TS6133: '
|
||||
|
||||
for (const _ in []) { }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
//// [unusedLocalsStartingWithUnderscore.ts]
|
||||
//// [a.ts]
|
||||
import * as _ from "./a";
|
||||
|
||||
for (const _ of []) { }
|
||||
|
||||
for (const _ in []) { }
|
||||
|
||||
namespace M {
|
||||
namespace _ns {
|
||||
let _;
|
||||
for (const _ of []) { }
|
||||
|
||||
for (const _ in []) { }
|
||||
}
|
||||
|
||||
|
||||
//// [unusedLocalsStartingWithUnderscore.js]
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
for (var _i = 0, _a = []; _i < _a.length; _i++) {
|
||||
var _ = _a[_i];
|
||||
var _1 = _a[_i];
|
||||
}
|
||||
for (var _ in []) { }
|
||||
var M;
|
||||
(function (M) {
|
||||
for (var _2 in []) { }
|
||||
var _ns;
|
||||
(function (_ns) {
|
||||
var _;
|
||||
for (var _i = 0, _a = []; _i < _a.length; _i++) {
|
||||
var _1 = _a[_i];
|
||||
var _3 = _a[_i];
|
||||
}
|
||||
for (var _2 in []) { }
|
||||
})(M || (M = {}));
|
||||
for (var _4 in []) { }
|
||||
})(_ns || (_ns = {}));
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
=== tests/cases/compiler/unusedLocalsStartingWithUnderscore.ts ===
|
||||
=== /a.ts ===
|
||||
import * as _ from "./a";
|
||||
>_ : Symbol(_, Decl(a.ts, 0, 6))
|
||||
|
||||
for (const _ of []) { }
|
||||
>_ : Symbol(_, Decl(unusedLocalsStartingWithUnderscore.ts, 0, 10))
|
||||
>_ : Symbol(_, Decl(a.ts, 2, 10))
|
||||
|
||||
for (const _ in []) { }
|
||||
>_ : Symbol(_, Decl(unusedLocalsStartingWithUnderscore.ts, 2, 10))
|
||||
>_ : Symbol(_, Decl(a.ts, 4, 10))
|
||||
|
||||
namespace M {
|
||||
>M : Symbol(M, Decl(unusedLocalsStartingWithUnderscore.ts, 2, 23))
|
||||
namespace _ns {
|
||||
>_ns : Symbol(_ns, Decl(a.ts, 4, 23))
|
||||
|
||||
let _;
|
||||
>_ : Symbol(_, Decl(unusedLocalsStartingWithUnderscore.ts, 5, 7))
|
||||
>_ : Symbol(_, Decl(a.ts, 7, 7))
|
||||
|
||||
for (const _ of []) { }
|
||||
>_ : Symbol(_, Decl(unusedLocalsStartingWithUnderscore.ts, 6, 14))
|
||||
>_ : Symbol(_, Decl(a.ts, 8, 14))
|
||||
|
||||
for (const _ in []) { }
|
||||
>_ : Symbol(_, Decl(unusedLocalsStartingWithUnderscore.ts, 8, 14))
|
||||
>_ : Symbol(_, Decl(a.ts, 10, 14))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
=== tests/cases/compiler/unusedLocalsStartingWithUnderscore.ts ===
|
||||
=== /a.ts ===
|
||||
import * as _ from "./a";
|
||||
>_ : typeof _
|
||||
|
||||
for (const _ of []) { }
|
||||
>_ : any
|
||||
>[] : undefined[]
|
||||
@@ -7,8 +10,8 @@ for (const _ in []) { }
|
||||
>_ : string
|
||||
>[] : undefined[]
|
||||
|
||||
namespace M {
|
||||
>M : typeof M
|
||||
namespace _ns {
|
||||
>_ns : typeof _ns
|
||||
|
||||
let _;
|
||||
>_ : any
|
||||
@@ -21,4 +24,4 @@ namespace M {
|
||||
>_ : string
|
||||
>[] : undefined[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
//@noUnusedLocals:true
|
||||
// @noUnusedLocals:true
|
||||
|
||||
// @Filename: /a.ts
|
||||
import * as _ from "./a";
|
||||
|
||||
for (const _ of []) { }
|
||||
|
||||
for (const _ in []) { }
|
||||
|
||||
namespace M {
|
||||
namespace _ns {
|
||||
let _;
|
||||
for (const _ of []) { }
|
||||
|
||||
for (const _ in []) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user