SonarLint VSCode should change behaviour of 'Organize Imports' keyboard shortcut

SonarLint wants relative imports in typescript, for example, but VSCode will undo that with the organize imports keyboard shortcut. Ideally with SonarLint installed, organize imports will make SonarLint happy.

Hello,

Welcome to the community!

To help us better understand what is happening, could you share with us a small reproducer ? Thanks

In sonarsource_topic_vscode_organize_imports_typescript/Kabob.tsx at master · micheal-w-wells/sonarsource_topic_vscode_organize_imports_typescript · GitHub for example, if you have baseUrl set in tsconfig Sonar will give the below smell, however the vscode organize import command won’t make any changes to address it.

I was mistaken in thinking the organize import command would undo relative to absolute imports, that behaviour was a result of prettier extension being enabled, however the smell issue is still there.

I think the ideal behaviour is for sonar lint to be smart enough to know that absolute imports are a thing if baseUrl is set and not confuse them with package.json imports.


# <big>Dependencies should be explicit</big> (typescript:S4328)

Dependencies should be explicitly listed in the `package.json` file. Importing a module that is not declared as a dependency makes it an implicit one and is bound to create problems

Launching VSCode today, I got a notification saying there were new bindings for sonarlint, I accepted and now SonarLint does not complain about the absolute path imports!

I’d say that the feature request now would be to change all relative imports to absolute, or visa versa on hitting ‘organize imports’, depending on what is in tsconfig.json for baseUrl.