vscode-solidity-inspector
vscode-solidity-inspector copied to clipboard
Unused import false positive when using unnamed imports
Sometimes, the extension will highlight an unnamed import (eg `import "../src/Contract.sol") as unused even though it is used. In my case, this happens when the file importing from has multiple contracts but I don't know whether this is actually the issue. If this is useful, I can experiment and try to find the root cause of the issue
Thanks for reporting! Will look into it soon.
Sorry for the delayed response.
The issue arises if you have use an imported contract from other file.
For ex, you have 2 contracts: Contract A and Contract B. If Contract B tries to use imports from contract A, it will not be detected by this extension. For now, it only detects unused imports in the current file to keep things simple. I agree it would be more useful to detect unused imports across different files.
If you can add the feature, PRs are more than welcome :) I'm happy to review!
Another false positive is happening with free functions, if you don't use named imports the extension will mark the whole import as unused.
Agreed. Currently, highlighting unused imports works best for named imports.
I believe named imports should be adopted by default so that readers know what contracts are being used from the imported file. It also helps to make the imports consistent. Unfortunately that's not the case now.
One way to fix this is to index the contract names in each of the files and check if the contract has been used in the current file. I wanted to keep it simple, but this change looks quite complex and I also suspect it might have some perf issues for larger projects. Other option is to ignore unused import highlights for unnamed imports.