-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #587 from protofire/import-order-rule
ADD: Import order rule
- Loading branch information
Showing
14 changed files
with
512 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 100 | ||
"printWidth": 100, | ||
"bracketSpacing": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
warning: "This is a dynamically generated file. Do not edit manually." | ||
layout: "default" | ||
title: "imports-order | Solhint" | ||
--- | ||
|
||
# imports-order | ||
![Category Badge](https://img.shields.io/badge/-Style%20Guide%20Rules-informational) | ||
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow) | ||
|
||
## Description | ||
Order the imports of the contract to follow a certain hierarchy (read "Notes section") | ||
|
||
## Options | ||
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn. | ||
|
||
### Example Config | ||
```json | ||
{ | ||
"rules": { | ||
"imports-order": "warn" | ||
} | ||
} | ||
``` | ||
|
||
### Notes | ||
- Paths starting with "@" like "@openzeppelin/" and urls ("http" and "https") will go first | ||
- Order by hierarchy of directories first, e.g. ./../../ comes before ./../, which comes before ./, which comes before ./foo | ||
- Order alphabetically for each path at the same level, e.g. ./contract/Zbar.sol comes before ./interface/Ifoo.sol | ||
- Rule does NOT support this kind of import "import * as Alias from "./filename.sol" | ||
- When "--fix", rule will re-write this notation "../folder/file.sol" or this one "../file.sol" to "./../folder/file.sol" or this one "./../file.sol" | ||
|
||
## Examples | ||
This rule does not have examples. | ||
|
||
## Version | ||
This rule is introduced in the latest version. | ||
|
||
## Resources | ||
- [Rule source](https://github.com/protofire/solhint/tree/master/lib/rules/naming/imports-order.js) | ||
- [Document source](https://github.com/protofire/solhint/tree/master/docs/rules/naming/imports-order.md) | ||
- [Test cases](https://github.com/protofire/solhint/tree/master/test/rules/naming/imports-order.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"imports-order": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import './ThisIsAVeryLongFileOnPurposeToTestTheFirstPathShorterThanTheLastOnelooooooooooong.sol'; | ||
import { Unauthorized, add as func, Point } from './Foo.sol'; | ||
import 'https://github.com/owner/repo/blob/branch/path/to/Contract.sol'; | ||
import { Initializable } from './openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import '../../../../token/interfaces/FakeContract1.sol'; | ||
import { FakeContract3 } from '../../../token/interfaces/FakeContract3.sol'; | ||
import './../../../../token/interfaces/AFakeContract1.sol'; | ||
import './../token/interfaces/IXTokenWrapper.sol'; | ||
import { IXTokenFactory, holaquetal } from '../../token/interfaces/IXTokenFactory.sol'; | ||
import './../../bpath/otherfolder/otherfolder/aContract.sol'; | ||
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; | ||
import { FakeContract2 } from '../../../token/interfaces/FakeContract2.sol'; | ||
import '../../apath/zContract.sol'; | ||
import 'http://github.com/owner/repo/blob/branch/path/to/Contract2.sol'; | ||
import { Afool1 } from './Afool1.sol'; | ||
import './Ownable.sol'; | ||
import { IXTokenWrapper2 } from '../token/interfaces/IXTokenWrapper2.sol'; | ||
import { ReentrancyGuardUpgradeable2 } from '@apenzeppelin/ReentrancyGuardUpgradeable2.sol'; | ||
|
||
contract ImportsOrder { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import { ReentrancyGuardUpgradeable2 } from '@apenzeppelin/ReentrancyGuardUpgradeable2.sol'; | ||
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; | ||
import 'http://github.com/owner/repo/blob/branch/path/to/Contract2.sol'; | ||
import 'https://github.com/owner/repo/blob/branch/path/to/Contract.sol'; | ||
import './../../../../token/interfaces/AFakeContract1.sol'; | ||
import './../../../../token/interfaces/FakeContract1.sol'; | ||
import { FakeContract2 } from './../../../token/interfaces/FakeContract2.sol'; | ||
import { FakeContract3 } from './../../../token/interfaces/FakeContract3.sol'; | ||
import './../../apath/zContract.sol'; | ||
import './../../bpath/otherfolder/otherfolder/aContract.sol'; | ||
import { IXTokenFactory, holaquetal } from './../../token/interfaces/IXTokenFactory.sol'; | ||
import './../token/interfaces/IXTokenWrapper.sol'; | ||
import { IXTokenWrapper2 } from './../token/interfaces/IXTokenWrapper2.sol'; | ||
import { Afool1 } from './Afool1.sol'; | ||
import { Unauthorized, add as func, Point } from './Foo.sol'; | ||
import { Initializable } from './openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import './Ownable.sol'; | ||
import './ThisIsAVeryLongFileOnPurposeToTestTheFirstPathShorterThanTheLastOnelooooooooooong.sol'; | ||
|
||
contract ImportsOrder { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import './ThisIsAVeryLongFileOnPurposeToTestTheFirstPathShorterThanTheLastOnelooooooooooong.sol'; | ||
import { Unauthorized, add as func, Point } from './Foo.sol'; | ||
import 'https://github.com/owner/repo/blob/branch/path/to/Contract.sol'; | ||
import { Initializable } from './openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import '../../../../token/interfaces/FakeContract1.sol'; | ||
import { FakeContract3 } from '../../../token/interfaces/FakeContract3.sol'; | ||
import './../../../../token/interfaces/AFakeContract1.sol'; | ||
import './../token/interfaces/IXTokenWrapper.sol'; | ||
import { IXTokenFactory, holaquetal } from '../../token/interfaces/IXTokenFactory.sol'; | ||
import './../../bpath/otherfolder/otherfolder/aContract.sol'; | ||
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; | ||
import { FakeContract2 } from '../../../token/interfaces/FakeContract2.sol'; | ||
import '../../apath/zContract.sol'; | ||
import 'http://github.com/owner/repo/blob/branch/path/to/Contract2.sol'; | ||
import { Afool1 } from './Afool1.sol'; | ||
import './Ownable.sol'; | ||
import { IXTokenWrapper2 } from '../token/interfaces/IXTokenWrapper2.sol'; | ||
import { ReentrancyGuardUpgradeable2 } from '@apenzeppelin/ReentrancyGuardUpgradeable2.sol'; | ||
|
||
contract ImportsOrder { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import './ThisIsAVeryLongFileOnPurposeToTestTheFirstPathShorterThanTheLastOnelooooooooooong.sol'; | ||
import '../../../../../token/interfaces/IXTokenWrapper3.sol'; | ||
import {IXTokenFactory2} from '../../atoken/interfaces/IXTokenFactory2.sol'; | ||
import {Initializable} from './openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import '../../../../token/interfaces/FakeContract1.sol'; | ||
import '../token/interfaces/IXTokenWrapper.sol'; | ||
import {IXTokenFactory, holaquetal} from '../../token/interfaces/IXTokenFactory.sol'; | ||
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; | ||
import {FakeContract2} from '../../../token/interfaces/FakeContract2.sol'; | ||
import {Afool1} from './Afool1.sol'; | ||
import {IXTokenWrapper2} from '../token/interfaces/IXTokenWrapper2.sol'; | ||
import {ReentrancyGuardUpgradeable2} from '@apenzeppelin/ReentrancyGuardUpgradeable2.sol'; | ||
|
||
contract ImportsOrder2 { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import {ReentrancyGuardUpgradeable2} from '@apenzeppelin/ReentrancyGuardUpgradeable2.sol'; | ||
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; | ||
import '../../../../../token/interfaces/IXTokenWrapper3.sol'; | ||
import '../../../../token/interfaces/FakeContract1.sol'; | ||
import {FakeContract2} from '../../../token/interfaces/FakeContract2.sol'; | ||
import {IXTokenFactory2} from '../../atoken/interfaces/IXTokenFactory2.sol'; | ||
import {IXTokenFactory, holaquetal} from '../../token/interfaces/IXTokenFactory.sol'; | ||
import '../token/interfaces/IXTokenWrapper.sol'; | ||
import {IXTokenWrapper2} from '../token/interfaces/IXTokenWrapper2.sol'; | ||
import {Initializable} from './openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import {Afool1} from './Afool1.sol'; | ||
import './ThisIsAVeryLongFileOnPurposeToTestTheFirstPathShorterThanTheLastOnelooooooooooong.sol'; | ||
|
||
contract ImportsOrder2 { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import './ThisIsAVeryLongFileOnPurposeToTestTheFirstPathShorterThanTheLastOnelooooooooooong.sol'; | ||
import '../../../../../token/interfaces/IXTokenWrapper3.sol'; | ||
import {IXTokenFactory2} from '../../atoken/interfaces/IXTokenFactory2.sol'; | ||
import {Initializable} from './openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import '../../../../token/interfaces/FakeContract1.sol'; | ||
import '../token/interfaces/IXTokenWrapper.sol'; | ||
import {IXTokenFactory, holaquetal} from '../../token/interfaces/IXTokenFactory.sol'; | ||
import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; | ||
import {FakeContract2} from '../../../token/interfaces/FakeContract2.sol'; | ||
import {Afool1} from './Afool1.sol'; | ||
import {IXTokenWrapper2} from '../token/interfaces/IXTokenWrapper2.sol'; | ||
import {ReentrancyGuardUpgradeable2} from '@apenzeppelin/ReentrancyGuardUpgradeable2.sol'; | ||
|
||
contract ImportsOrder2 { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.