-
Notifications
You must be signed in to change notification settings - Fork 889
Fix build #3853
Conversation
…e for TS2.8 support Logic had to be modified because starting from TS2.8, when all imports in an import node are not used, TS emits only 1 diagnostic object for the whole line as opposed to the previous behavior of outputting a diagnostic with kind == 6192 (UnusedKind.VARIABLE_OR_PARAMETER) for every unused import.
src/rules/noUnusedVariableRule.ts
Outdated
@@ -337,12 +339,14 @@ function forEachImport<T>(sourceFile: ts.SourceFile, f: (i: ImportLike) => T | u | |||
}); | |||
} | |||
|
|||
function findImport(pos: number, sourceFile: ts.SourceFile): ts.Identifier | undefined { | |||
function findImports(pos: number, sourceFile: ts.SourceFile, kind: UnusedKind): ReadonlyArray<ts.Identifier> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing to an array since in the case of kind === DECLARATION we want to return all the imports in the node
} | ||
if (kind === UnusedKind.VARIABLE_OR_PARAMETER || kind === UnusedKind.DECLARATION) { | ||
const importNames = findImports(diag.start, sourceFile, kind); | ||
if (importNames.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic changes to handle the array return type
@@ -66,7 +66,11 @@ export class DestructuringTests { | |||
} | |||
|
|||
abstract class AbstractTest { | |||
#if typescript >= 2.8.0 | |||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [err % ('AbstractTest')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in compiler generated ranges
@@ -2,7 +2,11 @@ | |||
const fs = require("fs"); | |||
|
|||
module Foo { | |||
~~~ [err % ('Foo')] | |||
#if typescript >= 2.8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in compiler generated ranges
// | ||
}; | ||
|
||
function func3() { | ||
~~~~~ [err % ('func3')] | ||
#if typescript >= 2.8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in compiler generated ranges
@@ -42,7 +42,11 @@ $(_.xyz()); | |||
/// <reference path="../externalFormatter.test.ts" /> | |||
|
|||
module S { | |||
#if typescript >= 2.8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in compiler generated ranges
Added builds for TS 2.7 and 2.8 |
@JoshuaKGoldberg can you take a look at this? |
@@ -12,8 +12,15 @@ var z; | |||
|
|||
export var abcd = 3; | |||
|
|||
// Could be a bug with 2.9-dev but getPreEmitDiagnostics isn't |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably should file a ticket to follow-up on this when real 2.9 is released
@@ -95,8 +95,6 @@ interface NotATuple { | |||
declare const notATuple: NotATuple; | |||
notATuple; | |||
|
|||
unknownName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this cause test errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I'm not very familiar with this particular area, but it all seems reasonable.
return imports !== undefined ? imports : []; | ||
} | ||
|
||
function isInRange(range: ts.TextRange, pos: number): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: might belong in some utils file somewhere? isInTextRange
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm not sure where it would belong though
// https://github.com/Microsoft/TypeScript/issues/14257 | ||
[Symbol.iterator]() {} | ||
#if typescript >= 2.8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL this is possible. Is this documented anywhere? If not, should we file a followup issue for another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if it has been documented anywhere, I found it while reading the tests. I think documenting it would be useful. Let's file a follow up issue
@@ -65,8 +65,15 @@ export class DestructuringTests { | |||
} | |||
} | |||
|
|||
// Could be a bug with 2.9-dev but getPreEmitDiagnostics isn't |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you link to the corresponding TypeScript issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 or if there isn't one, file a ticket with them and link it to this PR!
FYI @amcasey (I think you've been working in this space recently?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I don't know all the TS internals super well so I sort of just glanced over the details of the changes for 2.8, but the test cases all look reasonable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM so long as we file some tickets for those outstanding issues
So it wasn't an issue with TS, but the diagnoses were being ignored because the diagnosis code had changed in 2.9. Made changes to the code to handle those and fixed the tests accordingly. But this solidifies the concern that I had, which is that this rule is complex and hard to maintain with a living and changing compiler. I feel that we should deprecate this rule in the near future for the following reasons:
Deprecating the rule was discussed: #1481 but the community decided to not deprecate it for two main reasons: (1) is in discussion in microsoft/TypeScript#13408 and is already supported via microsoft/vscode#37616 |
@jkillian @johnwiseheart @JoshuaKGoldberg ^^^ not that we should take any action now but something to keep track of in the future |
I'm in favor of deprecating it altogether. My team at work just switched from the TSLint rule to TypeScript's flags because the TSLint VS Code extension doesn't support typed rules and we haven't gotten around to using the language service. Error diagnostics and messages are a big point of investment for TypeScript right now, so this doesn't feel like something worth investing in for TSLint. |
PR checklist
Overview of change:
no-unused-variables
rule due to changes (kind, count, text range) in what the compiler outputs forpreEmitDiagnostics
Is there anything you'd like reviewers to focus on?
CHANGELOG.md entry: