Skip to content

Commit 307fe6b

Browse files
Merge pull request #594 from protofire/develop
Merge Develop to Master v5.0.3
2 parents c4fa5c9 + 7a28bd9 commit 307fe6b

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [5.0.3] - 2024-08-03
2+
### Fixed
3+
- New Rule: Imports order [#593](https://github.com/protofire/solhint/pull/593)
4+
5+
<br><br>
6+
17
## [5.0.2] - 2024-07-25
28
### Fixed
39
- `func-named-parameters` exclude abi.encodeX from the rule [#583](https://github.com/protofire/solhint/pull/583) (Thanks to [@0xCLARITY](https://github.com/0xCLARITY))

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM node:20-alpine
22
LABEL maintainer="diego.bale@protofire.io"
3-
ENV VERSION=5.0.2
3+
ENV VERSION=5.0.3
44

55
RUN npm install -g solhint@"$VERSION"

docs/rules/naming/func-named-parameters.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ functionName({ sender: '0xA81705c8C247C413a19A244938ae7f4A0393944e', amount: 1e1
5151
functionName({ sender: _senderAddress, amount: 1e18, token: _tokenAddress, receiver: _receiverAddress })
5252
```
5353

54+
#### abi.encodeX call with four UNNAMED parameters
55+
56+
```solidity
57+
abi.encodePacked(_senderAddress, 1e18, _tokenAddress, _receiverAddress )
58+
```
59+
5460
### 👎 Examples of **incorrect** code for this rule
5561

5662
#### Function call with four UNNAMED parameters (default 4)

docs/rules/naming/imports-order.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
2626
### Notes
2727
- Paths starting with "@" like "@openzeppelin/" and urls ("http" and "https") will go first
2828
- Order by hierarchy of directories first, e.g. ./../../ comes before ./../, which comes before ./, which comes before ./foo
29+
- Direct imports come before relative imports
2930
- Order alphabetically for each path at the same level, e.g. ./contract/Zbar.sol comes before ./interface/Ifoo.sol
3031
- Rule does NOT support this kind of import "import * as Alias from "./filename.sol"
3132
- 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"
@@ -34,7 +35,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
3435
This rule does not have examples.
3536

3637
## Version
37-
This rule is introduced in the latest version.
38+
This rule was introduced in [Solhint 5.0.2](https://github.com/protofire/solhint/tree/v5.0.2)
3839

3940
## Resources
4041
- [Rule source](https://github.com/protofire/solhint/tree/master/lib/rules/naming/imports-order.js)

lib/rules/naming/imports-order.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const meta = {
2323
{
2424
note: 'Order by hierarchy of directories first, e.g. ./../../ comes before ./../, which comes before ./, which comes before ./foo',
2525
},
26+
{
27+
note: 'Direct imports come before relative imports',
28+
},
2629
{
2730
note: 'Order alphabetically for each path at the same level, e.g. ./contract/Zbar.sol comes before ./interface/Ifoo.sol',
2831
},
@@ -135,18 +138,25 @@ class ImportsOrderChecker extends BaseChecker {
135138
function getHierarchyLevel(path) {
136139
// put very large numbers so these comes first in precedence
137140
const protocolOrder = {
138-
'@': -30000,
139-
'http://': -20000,
140-
'https://': -10000,
141+
'@': -40000,
142+
'http://': -30000,
143+
'https://': -20000,
144+
// eslint-disable-next-line prettier/prettier
145+
folderPath: -10000,
141146
}
142147

143148
// Check for protocol-specific paths and assign them their respective order levels
144149
for (const protocol in protocolOrder) {
145-
if (path.startsWith(protocol)) {
150+
if (protocol !== 'folderPath' && path.startsWith(protocol)) {
146151
return protocolOrder[protocol]
147152
}
148153
}
149154

155+
// Handling for paths that are likely folder names without a leading './'
156+
if (!path.startsWith('./') && /^[a-zA-Z0-9]/.test(path)) {
157+
return protocolOrder.folderPath
158+
}
159+
150160
// Relative path handling
151161
if (path.startsWith('./')) {
152162
// Count the number of '../' sequences to determine depth

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solhint",
3-
"version": "5.0.2",
3+
"version": "5.0.3",
44
"description": "Solidity Code Linter",
55
"main": "lib/index.js",
66
"keywords": [

0 commit comments

Comments
 (0)