plantain-00 / type-coverage

A CLI tool to check type coverage for typescript code
MIT License
1.2k stars 43 forks source link

Report unused ignore lines #136

Closed Logicer16 closed 3 months ago

Logicer16 commented 3 months ago

Report ignore lines which are not silencing an issue. This will help catch comments that are yet to be removed even if the issue they were previously silencing has been fixed. These unused comments may pollute the code over time and may hide new issues in the code.

Similar to eslint's reportUnusedDisableDirectives:

1:1  error  Unused eslint-disable directive (no problems were reported)

Or typescript's:

TS2578: Unused '@ts-expect-error' directive.

1 // @ts-expect-error
  ~~~~~~~~~~~~~~~~~~~
plantain-00 commented 3 months ago

I think it's out of scope of this tool, it's not type of any identifier.

Logicer16 commented 3 months ago

I think it's out of scope of this tool

I'm not sure I understand. I'm referring to the // type-coverage:ignore-next-line and // type-coverage:ignore-line comments described here. These are comments specific to this project and are only relevant to this project's functionality.

The examples above are just to demonstrate similar functionality in other projects. I am not asking to reimplement the functionality of these projects for their use cases, but to instead have one for this project's use case.

When a user tries to ignore an any type which doesn't exist, this is likely mistake and should be brought to the user's attention. For example:

// Valid
const one: number = 1;
// type-coverage:ignore-next-line
const two: any = getTwo();

// Invalid: There is no any type so the ignore comment is unused.
// type-coverage:ignore-next-line
const three: number = 3
plantain-00 commented 3 months ago

v2.28's --report-unused-ignore should support this.

Logicer16 commented 3 months ago

Thank you so much! ❤️