Skip to content

Commit 37f5082

Browse files
Merge pull request #563 from protofire/develop
Merge into master: v4.5.0
2 parents 2738047 + 6ae3f4b commit 37f5082

File tree

71 files changed

+4874
-1139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4874
-1139
lines changed

CHANGELOG.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
1+
2+
## [4.5.0] - 2024-03-15
3+
4+
### Updated
5+
- Update dependencies in package json [#548](https://github.com/protofire/solhint/pull/548)
6+
- Custom errors rules checks from 0.8.4 forward before warning [#555](https://github.com/protofire/solhint/pull/555)
7+
- Parser support up to Solidity 0.8.22 (*)
8+
9+
(*) Note: Solhint can work with latest Solidity versions.
10+
If new grammar/syntax is added or changed, it could give some false positives or miss a rule.
11+
But overall functionality will work as expected.
12+
13+
14+
### Added
15+
- New Rule: Interface starts with `i` [#557](https://github.com/protofire/solhint/pull/557)
16+
17+
#### Gas Consumption Rules
18+
- New Rule: [GC] Mutlitoken1155 rule [#541](https://github.com/protofire/solhint/pull/541)
19+
- New Rule: [GC] Small strings check [#542](https://github.com/protofire/solhint/pull/542)
20+
- New Rule: [GC] Indexed events [#543](https://github.com/protofire/solhint/pull/543)
21+
- New Rule: [GC] Calldata parameters [#544](https://github.com/protofire/solhint/pull/544)
22+
- New Rule: [GC] Increment by one [#545](https://github.com/protofire/solhint/pull/545)
23+
- New Rule: [GC] Struct packing [#546](https://github.com/protofire/solhint/pull/546)
24+
- New Rule: [GC] Name Return Values [#552](https://github.com/protofire/solhint/pull/552)
25+
- New Rule: [GC] Custom Errors #553 [#555](https://github.com/protofire/solhint/pull/553)
26+
- New Rule: [GC] Dot Length in Loops [#559](https://github.com/protofire/solhint/pull/559)
27+
- New Rule: [GC] Gas Strict Inequalities [#560](https://github.com/protofire/solhint/pull/560)
28+
29+
30+
### Fixed
31+
- `explicit-types` logic improved and bug free [#551](https://github.com/protofire/solhint/pull/551)
32+
- `payable fallback` Improved behavior [#561](https://github.com/protofire/solhint/pull/561)
33+
34+
35+
36+
### BREAKING CHANGES
37+
- `named-return-values` rule was renamed to gas-named-return-values and now it is part of Gas Consumption ruleset [#552](https://github.com/protofire/solhint/pull/552)
38+
- `custom-errors` rule was renamed to gas-custom-errors and now it is part of Gas Consumption ruleset [#553](https://github.com/protofire/solhint/pull/553)
39+
- Return error 0 when executed correctly [#554](https://github.com/protofire/solhint/pull/554)
40+
- Default severity modified to `WARN` instead of `OFF` for
41+
`foundry-test-functions` and `named-parameters-mapping` rules [#556](https://github.com/protofire/solhint/pull/556)
42+
43+
44+
45+
146
## [4.1.1] - 2024-01-08
247

348
### Fixed
449
- Fix changelog typos
550

651

7-
852
## [4.1.0] - 2024-01-08
953

1054
### Updated

conf/rulesets/solhint-all.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
module.exports = Object.freeze({
77
rules: {
88
'code-complexity': ['warn', 7],
9-
'custom-errors': 'warn',
109
'explicit-types': ['warn', 'explicit'],
1110
'function-max-lines': ['warn', 50],
11+
'interface-starts-with-i': 'warn',
1212
'max-line-length': ['error', 120],
1313
'max-states-count': ['warn', 15],
1414
'no-console': 'error',
@@ -25,12 +25,22 @@ module.exports = Object.freeze({
2525
},
2626
],
2727
'constructor-syntax': 'warn',
28+
'gas-calldata-parameters': 'warn',
29+
'gas-custom-errors': 'warn',
30+
'gas-increment-by-one': 'warn',
31+
'gas-indexed-events': 'warn',
32+
'gas-length-in-loops': 'warn',
33+
'gas-multitoken1155': 'warn',
34+
'gas-named-return-values': 'warn',
35+
'gas-small-strings': 'warn',
36+
'gas-strict-inequalities': 'warn',
37+
'gas-struct-packing': 'warn',
2838
'comprehensive-interface': 'warn',
2939
quotes: ['error', 'double'],
3040
'const-name-snakecase': 'warn',
3141
'contract-name-camelcase': 'warn',
3242
'event-name-camelcase': 'warn',
33-
'foundry-test-functions': ['off', ['setUp']],
43+
'foundry-test-functions': ['warn', ['setUp']],
3444
'func-name-mixedcase': 'warn',
3545
'func-named-parameters': ['warn', 4],
3646
'func-param-name-mixedcase': 'warn',
@@ -41,8 +51,7 @@ module.exports = Object.freeze({
4151
},
4252
],
4353
'modifier-name-mixedcase': 'warn',
44-
'named-parameters-mapping': 'off',
45-
'named-return-values': 'warn',
54+
'named-parameters-mapping': 'warn',
4655
'private-vars-leading-underscore': [
4756
'warn',
4857
{

conf/rulesets/solhint-recommended.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
module.exports = Object.freeze({
77
rules: {
8-
'custom-errors': 'warn',
98
'explicit-types': ['warn', 'explicit'],
109
'max-states-count': ['warn', 15],
1110
'no-console': 'error',
@@ -21,6 +20,7 @@ module.exports = Object.freeze({
2120
maxLength: 32,
2221
},
2322
],
23+
'gas-custom-errors': 'warn',
2424
quotes: ['error', 'double'],
2525
'const-name-snakecase': 'warn',
2626
'contract-name-camelcase': 'warn',

docs/rules.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ title: "Rule Index of Solhint"
99
| Rule Id | Error | Recommended | Deprecated |
1010
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------ | ---------- |
1111
| [code-complexity](./rules/best-practises/code-complexity.md) | Function has cyclomatic complexity "current" but allowed no more than maxcompl. | | |
12-
| [custom-errors](./rules/best-practises/custom-errors.md) | Enforces the use of Custom Errors over Require and Revert statements | $~~~~~~~~$✔️ | |
1312
| [explicit-types](./rules/best-practises/explicit-types.md) | Forbid or enforce explicit types (like uint256) that have an alias (like uint). | $~~~~~~~~$✔️ | |
1413
| [function-max-lines](./rules/best-practises/function-max-lines.md) | Function body contains "count" lines but allowed no more than maxlines. | | |
1514
| [max-line-length](./rules/best-practises/max-line-length.md) | Line length must be no more than maxlen. | | |
@@ -20,23 +19,16 @@ title: "Rule Index of Solhint"
2019
| [no-unused-import](./rules/best-practises/no-unused-import.md) | Imported object name is not being used by the contract. | $~~~~~~~~$✔️ | |
2120
| [no-unused-vars](./rules/best-practises/no-unused-vars.md) | Variable "name" is unused. | $~~~~~~~~$✔️ | |
2221
| [one-contract-per-file](./rules/best-practises/one-contract-per-file.md) | Enforces the use of ONE Contract per file see [here](https://docs.soliditylang.org/en/v0.8.21/style-guide.html#contract-and-library-names) | $~~~~~~~~$✔️ | |
23-
| [payable-fallback](./rules/best-practises/payable-fallback.md) | When fallback is not payable you will not be able to receive ethers. | $~~~~~~~~$✔️ | |
22+
| [payable-fallback](./rules/best-practises/payable-fallback.md) | When fallback is not payable and there is no receive function you will not be able to receive currency. | $~~~~~~~~$✔️ | |
2423
| [reason-string](./rules/best-practises/reason-string.md) | Require or revert statement must have a reason string and check that each reason string is at most N characters long. | $~~~~~~~~$✔️ | |
2524
| [constructor-syntax](./rules/best-practises/constructor-syntax.md) | Constructors should use the new constructor keyword. | | |
2625
2726

28-
## Miscellaneous
29-
30-
| Rule Id | Error | Recommended | Deprecated |
31-
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- |
32-
| [comprehensive-interface](./rules/miscellaneous/comprehensive-interface.md) | Check that all public or external functions are override. This is iseful to make sure that the whole API is extracted in an interface. | | |
33-
| [quotes](./rules/miscellaneous/quotes.md) | Enforces the use of double or simple quotes as configured for string literals. Values must be 'single' or 'double'. | $~~~~~~~~$✔️ | |
34-
35-
3627
## Style Guide Rules
3728

3829
| Rule Id | Error | Recommended | Deprecated |
3930
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | ------------ | ----------- |
31+
| [interface-starts-with-i](./rules/naming/interface-starts-with-i.md) | Solidity Interfaces names should start with an `I` | | |
4032
| [const-name-snakecase](./rules/naming/const-name-snakecase.md) | Constant name must be in capitalized SNAKE_CASE. (Does not check IMMUTABLES, use immutable-vars-naming) | $~~~~~~~~$✔️ | |
4133
| [contract-name-camelcase](./rules/naming/contract-name-camelcase.md) | Contract, Structs and Enums should be in CamelCase. | $~~~~~~~~$✔️ | |
4234
| [event-name-camelcase](./rules/naming/event-name-camelcase.md) | Event name must be in CamelCase. | $~~~~~~~~$✔️ | |
@@ -47,7 +39,6 @@ title: "Rule Index of Solhint"
4739
| [immutable-vars-naming](./rules/naming/immutable-vars-naming.md) | Check Immutable variables. Capitalized SNAKE_CASE or mixedCase depending on configuration. | $~~~~~~~~$✔️ | |
4840
| [modifier-name-mixedcase](./rules/naming/modifier-name-mixedcase.md) | Modifier name must be in mixedCase. | | |
4941
| [named-parameters-mapping](./rules/naming/named-parameters-mapping.md) | Solidity v0.8.18 introduced named parameters on the mappings definition. | | |
50-
| [named-return-values](./rules/naming/named-return-values.md) | Enforce the return values of a function to be named | | |
5142
| [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 | | |
5243
| [use-forbidden-name](./rules/naming/use-forbidden-name.md) | Avoid to use letters 'I', 'l', 'O' as identifiers. | $~~~~~~~~$✔️ | |
5344
| [var-name-mixedcase](./rules/naming/var-name-mixedcase.md) | Variable name must be in mixedCase. (Does not check IMMUTABLES, use immutable-vars-naming) | $~~~~~~~~$✔️ | |
@@ -57,6 +48,30 @@ title: "Rule Index of Solhint"
5748
| [visibility-modifier-order](./rules/order/visibility-modifier-order.md) | Visibility modifier must be first in list of modifiers. | $~~~~~~~~$✔️ | |
5849
5950

51+
## Gas Consumption Rules
52+
53+
| Rule Id | Error | Recommended | Deprecated |
54+
| ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------ | ---------- |
55+
| [gas-calldata-parameters](./rules/gas-consumption/gas-calldata-parameters.md) | Suggest calldata keyword on function arguments when read only | | |
56+
| [gas-custom-errors](./rules/gas-consumption/gas-custom-errors.md) | Enforces the use of Custom Errors over Require and Revert statements | $~~~~~~~~$✔️ | |
57+
| [gas-increment-by-one](./rules/gas-consumption/gas-increment-by-one.md) | Suggest incrementation by one like this ++i instead of other type | | |
58+
| [gas-indexed-events](./rules/gas-consumption/gas-indexed-events.md) | Suggest indexed arguments on events for uint, bool and address | | |
59+
| [gas-length-in-loops](./rules/gas-consumption/gas-length-in-loops.md) | Suggest replacing object.length in a loop condition to avoid calculation on each lap | | |
60+
| [gas-multitoken1155](./rules/gas-consumption/gas-multitoken1155.md) | ERC1155 is a cheaper non-fungible token than ERC721 | | |
61+
| [gas-named-return-values](./rules/gas-consumption/gas-named-return-values.md) | Enforce the return values of a function to be named | | |
62+
| [gas-small-strings](./rules/gas-consumption/gas-small-strings.md) | Keep strings smaller than 32 bytes | | |
63+
| [gas-strict-inequalities](./rules/gas-consumption/gas-strict-inequalities.md) | Suggest Strict Inequalities over non Strict ones | | |
64+
| [gas-struct-packing](./rules/gas-consumption/gas-struct-packing.md) | Suggest to re-arrange struct packing order when it is inefficient | | |
65+
66+
67+
## Miscellaneous
68+
69+
| Rule Id | Error | Recommended | Deprecated |
70+
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- |
71+
| [comprehensive-interface](./rules/miscellaneous/comprehensive-interface.md) | Check that all public or external functions are override. This is iseful to make sure that the whole API is extracted in an interface. | | |
72+
| [quotes](./rules/miscellaneous/quotes.md) | Enforces the use of double or simple quotes as configured for string literals. Values must be 'single' or 'double'. | $~~~~~~~~$✔️ | |
73+
74+
6075
## Security Rules
6176

6277
| Rule Id | Error | Recommended | Deprecated |

docs/rules/best-practises/payable-fallback.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ title: "payable-fallback | Solhint"
1212
1313

1414
## Description
15-
When fallback is not payable you will not be able to receive ethers.
15+
When fallback is not payable and there is no receive function you will not be able to receive currency.
1616

1717
## Options
1818
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn.
@@ -28,36 +28,35 @@ This rule accepts a string option of rule severity. Must be one of "error", "war
2828

2929
### Notes
3030
- Solhint allows this rule to automatically fix the code with `--fix` option
31+
- Instead of having a fallback function to receive native currency it is recommended to code a receive() function [[here]](https://docs.soliditylang.org/en/v0.8.24/contracts.html#fallback-function)
3132

3233
## Examples
3334
### 👍 Examples of **correct** code for this rule
3435

3536
#### Fallback is payable
3637

3738
```solidity
39+
function() public payable {}
40+
```
41+
42+
#### Fallback is payable
3843

39-
pragma solidity 0.4.4;
40-
41-
42-
contract A {
43-
function () public payable {}
44-
}
45-
44+
```solidity
45+
fallback() external payable {}
4646
```
4747

4848
### 👎 Examples of **incorrect** code for this rule
4949

5050
#### Fallback is not payable
5151

5252
```solidity
53+
function() {} function g() payable {}
54+
```
55+
56+
#### Fallback is not payable
5357

54-
pragma solidity 0.4.4;
55-
56-
57-
contract A {
58-
function () public {}
59-
}
60-
58+
```solidity
59+
fallback() {} function g() payable {}
6160
```
6261

6362
## Version
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
warning: "This is a dynamically generated file. Do not edit manually."
3+
layout: "default"
4+
title: "gas-calldata-parameters | Solhint"
5+
---
6+
7+
# gas-calldata-parameters
8+
![Category Badge](https://img.shields.io/badge/-Gas%20Consumption%20Rules-informational)
9+
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow)
10+
11+
## Description
12+
Suggest calldata keyword on function arguments when read only
13+
14+
## Options
15+
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn.
16+
17+
### Example Config
18+
```json
19+
{
20+
"rules": {
21+
"gas-calldata-parameters": "warn"
22+
}
23+
}
24+
```
25+
26+
### Notes
27+
- Only applies for external functions when receiving arguments with [memory] keyword
28+
- This rule makes a soft check to see if argument is readOnly to make the suggestion. Check it manually before changing it.
29+
- [source 1](https://coinsbench.com/comprehensive-guide-tips-and-tricks-for-gas-optimization-in-solidity-5380db734404) of the rule initiative (see Calldata vs Memory)
30+
- [source 2](https://www.rareskills.io/post/gas-optimization?postId=c9db474a-ff97-4fa3-a51d-fe13ccb8fe3b#viewer-6acr7) of the rule initiative
31+
32+
## Examples
33+
This rule does not have examples.
34+
35+
## Version
36+
This rule is introduced in the latest version.
37+
38+
## Resources
39+
- [Rule source](https://github.com/protofire/solhint/tree/master/lib/rules/gas-consumption/gas-calldata-parameters.js)
40+
- [Document source](https://github.com/protofire/solhint/tree/master/docs/rules/gas-consumption/gas-calldata-parameters.md)
41+
- [Test cases](https://github.com/protofire/solhint/tree/master/test/rules/gas-consumption/gas-calldata-parameters.js)

0 commit comments

Comments
 (0)