microsoft / typespec

https://typespec.io/
MIT License
4.44k stars 208 forks source link

Add linter rule or compiler warning for unused imports #2196

Open mikeharder opened 1 year ago

mikeharder commented 1 year ago

I have seen many typespec files which import packages they don't actually need, like Azure/azure-rest-api-specs-pr#12933 which was importing @azure-tools/typespec-providerhub-controller.

Could we add a linter rule or compiler warnings for imports that are not reference in the typespec (or imports that have no typespec exports)?

mikeharder commented 5 months ago

Recent spec where this would have helped:

https://github.com/Azure/azure-rest-api-specs/pull/29212

RodgeFu commented 4 months ago

When reporting diagnostic for the unused stuff, please make sure DiagnosticTag .Unnecessary tag is added.

https://vscode-api.js.org/enums/vscode.DiagnosticTag.html#Unnecessary