Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

[FIX] [no-unused-vars] address more false positives #153

Merged
merged 2 commits into from
Nov 16, 2018
Merged

[FIX] [no-unused-vars] address more false positives #153

merged 2 commits into from
Nov 16, 2018

Conversation

brainkim
Copy link
Contributor

@brainkim brainkim commented Aug 10, 2018

Fixes false positives demonstrated in these test cases (type parameter in new expression, type parameter constraints):

import { Nullable } from 'nullable';
class A<T> {
    bar: T
}
new A<Nullable>();
import { Nullable } from 'nullable';
import { SomeOther } from 'other';
function foo<T extends Nullable>() {
}
foo<SomeOther>();
import { Nullable } from 'nullable';
import { SomeOther } from 'other';
class A<T extends Nullable> {
    bar: T;
}
new A<SomeOther>();
import { Nullable } from 'nullable';
import { SomeOther } from 'other';
interface A<T extends Nullable> {
    bar: T;
}
const a: A<SomeOther> = {
    foo: "bar"
};
console.log(a);

@brainkim brainkim changed the title mark type parameter constraints as used fix unused var false positives Aug 10, 2018
@brainkim
Copy link
Contributor Author

updated to deal with new expressions and class type parameter constraints

@JamesHenry
Copy link
Collaborator

@brainkim I am very sorry for the long delay in coming back to this, we are going to work out a better maintenance plan for this project.

I have been merging PRs in order, and I'm afraid that means there are new conflicts for your PR

@brainkim
Copy link
Contributor Author

brainkim commented Nov 8, 2018

Rebased the PR against master. Unfortunately, I decided after a while to stop using this rule b/c I kept running into false positives. Instead, I'm setting "noUnusedLocals" and "noUnusedParameters" in tsconfig to true.

Two additional cases which may or may not have been fixed since I worked on this:

this type in arguments:

function foo(this: Bar) {
  return this.type === "bar";
}

will throw an error saying this is unused.
public/protected/private keywords in constructor arguments:

class Foo {
  constructor(public: bar, private: baz) {}
}

will throw an error saying bar and baz are unused.

@brainkim
Copy link
Contributor Author

brainkim commented Nov 8, 2018

#150 <- related issue.
We might want to create a meta-issue for dealing with all no-unused-var false positives.

@bradzacher bradzacher changed the title fix unused var false positives [FIX] [no-unused-vars] address more false positives Nov 16, 2018
@bradzacher
Copy link
Owner

unfortunately no-unused-vars is a difficult rule to maintain due to how many cases typescript introduces.

Thanks for your help in catching more edge cases

@bradzacher bradzacher merged commit 1090947 into bradzacher:master Nov 16, 2018
@brainkim brainkim deleted the mark-type-parameter-constraints branch November 16, 2018 19:55
@bradzacher bradzacher added this to the 1.0.0 milestone Nov 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants