Skip to content

Commit

Permalink
Merge pull request #590 from protofire/develop
Browse files Browse the repository at this point in the history
5.0.2 Develop to Master
  • Loading branch information
dbale-altoros authored Jul 25, 2024
2 parents e20b8c8 + 8012672 commit c4fa5c9
Show file tree
Hide file tree
Showing 22 changed files with 552 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 100
"printWidth": 100,
"bracketSpacing": true
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [5.0.2] - 2024-07-25
### Fixed
- `func-named-parameters` exclude abi.encodeX from the rule [#583](https://github.com/protofire/solhint/pull/583) (Thanks to [@0xCLARITY](https://github.com/0xCLARITY))
- Several typos in comments [#586](https://github.com/protofire/solhint/pull/586) (Thanks to [@dropbigfish](https://github.com/dropbigfish))

### Added
- New Rule: Imports order [#587](https://github.com/protofire/solhint/pull/587)

<br><br>

## [5.0.1] - 2024-05-13
### BREAKING CHANGES (refer to v5.0.0)
Fixed an issue on the returining values where only was evaluating the first report instead of all of them.
Expand Down
1 change: 1 addition & 0 deletions conf/rulesets/solhint-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = Object.freeze({
immutablesAsConstants: true,
},
],
'imports-order': 'warn',
'modifier-name-mixedcase': 'warn',
'named-parameters-mapping': 'warn',
'private-vars-leading-underscore': [
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:20-alpine
LABEL maintainer="[email protected]"
ENV VERSION=5.0.1
ENV VERSION=5.0.2

RUN npm install -g solhint@"$VERSION"
1 change: 1 addition & 0 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ title: "Rule Index of Solhint"
| [func-named-parameters](./rules/naming/func-named-parameters.md) | Enforce named parameters for function calls with 4 or more arguments. This rule may have some false positives | | |
| [func-param-name-mixedcase](./rules/naming/func-param-name-mixedcase.md) | Function param name must be in mixedCase. | | |
| [immutable-vars-naming](./rules/naming/immutable-vars-naming.md) | Check Immutable variables. Capitalized SNAKE_CASE or mixedCase depending on configuration. | $~~~~~~~~$✔️ | |
| [imports-order](./rules/naming/imports-order.md) | Order the imports of the contract to follow a certain hierarchy (read "Notes section") | | |
| [modifier-name-mixedcase](./rules/naming/modifier-name-mixedcase.md) | Modifier name must be in mixedCase. | | |
| [named-parameters-mapping](./rules/naming/named-parameters-mapping.md) | Solidity v0.8.18 introduced named parameters on the mappings definition. | | |
| [private-vars-leading-underscore](./rules/naming/private-vars-leading-underscore.md) | Non-external functions and state variables should start with a single underscore. Others, shouldn't | | |
Expand Down
42 changes: 42 additions & 0 deletions docs/rules/naming/imports-order.md
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)
2 changes: 1 addition & 1 deletion docs/rules/naming/named-parameters-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mapping(string name => uint256 balance) public users;
mapping(address owner => mapping(address token => uint256 balance)) public tokenBalances;
```

#### Main key of mapping is enforced. On nested mappings other naming are not neccesary
#### Main key of mapping is enforced. On nested mappings other naming are not necessary

```solidity
mapping(address owner => mapping(address => uint256)) public tokenBalances;
Expand Down
5 changes: 5 additions & 0 deletions e2e/08-autofix/imports-order/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"imports-order": "error"
}
}
25 changes: 25 additions & 0 deletions e2e/08-autofix/imports-order/Foo1.sol
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() {}
}
25 changes: 25 additions & 0 deletions e2e/08-autofix/imports-order/Foo1AfterFix.sol
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() {}
}
25 changes: 25 additions & 0 deletions e2e/08-autofix/imports-order/Foo1BeforeFix.sol
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() {}
}
19 changes: 19 additions & 0 deletions e2e/08-autofix/imports-order/Foo2.sol
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() {}
}
19 changes: 19 additions & 0 deletions e2e/08-autofix/imports-order/Foo2AfterFix.sol
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() {}
}
19 changes: 19 additions & 0 deletions e2e/08-autofix/imports-order/Foo2BeforeFix.sol
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() {}
}
Loading

0 comments on commit c4fa5c9

Please sign in to comment.