diff --git a/conf/rulesets/solhint-all.js b/conf/rulesets/solhint-all.js index d2fc2406..852ce670 100644 --- a/conf/rulesets/solhint-all.js +++ b/conf/rulesets/solhint-all.js @@ -30,6 +30,7 @@ module.exports = Object.freeze({ 'gas-indexed-events': 'warn', 'gas-multitoken1155': 'warn', 'gas-small-strings': 'warn', + 'gas-struct-packing': 'warn', 'comprehensive-interface': 'warn', quotes: ['error', 'double'], 'const-name-snakecase': 'warn', diff --git a/docs/rules.md b/docs/rules.md index bb220f32..356d1d7a 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -34,6 +34,7 @@ title: "Rule Index of Solhint" | [gas-indexed-events](./rules/gas-consumption/gas-indexed-events.md) | Suggest indexed arguments on events for uint, bool and address | | | | [gas-multitoken1155](./rules/gas-consumption/gas-multitoken1155.md) | ERC1155 is a cheaper non-fungible token than ERC721 | | | | [gas-small-strings](./rules/gas-consumption/gas-small-strings.md) | Keep strings smaller than 32 bytes | | | +| [gas-struct-packing](./rules/gas-consumption/gas-struct-packing.md) | Suggest to re-arrange struct packing order when it is inefficient | | | ## Miscellaneous diff --git a/docs/rules/gas-consumption/gas-struct-packing.md b/docs/rules/gas-consumption/gas-struct-packing.md new file mode 100644 index 00000000..1177b18e --- /dev/null +++ b/docs/rules/gas-consumption/gas-struct-packing.md @@ -0,0 +1,40 @@ +--- +warning: "This is a dynamically generated file. Do not edit manually." +layout: "default" +title: "gas-struct-packing | Solhint" +--- + +# gas-struct-packing +![Category Badge](https://img.shields.io/badge/-Gas%20Consumption%20Rules-informational) +![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow) + +## Description +Suggest to re-arrange struct packing order when it is inefficient + +## Options +This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn. + +### Example Config +```json +{ + "rules": { + "gas-struct-packing": "warn" + } +} +``` + +### Notes +- This rule +- [source 1](https://coinsbench.com/comprehensive-guide-tips-and-tricks-for-gas-optimization-in-solidity-5380db734404) of the rule initiative (Variable Packing) +- [source 2](https://www.rareskills.io/post/gas-optimization?postId=c9db474a-ff97-4fa3-a51d-fe13ccb8fe3b#viewer-f8m1r) of the rule initiative + +## 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/gas-consumption/gas-struct-packing.js) +- [Document source](https://github.com/protofire/solhint/tree/master/docs/rules/gas-consumption/gas-struct-packing.md) +- [Test cases](https://github.com/protofire/solhint/tree/master/test/rules/gas-consumption/gas-struct-packing.js)