-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[no-unused-var] false positive when using recursive interface in d.ts #2714
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
are you using This is the same behaviour that you get for self-referencing functions |
@bradzacher yes,I declare |
please provide the full code sample so I can repro it appropriately. |
@bradzacher try this repo, please |
The bug is that we're doing an explicit report for interfaces that self-reference, but that circumvents the checks we do for ambient declarations. typescript-eslint/packages/eslint-plugin/src/rules/no-unused-vars.ts Lines 190 to 199 in 0d696c7
|
@bradzacher would this solve the issue? const isOnlySelfReferenced = variable.references.every(ref => {
if (
ref.identifier.range[0] >= node.range[0] &&
- ref.identifier.range[1] <= node.range[1]
+ ref.identifier.range[1] <= node.range[1] &&
+ !util.isDefinitionFile(filename)
) {
return true;
}
return false;
});
|
that's in the right direction! But we should be able simplify this (I believe) When the rule runs over a declaration file, it calls typescript-eslint/packages/eslint-plugin/src/rules/no-unused-vars.ts Lines 306 to 358 in 0d696c7
So instead we could express this clearer as: const isOnlySelfReferenced = variable.references.every(ref => {
if (
ref.identifier.range[0] >= node.range[0] &&
ref.identifier.range[1] <= node.range[1]
) {
return true;
}
return false;
});
-if (isOnlySelfReferenced) {
+if (isOnlySelfReferenced && variable.eslintUsed !== true) { |
@bradzacher is it possible to create a test case for this? To test |
yes - you can use the |
Repro
interface.d.ts
Expected Result
No warning on interface IItem
Actual Result
Got warning: 'IItem' is defined but never used
Additional Info
Versions
@typescript-eslint/eslint-plugin
4.6.0
@typescript-eslint/parser
4.6.0
TypeScript
4.0.5
ESLint
6.8.0
node
12.16.2
The text was updated successfully, but these errors were encountered: