From 0f0f313c0d109ee4af61ca98a20248abd1ec916a Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Sat, 3 Aug 2024 00:10:11 -0300 Subject: [PATCH 1/4] fix: imports-order for direct paths --- lib/rules/naming/imports-order.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/rules/naming/imports-order.js b/lib/rules/naming/imports-order.js index 6d3a255e..8605f18b 100644 --- a/lib/rules/naming/imports-order.js +++ b/lib/rules/naming/imports-order.js @@ -23,6 +23,9 @@ const meta = { { note: 'Order by hierarchy of directories first, e.g. ./../../ comes before ./../, which comes before ./, which comes before ./foo', }, + { + note: 'Direct imports come before relative imports', + }, { note: 'Order alphabetically for each path at the same level, e.g. ./contract/Zbar.sol comes before ./interface/Ifoo.sol', }, @@ -72,10 +75,10 @@ class ImportsOrderChecker extends BaseChecker { this.orderedImports = this.sortImports(this.orderedImports) // console.log('this.orderedImports :>> ', this.fromContractImports) - // console.log('NO Order: \n') - // this.fromContractImports.forEach((importItem) => console.log(importItem.fullSentence)) - // console.log('\n\nOrdered: \n') - // this.orderedImports.forEach((importItem) => console.log(importItem.fullSentence)) + console.log('NO Order: \n') + this.fromContractImports.forEach((importItem) => console.log(importItem.fullSentence)) + console.log('\n\nOrdered: \n') + this.orderedImports.forEach((importItem) => console.log(importItem.fullSentence)) } 'SourceUnit:exit'(node) { @@ -135,18 +138,25 @@ class ImportsOrderChecker extends BaseChecker { function getHierarchyLevel(path) { // put very large numbers so these comes first in precedence const protocolOrder = { - '@': -30000, - 'http://': -20000, - 'https://': -10000, + '@': -40000, + 'http://': -30000, + 'https://': -20000, + // eslint-disable-next-line prettier/prettier + folderPath: -10000, } // Check for protocol-specific paths and assign them their respective order levels for (const protocol in protocolOrder) { - if (path.startsWith(protocol)) { + if (protocol !== 'folderPath' && path.startsWith(protocol)) { return protocolOrder[protocol] } } + // Handling for paths that are likely folder names without a leading './' + if (!path.startsWith('./') && /^[a-zA-Z0-9]/.test(path)) { + return protocolOrder.folderPath + } + // Relative path handling if (path.startsWith('./')) { // Count the number of '../' sequences to determine depth From e06930b594cefd1127d0043723cfa0cbda547a6a Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Sat, 3 Aug 2024 00:10:23 -0300 Subject: [PATCH 2/4] fix: imports-order for direct paths --- docs/rules/naming/func-named-parameters.md | 6 ++++++ docs/rules/naming/imports-order.md | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/rules/naming/func-named-parameters.md b/docs/rules/naming/func-named-parameters.md index 44fe7da6..88b660f9 100644 --- a/docs/rules/naming/func-named-parameters.md +++ b/docs/rules/naming/func-named-parameters.md @@ -51,6 +51,12 @@ functionName({ sender: '0xA81705c8C247C413a19A244938ae7f4A0393944e', amount: 1e1 functionName({ sender: _senderAddress, amount: 1e18, token: _tokenAddress, receiver: _receiverAddress }) ``` +#### abi.encodeX call with four UNNAMED parameters + +```solidity +abi.encodePacked(_senderAddress, 1e18, _tokenAddress, _receiverAddress ) +``` + ### 👎 Examples of **incorrect** code for this rule #### Function call with four UNNAMED parameters (default 4) diff --git a/docs/rules/naming/imports-order.md b/docs/rules/naming/imports-order.md index b5322754..484934b6 100644 --- a/docs/rules/naming/imports-order.md +++ b/docs/rules/naming/imports-order.md @@ -26,6 +26,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war ### 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 +- Direct imports come before relative imports - 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" @@ -34,7 +35,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war This rule does not have examples. ## Version -This rule is introduced in the latest version. +This rule was introduced in [Solhint 5.0.2](https://github.com/protofire/solhint/tree/v5.0.2) ## Resources - [Rule source](https://github.com/protofire/solhint/tree/master/lib/rules/naming/imports-order.js) From 476679a0e3587a61f17c95ffdd59dd100c3dad0f Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Sat, 3 Aug 2024 00:14:21 -0300 Subject: [PATCH 3/4] fix: imports-order for direct paths --- lib/rules/naming/imports-order.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rules/naming/imports-order.js b/lib/rules/naming/imports-order.js index 8605f18b..77807d37 100644 --- a/lib/rules/naming/imports-order.js +++ b/lib/rules/naming/imports-order.js @@ -75,10 +75,10 @@ class ImportsOrderChecker extends BaseChecker { this.orderedImports = this.sortImports(this.orderedImports) // console.log('this.orderedImports :>> ', this.fromContractImports) - console.log('NO Order: \n') - this.fromContractImports.forEach((importItem) => console.log(importItem.fullSentence)) - console.log('\n\nOrdered: \n') - this.orderedImports.forEach((importItem) => console.log(importItem.fullSentence)) + // console.log('NO Order: \n') + // this.fromContractImports.forEach((importItem) => console.log(importItem.fullSentence)) + // console.log('\n\nOrdered: \n') + // this.orderedImports.forEach((importItem) => console.log(importItem.fullSentence)) } 'SourceUnit:exit'(node) { From 534b6ddc239b80fe77398fca36c767a786e85960 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Sat, 3 Aug 2024 14:45:55 -0300 Subject: [PATCH 4/4] fix: imports-order for direct paths --- CHANGELOG.md | 6 ++++++ docker/Dockerfile | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e91fe0a..f0304637 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [5.0.3] - 2024-08-03 +### Fixed +- New Rule: Imports order [#593](https://github.com/protofire/solhint/pull/593) + +

+ ## [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)) diff --git a/docker/Dockerfile b/docker/Dockerfile index e7af3f49..61c9a8c3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ FROM node:20-alpine LABEL maintainer="diego.bale@protofire.io" -ENV VERSION=5.0.2 +ENV VERSION=5.0.3 RUN npm install -g solhint@"$VERSION" \ No newline at end of file diff --git a/package.json b/package.json index bb17a54e..74324f37 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solhint", - "version": "5.0.2", + "version": "5.0.3", "description": "Solidity Code Linter", "main": "lib/index.js", "keywords": [