Skip to content

Commit

Permalink
Lint: add a rule for order import sorting (#818)
Browse files Browse the repository at this point in the history
@remedcu
[mentioned](#731 (comment))
that `solhint` now has a rule to sort imports in contracts and we can
implement #731

This PR:
- Enables `imports-order` solhint rule and fixes imports across
contracts

---------

Co-authored-by: Shebin John <[email protected]>
  • Loading branch information
mmv08 and remedcu authored Aug 29, 2024
1 parent a7928e8 commit c266ffc
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"reason-string": "off",
"no-empty-blocks": "off",
"avoid-low-level-calls": "off",
"gas-custom-errors": "off"
"gas-custom-errors": "off",
"imports-order": "warn"
}
}
10 changes: 5 additions & 5 deletions contracts/Safe.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {FallbackManager} from "./base/FallbackManager.sol";
import {ITransactionGuard, GuardManager} from "./base/GuardManager.sol";
import {ModuleManager} from "./base/ModuleManager.sol";
import {OwnerManager} from "./base/OwnerManager.sol";
import {FallbackManager} from "./base/FallbackManager.sol";
import {NativeCurrencyPaymentFallback} from "./common/NativeCurrencyPaymentFallback.sol";
import {Singleton} from "./common/Singleton.sol";
import {SignatureDecoder} from "./common/SignatureDecoder.sol";
import {SecuredTokenTransfer} from "./common/SecuredTokenTransfer.sol";
import {SignatureDecoder} from "./common/SignatureDecoder.sol";
import {Singleton} from "./common/Singleton.sol";
import {StorageAccessible} from "./common/StorageAccessible.sol";
import {Enum} from "./libraries/Enum.sol";
import {ISignatureValidator, ISignatureValidatorConstants} from "./interfaces/ISignatureValidator.sol";
import {SafeMath} from "./external/SafeMath.sol";
import {ISafe} from "./interfaces/ISafe.sol";
import {ISignatureValidator, ISignatureValidatorConstants} from "./interfaces/ISignatureValidator.sol";
import {Enum} from "./libraries/Enum.sol";

/**
* @title Safe - A multisignature wallet with support for confirmations using signed messages based on EIP-712.
Expand Down
6 changes: 2 additions & 4 deletions contracts/SafeL2.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {Safe, Enum} from "./Safe.sol";

// Imports are required for NatSpec validation of the compiler, and falsely detected as unused by
// the linter, so disable the `no-unused-imports` rule for the next line.
// The import is used in the @inheritdoc, false positive
// solhint-disable-next-line no-unused-import
import {ModuleManager} from "./base/ModuleManager.sol";
import {Safe, Enum} from "./Safe.sol";

/**
* @title SafeL2 - An implementation of the Safe contract that emits additional events on transaction executions.
Expand Down
8 changes: 4 additions & 4 deletions contracts/base/GuardManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/* solhint-disable one-contract-per-file */
pragma solidity >=0.7.0 <0.9.0;

import {Enum} from "../libraries/Enum.sol";
import {SelfAuthorized} from "../common/SelfAuthorized.sol";
import {IERC165} from "../interfaces/IERC165.sol";
import {IGuardManager} from "../interfaces/IGuardManager.sol";
import {SelfAuthorized} from "./../common/SelfAuthorized.sol";
import {IERC165} from "./../interfaces/IERC165.sol";
import {IGuardManager} from "./../interfaces/IGuardManager.sol";
import {Enum} from "./../libraries/Enum.sol";

/**
* @title ITransactionGuard Interface
Expand Down
8 changes: 4 additions & 4 deletions contracts/base/ModuleManager.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: LGPL-3.0-only
/* solhint-disable one-contract-per-file */
pragma solidity >=0.7.0 <0.9.0;
import {Enum} from "../libraries/Enum.sol";
import {SelfAuthorized} from "../common/SelfAuthorized.sol";
import {SelfAuthorized} from "./../common/SelfAuthorized.sol";
import {IERC165} from "./../interfaces/IERC165.sol";
import {IModuleManager} from "./../interfaces/IModuleManager.sol";
import {Enum} from "./../libraries/Enum.sol";
import {Executor} from "./Executor.sol";
import {IModuleManager} from "../interfaces/IModuleManager.sol";
import {IERC165} from "../interfaces/IERC165.sol";

/**
* @title IModuleGuard Interface
Expand Down
6 changes: 3 additions & 3 deletions contracts/examples/guards/BaseGuard.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
import {IERC165} from "../../interfaces/IERC165.sol";
import {BaseTransactionGuard, ITransactionGuard} from "../../base/GuardManager.sol";
import {BaseModuleGuard, IModuleGuard} from "../../base/ModuleManager.sol";
import {BaseTransactionGuard, ITransactionGuard} from "./../../base/GuardManager.sol";
import {BaseModuleGuard, IModuleGuard} from "./../../base/ModuleManager.sol";
import {IERC165} from "./../../interfaces/IERC165.sol";

/**
* @title BaseGuard - Inherits BaseTransactionGuard and BaseModuleGuard.
Expand Down
4 changes: 2 additions & 2 deletions contracts/examples/guards/DebugTransactionGuard.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {Enum} from "../../libraries/Enum.sol";
import {ISafe} from "../../interfaces/ISafe.sol";
import {ISafe} from "./../../interfaces/ISafe.sol";
import {Enum} from "./../../libraries/Enum.sol";
import {BaseGuard} from "./BaseGuard.sol";
/**
* @title Debug Transaction Guard - Emits transaction events with extended information.
Expand Down
6 changes: 3 additions & 3 deletions contracts/examples/guards/OnlyOwnersGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* solhint-disable one-contract-per-file */
pragma solidity >=0.7.0 <0.9.0;

