Skip to content

Commit c266ffc

Browse files
mmv08remedcu
andauthored
Lint: add a rule for order import sorting (safe-global#818)
@remedcu [mentioned](safe-global#731 (comment)) that `solhint` now has a rule to sort imports in contracts and we can implement safe-global#731 This PR: - Enables `imports-order` solhint rule and fixes imports across contracts --------- Co-authored-by: Shebin John <[email protected]>
1 parent a7928e8 commit c266ffc

17 files changed

+46
-45
lines changed

.solhint.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"reason-string": "off",
1414
"no-empty-blocks": "off",
1515
"avoid-low-level-calls": "off",
16-
"gas-custom-errors": "off"
16+
"gas-custom-errors": "off",
17+
"imports-order": "warn"
1718
}
1819
}

contracts/Safe.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

4+
import {FallbackManager} from "./base/FallbackManager.sol";
45
import {ITransactionGuard, GuardManager} from "./base/GuardManager.sol";
56
import {ModuleManager} from "./base/ModuleManager.sol";
67
import {OwnerManager} from "./base/OwnerManager.sol";
7-
import {FallbackManager} from "./base/FallbackManager.sol";
88
import {NativeCurrencyPaymentFallback} from "./common/NativeCurrencyPaymentFallback.sol";
9-
import {Singleton} from "./common/Singleton.sol";
10-
import {SignatureDecoder} from "./common/SignatureDecoder.sol";
119
import {SecuredTokenTransfer} from "./common/SecuredTokenTransfer.sol";
10+
import {SignatureDecoder} from "./common/SignatureDecoder.sol";
11+
import {Singleton} from "./common/Singleton.sol";
1212
import {StorageAccessible} from "./common/StorageAccessible.sol";
13-
import {Enum} from "./libraries/Enum.sol";
14-
import {ISignatureValidator, ISignatureValidatorConstants} from "./interfaces/ISignatureValidator.sol";
1513
import {SafeMath} from "./external/SafeMath.sol";
1614
import {ISafe} from "./interfaces/ISafe.sol";
15+
import {ISignatureValidator, ISignatureValidatorConstants} from "./interfaces/ISignatureValidator.sol";
16+
import {Enum} from "./libraries/Enum.sol";
1717

1818
/**
1919
* @title Safe - A multisignature wallet with support for confirmations using signed messages based on EIP-712.

contracts/SafeL2.sol

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

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

119
/**
1210
* @title SafeL2 - An implementation of the Safe contract that emits additional events on transaction executions.

contracts/base/GuardManager.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
/* solhint-disable one-contract-per-file */
33
pragma solidity >=0.7.0 <0.9.0;
44

5-
import {Enum} from "../libraries/Enum.sol";
6-
import {SelfAuthorized} from "../common/SelfAuthorized.sol";
7-
import {IERC165} from "../interfaces/IERC165.sol";
8-
import {IGuardManager} from "../interfaces/IGuardManager.sol";
5+
import {SelfAuthorized} from "./../common/SelfAuthorized.sol";
6+
import {IERC165} from "./../interfaces/IERC165.sol";
7+
import {IGuardManager} from "./../interfaces/IGuardManager.sol";
8+
import {Enum} from "./../libraries/Enum.sol";
99

1010
/**
1111
* @title ITransactionGuard Interface

contracts/base/ModuleManager.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
/* solhint-disable one-contract-per-file */
33
pragma solidity >=0.7.0 <0.9.0;
4-
import {Enum} from "../libraries/Enum.sol";
5-
import {SelfAuthorized} from "../common/SelfAuthorized.sol";
4+
import {SelfAuthorized} from "./../common/SelfAuthorized.sol";
5+
import {IERC165} from "./../interfaces/IERC165.sol";
6+
import {IModuleManager} from "./../interfaces/IModuleManager.sol";
7+
import {Enum} from "./../libraries/Enum.sol";
68
import {Executor} from "./Executor.sol";
7-
import {IModuleManager} from "../interfaces/IModuleManager.sol";
8-
import {IERC165} from "../interfaces/IERC165.sol";
99

1010
/**
1111
* @title IModuleGuard Interface

contracts/examples/guards/BaseGuard.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
3-
import {IERC165} from "../../interfaces/IERC165.sol";
4-
import {BaseTransactionGuard, ITransactionGuard} from "../../base/GuardManager.sol";
5-
import {BaseModuleGuard, IModuleGuard} from "../../base/ModuleManager.sol";
3+
import {BaseTransactionGuard, ITransactionGuard} from "./../../base/GuardManager.sol";
4+
import {BaseModuleGuard, IModuleGuard} from "./../../base/ModuleManager.sol";
5+
import {IERC165} from "./../../interfaces/IERC165.sol";
66

77
/**
88
* @title BaseGuard - Inherits BaseTransactionGuard and BaseModuleGuard.

contracts/examples/guards/DebugTransactionGuard.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

4-
import {Enum} from "../../libraries/Enum.sol";
5-
import {ISafe} from "../../interfaces/ISafe.sol";
4+
import {ISafe} from "./../../interfaces/ISafe.sol";
5+
import {Enum} from "./../../libraries/Enum.sol";
66
import {BaseGuard} from "./BaseGuard.sol";
77
/**
88
* @title Debug Transaction Guard - Emits transaction events with extended information.

contracts/examples/guards/OnlyOwnersGuard.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/* solhint-disable one-contract-per-file */
33
pragma solidity >=0.7.0 <0.9.0;
44

