solidity icon indicating copy to clipboard operation
solidity copied to clipboard

Warning about unused imports

Open pcaversaccio opened this issue 2 years ago • 11 comments

Currently, the compiler issues a warning for an unused function parameter. I think it would be a good idea to do the same for unused imports in order to improve the quality and cleanliness of the code.

Example

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

/// @dev This import is unused. The compiler should issue a warning.
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract MockContract {
    function hashFunction() external pure returns (bytes32) {
        return keccak256("Hello World");
    }
}

pcaversaccio avatar Dec 21 '22 22:12 pcaversaccio

libtasn1-6/stable 4.16.0-2+deb11u1 amd64 [upgradable from: 4.16.0-2]

4.26.0.3

Killabits avatar Dec 24 '22 14:12 Killabits

I agree, this would be a nice thing to have. We should discuss this on one of the upcoming design calls and see if we have consensus in the team to go forward with it.

cameel avatar Jan 27 '23 22:01 cameel

We discussed this and agreed that it would be nice to have, though very low priority. We'd be open to contributions. The nice thing about it is that it's very clear in terms of what the end result should be. In terms of implementation it might not be that easy though, and we really would not like it to just be hacked into the analyzer so anyone working on it should first drop on one of the team calls and discuss the details with us first.

cameel avatar Jan 31 '23 19:01 cameel

Would also be nice to have a warning for unused modifiers and custom errors.

shafu0x avatar Mar 22 '23 04:03 shafu0x

This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.

github-actions[bot] avatar Jun 20 '23 12:06 github-actions[bot]

Don't close this issue.

pcaversaccio avatar Jun 20 '23 12:06 pcaversaccio

I'd also be in favor of both unused imports and particularly custom errors these are later added to the interfaceId in some way

ernestognw avatar Jul 18 '23 02:07 ernestognw

This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.

github-actions[bot] avatar Oct 16 '23 12:10 github-actions[bot]

Don't close this issue as it's still relevant.

pcaversaccio avatar Oct 16 '23 12:10 pcaversaccio

This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.

github-actions[bot] avatar Jan 15 '24 12:01 github-actions[bot]

Don't close this issue as it's still relevant.

pcaversaccio avatar Jan 15 '24 12:01 pcaversaccio