import {Enum} from "../../libraries/Enum.sol";
import {BaseTransactionGuard} from "../../base/GuardManager.sol";
import {ISafe} from "../../interfaces/ISafe.sol";
import {BaseTransactionGuard} from "./../../base/GuardManager.sol";
import {ISafe} from "./../../interfaces/ISafe.sol";
import {Enum} from "./../../libraries/Enum.sol";

/**
* @title OnlyOwnersGuard - Only allows owners to execute transactions.
Expand Down
6 changes: 3 additions & 3 deletions contracts/handler/CompatibilityFallbackHandler.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {TokenCallbackHandler} from "./TokenCallbackHandler.sol";
import {ISignatureValidator} from "../interfaces/ISignatureValidator.sol";
import {ISafe} from "../interfaces/ISafe.sol";
import {ISafe} from "./../interfaces/ISafe.sol";
import {ISignatureValidator} from "./../interfaces/ISignatureValidator.sol";
import {HandlerContext} from "./HandlerContext.sol";
import {TokenCallbackHandler} from "./TokenCallbackHandler.sol";

/**
* @title Compatibility Fallback Handler - Provides compatibility between pre 1.3.0 and 1.3.0+ Safe Smart Account contracts.
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/ISafe.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {Enum} from "../libraries/Enum.sol";
import {IModuleManager} from "./IModuleManager.sol";
import {IOwnerManager} from "./IOwnerManager.sol";
import {Enum} from "./../libraries/Enum.sol";
import {IFallbackManager} from "./IFallbackManager.sol";
import {IGuardManager} from "./IGuardManager.sol";
import {IModuleManager} from "./IModuleManager.sol";
import {IOwnerManager} from "./IOwnerManager.sol";

/**
* @title ISafe - A multisignature wallet interface with support for confirmations using signed messages based on EIP-712.
Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/SafeMigration.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {SafeStorage} from "../libraries/SafeStorage.sol";
import {ISafe} from "../interfaces/ISafe.sol";
import {ISafe} from "./../interfaces/ISafe.sol";
import {SafeStorage} from "./../libraries/SafeStorage.sol";

/**
* @title Migration Contract for Safe Upgrade
Expand Down
6 changes: 3 additions & 3 deletions contracts/libraries/SafeToL2Migration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* solhint-disable one-contract-per-file */
pragma solidity >=0.7.0 <0.9.0;

import {SafeStorage} from "../libraries/SafeStorage.sol";
import {Enum} from "../libraries/Enum.sol";
import {ISafe} from "../interfaces/ISafe.sol";
import {ISafe} from "./../interfaces/ISafe.sol";
import {Enum} from "./../libraries/Enum.sol";
import {SafeStorage} from "./../libraries/SafeStorage.sol";

/**
* @title Migration Contract for updating a Safe from 1.1.1/1.3.0/1.4.1 versions to a L2 version. Useful when replaying a Safe from a non L2 network in a L2 network.
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/SignMessageLib.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {ISafe} from "./../interfaces/ISafe.sol";
import {SafeStorage} from "./SafeStorage.sol";
import {ISafe} from "../interfaces/ISafe.sol";

/**
* @title SignMessageLib - Allows to sign messages on-chain by writing the signed message hashes on-chain.
Expand Down
2 changes: 1 addition & 1 deletion contracts/proxies/SafeProxyFactory.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {SafeProxy} from "./SafeProxy.sol";
import {IProxyCreationCallback} from "./IProxyCreationCallback.sol";
import {SafeProxy} from "./SafeProxy.sol";

/**
* @title Proxy Factory - Allows to create a new proxy contract and execute a message call to the new proxy within one transaction.
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/ERC1155Token.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import {ERC1155TokenReceiver} from "../interfaces/ERC1155TokenReceiver.sol";
import {SafeMath} from "../external/SafeMath.sol";
import {SafeMath} from "./../external/SafeMath.sol";
import {ERC1155TokenReceiver} from "./../interfaces/ERC1155TokenReceiver.sol";

/**
* @title ERC1155Token - A test ERC1155 token contract
Expand Down
5 changes: 2 additions & 3 deletions contracts/test/TestImports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity >=0.7.0 <0.9.0;

// Import the contract so hardhat compiles it, and we have the ABI available
// solhint-disable-next-line no-unused-import
import {MockContract} from "@safe-global/mock-contract/contracts/MockContract.sol";
// solhint-disable-next-line no-unused-import
// solhint-disable no-unused-import
import {UpgradeableProxy} from "@openzeppelin/contracts/proxy/UpgradeableProxy.sol";
import {MockContract} from "@safe-global/mock-contract/contracts/MockContract.sol";
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
"deploy-all": "hardhat deploy-contracts --network",
"deploy": "hardhat deploy --network",
"lint": "npm run lint:sol && npm run lint:ts",
"lint:fix": "npm run lint:sol:fix && npm run lint:ts:fix",
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint:sol:fix": "solhint --fix 'contracts/**/*.sol'",
"lint:sol:prettier": "prettier 'contracts/**/*.sol' --list-different",
"lint:ts": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
"lint:ts": "eslint 'src/**/*.ts' 'test/**/*.ts'",
"lint:ts:fix": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
"lint:ts:prettier": "prettier 'src/**/*.ts' 'test/**/*.ts' --list-different",
"fmt": "npm run fmt:sol && npm run fmt:ts",
"fmt:sol": "prettier 'contracts/**/*.sol' -w",
Expand Down

0 comments on commit c266ffc

Please sign in to comment.