5-
import {Enum} from "../../libraries/Enum.sol";
6-
import {BaseTransactionGuard} from "../../base/GuardManager.sol";
7-
import {ISafe} from "../../interfaces/ISafe.sol";
5+
import {BaseTransactionGuard} from "./../../base/GuardManager.sol";
6+
import {ISafe} from "./../../interfaces/ISafe.sol";
7+
import {Enum} from "./../../libraries/Enum.sol";
88

99
/**
1010
* @title OnlyOwnersGuard - Only allows owners to execute transactions.

contracts/handler/CompatibilityFallbackHandler.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

4-
import {TokenCallbackHandler} from "./TokenCallbackHandler.sol";
5-
import {ISignatureValidator} from "../interfaces/ISignatureValidator.sol";
6-
import {ISafe} from "../interfaces/ISafe.sol";
4+
import {ISafe} from "./../interfaces/ISafe.sol";
5+
import {ISignatureValidator} from "./../interfaces/ISignatureValidator.sol";
76
import {HandlerContext} from "./HandlerContext.sol";
7+
import {TokenCallbackHandler} from "./TokenCallbackHandler.sol";
88

99
/**
1010
* @title Compatibility Fallback Handler - Provides compatibility between pre 1.3.0 and 1.3.0+ Safe Smart Account contracts.

contracts/interfaces/ISafe.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

4-
import {Enum} from "../libraries/Enum.sol";
5-
import {IModuleManager} from "./IModuleManager.sol";
6-
import {IOwnerManager} from "./IOwnerManager.sol";
4+
import {Enum} from "./../libraries/Enum.sol";
75
import {IFallbackManager} from "./IFallbackManager.sol";
86
import {IGuardManager} from "./IGuardManager.sol";
7+
import {IModuleManager} from "./IModuleManager.sol";
8+
import {IOwnerManager} from "./IOwnerManager.sol";
99

1010
/**
1111
* @title ISafe - A multisignature wallet interface with support for confirmations using signed messages based on EIP-712.

contracts/libraries/SafeMigration.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

4-
import {SafeStorage} from "../libraries/SafeStorage.sol";
5-
import {ISafe} from "../interfaces/ISafe.sol";
4+
import {ISafe} from "./../interfaces/ISafe.sol";
5+
import {SafeStorage} from "./../libraries/SafeStorage.sol";
66

77
/**
88
* @title Migration Contract for Safe Upgrade

contracts/libraries/SafeToL2Migration.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/* solhint-disable one-contract-per-file */
33
pragma solidity >=0.7.0 <0.9.0;
44

5-
import {SafeStorage} from "../libraries/SafeStorage.sol";
6-
import {Enum} from "../libraries/Enum.sol";
7-
import {ISafe} from "../interfaces/ISafe.sol";
5+
import {ISafe} from "./../interfaces/ISafe.sol";
6+
import {Enum} from "./../libraries/Enum.sol";
7+
import {SafeStorage} from "./../libraries/SafeStorage.sol";
88

99
/**
1010
* @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.

contracts/libraries/SignMessageLib.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

4+
import {ISafe} from "./../interfaces/ISafe.sol";
45
import {SafeStorage} from "./SafeStorage.sol";
5-
import {ISafe} from "../interfaces/ISafe.sol";
66

77
/**
88
* @title SignMessageLib - Allows to sign messages on-chain by writing the signed message hashes on-chain.

contracts/proxies/SafeProxyFactory.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

4-
import {SafeProxy} from "./SafeProxy.sol";
54
import {IProxyCreationCallback} from "./IProxyCreationCallback.sol";
5+
import {SafeProxy} from "./SafeProxy.sol";
66

77
/**
88
* @title Proxy Factory - Allows to create a new proxy contract and execute a message call to the new proxy within one transaction.

contracts/test/ERC1155Token.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.7.0 <0.9.0;
33

4-
import {ERC1155TokenReceiver} from "../interfaces/ERC1155TokenReceiver.sol";
5-
import {SafeMath} from "../external/SafeMath.sol";
4+
import {SafeMath} from "./../external/SafeMath.sol";
5+
import {ERC1155TokenReceiver} from "./../interfaces/ERC1155TokenReceiver.sol";
66

77
/**
88
* @title ERC1155Token - A test ERC1155 token contract

contracts/test/TestImports.sol

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
pragma solidity >=0.7.0 <0.9.0;
44

55
// Import the contract so hardhat compiles it, and we have the ABI available
6-
// solhint-disable-next-line no-unused-import
7-
import {MockContract} from "@safe-global/mock-contract/contracts/MockContract.sol";
8-
// solhint-disable-next-line no-unused-import
6+
// solhint-disable no-unused-import
97
import {UpgradeableProxy} from "@openzeppelin/contracts/proxy/UpgradeableProxy.sol";
8+
import {MockContract} from "@safe-global/mock-contract/contracts/MockContract.sol";

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
"deploy-all": "hardhat deploy-contracts --network",
2828
"deploy": "hardhat deploy --network",
2929
"lint": "npm run lint:sol && npm run lint:ts",
30+
"lint:fix": "npm run lint:sol:fix && npm run lint:ts:fix",
3031
"lint:sol": "solhint 'contracts/**/*.sol'",
32+
"lint:sol:fix": "solhint --fix 'contracts/**/*.sol'",
3133
"lint:sol:prettier": "prettier 'contracts/**/*.sol' --list-different",
32-
"lint:ts": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
34+
"lint:ts": "eslint 'src/**/*.ts' 'test/**/*.ts'",
35+
"lint:ts:fix": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
3336
"lint:ts:prettier": "prettier 'src/**/*.ts' 'test/**/*.ts' --list-different",
3437
"fmt": "npm run fmt:sol && npm run fmt:ts",
3538
"fmt:sol": "prettier 'contracts/**/*.sol' -w",

0 commit comments

Comments
 (0)