"Remove this unused import" when a type is actually used


The VSCode SonarLint extension warns be about an unused import of a type I actually use

// ...
import { AdditionalPanelComment } from '@/types';
// Remove this unused import of 'AdditionalPanelComment'.sonarlint(javascript:S1128)
// ...
comments(): AdditionalPanelComment[] {
// ...

I’d guess it’s because types are not actually used at runtime, so SonarJS might get confused? I don’t really know what’s happening under the hood. In any case, here’s my env:

Ubuntu 20.10
VSCode 1.52.1
SonarLint 1.19.0

Hello Nino!
Welcome to SonarSource comunity and thanks for your feedback.
Sorry response took so long. I tried to reproduce this behavior but had no luck. May be you can attach archive with sample project where this bug appears? We will try to reproduce it anyway, but with sample project it will be faster.

Best regards

Hello Kirill!

Unfortunately the repo where it happened is closed-source and I cannot include it… I tried to do a minimal reproducible example but like you I couldn’t

Don’t worry too much about this bug it’s not blocking our CI (somehow SonarQube doesn’t raise any errors, by SonarLint does), it’s just a bit annoying sometimes and I wanted to give you a heads up on it in case it was related to an unknown bigger issue

1 Like