From aa6fb93aad8625043cf7bf5d6fe06eae5e4024d0 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Tue, 1 Aug 2023 10:38:56 -0300 Subject: [PATCH] small updates on docs and package json --- CHANGELOG.md | 25 ++++++++ docs/rules.md | 62 ++++++++++---------- docs/rules/best-practises/no-empty-blocks.md | 36 +++++++++++- lib/rules/best-practises/no-empty-blocks.js | 19 +++++- package.json | 2 - 5 files changed, 108 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af36d16..15c24f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,28 @@ +## [3.4.2] - 2023-08-04 +### Updated +- Support `ignoreConstructors` option for `no-empty-blocks` [#418](https://github.com/protofire/solhint/pull/418) +- Bump json5 from 2.1.3 to 2.2.3 [#376](https://github.com/protofire/solhint/pull/376) +- Bump json-schema and jsprim [#370](https://github.com/protofire/solhint/pull/370) +- Bump semver from 6.3.0 to 7.5.2 [#438](https://github.com/protofire/solhint/pull/438) +- Corrected "Category" of `quotes` rule, added default rules list on readme [#443](https://github.com/protofire/solhint/pull/443) +- 'Deprecated' column on `rules.md`` [#444](https://github.com/protofire/solhint/pull/444) +- Information about maxCharacters allowed on `reason-string` rule [#446](https://github.com/protofire/solhint/pull/446) +- E2E tests for `max-warnings` [#455](https://github.com/protofire/solhint/pull/455) +- Replaced blacklist and whitelist words [#459](https://github.com/protofire/solhint/pull/459) +### Added +- New Rule: No unused imports [#417](https://github.com/protofire/solhint/pull/417) +- New Rule: To treat immutable as constants [#458](https://github.com/protofire/solhint/pull/458) +- JSON formatter support [#440](https://github.com/protofire/solhint/pull/440) +- Rules List with `list-rules` command [#449](https://github.com/protofire/solhint/pull/449) +- E2E tests for formatters and new `Compact formatter` [#457](https://github.com/protofire/solhint/pull/457) + +### Fixed +- `maxWarnings` parameter waiting review [#439](https://github.com/protofire/solhint/pull/439) +- `–fix` option not working in avoid-throw rule [#442](https://github.com/protofire/solhint/pull/442) +- Formatter option fixed for `stdin` command [#450](https://github.com/protofire/solhint/pull/450) + + +

## [3.4.1] - 2023-03-06 ### Updated - Updated solidity parser to 0.16.0 [#420](https://github.com/protofire/solhint/pull/420) diff --git a/docs/rules.md b/docs/rules.md index 9765afd3..2f4ffc93 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -6,20 +6,20 @@ title: "Rule Index of Solhint" ## Best Practise Rules -| Rule Id | Error | Recommended | -| ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- | ----------- | -| [code-complexity](./rules/best-practises/code-complexity.md) | Function has cyclomatic complexity "current" but allowed no more than maxcompl. | | -| [function-max-lines](./rules/best-practises/function-max-lines.md) | Function body contains "count" lines but allowed no more than maxlines. | | -| [max-line-length](./rules/best-practises/max-line-length.md) | Line length must be no more than maxlen. | | -| [max-states-count](./rules/best-practises/max-states-count.md) | Contract has "some count" states declarations but allowed no more than maxstates. | ✔️ | -| [no-console](./rules/best-practises/no-console.md) | No console.log/logInt/logBytesX/logString/etc & No hardhat and forge-std console.sol import statements. | ✔️ | -| [no-empty-blocks](./rules/best-practises/no-empty-blocks.md) | Code contains empty block. | ✔️ | -| [no-global-import](./rules/best-practises/no-global-import.md) | Import statement includes an entire file instead of selected symbols. | ✔️ | -| [no-unused-import](./rules/best-practises/no-unused-import.md) | Imported name is not used. | ✔️ | -| [no-unused-vars](./rules/best-practises/no-unused-vars.md) | Variable "name" is unused. | ✔️ | -| [payable-fallback](./rules/best-practises/payable-fallback.md) | When fallback is not payable you will not be able to receive ethers. | ✔️ | -| [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. | ✔️ | -| [constructor-syntax](./rules/best-practises/constructor-syntax.md) | Constructors should use the new constructor keyword. | | +| Rule Id | Error | Recommended | Deprecated | +| ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | +| [code-complexity](./rules/best-practises/code-complexity.md) | Function has cyclomatic complexity "current" but allowed no more than maxcompl. | | | +| [function-max-lines](./rules/best-practises/function-max-lines.md) | Function body contains "count" lines but allowed no more than maxlines. | | | +| [max-line-length](./rules/best-practises/max-line-length.md) | Line length must be no more than maxlen. | | | +| [max-states-count](./rules/best-practises/max-states-count.md) | Contract has "some count" states declarations but allowed no more than maxstates. | $~~~~~~~~$✔️ | | +| [no-console](./rules/best-practises/no-console.md) | No console.log/logInt/logBytesX/logString/etc & No hardhat and forge-std console.sol import statements. | $~~~~~~~~$✔️ | | +| [no-empty-blocks](./rules/best-practises/no-empty-blocks.md) | Code block has zero statements inside. Exceptions apply. | $~~~~~~~~$✔️ | | +| [no-global-import](./rules/best-practises/no-global-import.md) | Import statement includes an entire file instead of selected symbols. | $~~~~~~~~$✔️ | | +| [no-unused-import](./rules/best-practises/no-unused-import.md) | Imported name is not used. | $~~~~~~~~$✔️ | | +| [no-unused-vars](./rules/best-practises/no-unused-vars.md) | Variable "name" is unused. | $~~~~~~~~$✔️ | | +| [payable-fallback](./rules/best-practises/payable-fallback.md) | When fallback is not payable you will not be able to receive ethers. | $~~~~~~~~$✔️ | | +| [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. | $~~~~~~~~$✔️ | | +| [constructor-syntax](./rules/best-practises/constructor-syntax.md) | Constructors should use the new constructor keyword. | | | ## Miscellaneous @@ -32,23 +32,23 @@ title: "Rule Index of Solhint" ## Style Guide Rules -| Rule Id | Error | Recommended | -| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- | ----------- | -| [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) | ✔️ | -| [contract-name-camelcase](./rules/naming/contract-name-camelcase.md) | Contract name must be in CamelCase. | ✔️ | -| [event-name-camelcase](./rules/naming/event-name-camelcase.md) | Event name must be in CamelCase. | ✔️ | -| [func-name-mixedcase](./rules/naming/func-name-mixedcase.md) | Function name must be in mixedCase. | ✔️ | -| [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. | ✔️ | -| [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) | Private and internal names must start with a single underscore. | | -| [use-forbidden-name](./rules/naming/use-forbidden-name.md) | Avoid to use letters 'I', 'l', 'O' as identifiers. | ✔️ | -| [var-name-mixedcase](./rules/naming/var-name-mixedcase.md) | Variable name must be in mixedCase. (Does not check IMMUTABLES, use immutable-vars-naming) | ✔️ | -| [func-order](./rules/order/func-order.md) | Function order is incorrect. | | -| [imports-on-top](./rules/order/imports-on-top.md) | Import statements must be on top. | ✔️ | -| [ordering](./rules/order/ordering.md) | Check order of elements in file and inside each contract, according to the style guide. | | -| [visibility-modifier-order](./rules/order/visibility-modifier-order.md) | Visibility modifier must be first in list of modifiers. | ✔️ | +| Rule Id | Error | Recommended | Deprecated | +| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- | ------------ | ----------- | +| [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) | $~~~~~~~~$✔️ | | +| [contract-name-camelcase](./rules/naming/contract-name-camelcase.md) | Contract name must be in CamelCase. | $~~~~~~~~$✔️ | | +| [event-name-camelcase](./rules/naming/event-name-camelcase.md) | Event name must be in CamelCase. | $~~~~~~~~$✔️ | | +| [func-name-mixedcase](./rules/naming/func-name-mixedcase.md) | Function name must be in mixedCase. | $~~~~~~~~$✔️ | | +| [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. | $~~~~~~~~$✔️ | | +| [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) | Private and internal names must start with a single underscore. | | | +| [use-forbidden-name](./rules/naming/use-forbidden-name.md) | Avoid to use letters 'I', 'l', 'O' as identifiers. | $~~~~~~~~$✔️ | | +| [var-name-mixedcase](./rules/naming/var-name-mixedcase.md) | Variable name must be in mixedCase. (Does not check IMMUTABLES, use immutable-vars-naming) | $~~~~~~~~$✔️ | | +| [func-order](./rules/order/func-order.md) | Function order is incorrect. | | $~~~~~~~$✔️ | +| [imports-on-top](./rules/order/imports-on-top.md) | Import statements must be on top. | $~~~~~~~~$✔️ | | +| [ordering](./rules/order/ordering.md) | Check order of elements in file and inside each contract, according to the style guide. | | | +| [visibility-modifier-order](./rules/order/visibility-modifier-order.md) | Visibility modifier must be first in list of modifiers. | $~~~~~~~~$✔️ | | ## Security Rules diff --git a/docs/rules/best-practises/no-empty-blocks.md b/docs/rules/best-practises/no-empty-blocks.md index d4f3d0b0..cbc7caec 100644 --- a/docs/rules/best-practises/no-empty-blocks.md +++ b/docs/rules/best-practises/no-empty-blocks.md @@ -12,7 +12,7 @@ title: "no-empty-blocks | Solhint" ## Description -Code contains empty block. +Code block has zero statements inside. Exceptions apply. ## Options This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn. @@ -28,7 +28,39 @@ This rule accepts a string option of rule severity. Must be one of "error", "war ## Examples -This rule does not have examples. +### 👍 Examples of **correct** code for this rule + +#### Empty fallback function + +```solidity +fallback () external { } +``` + +#### Empty constructor with member initialization list + +```solidity +constructor(uint param) Foo(param) Bar(param*2) { } +``` + +### 👎 Examples of **incorrect** code for this rule + +#### Empty block on if statement + +```solidity +if (condition) { } +``` + +#### Empty contract + +```solidity +contract Foo { } +``` + +#### Empty block in constructor without parent initialization + +```solidity +constructor () { } +``` ## Version This rule was introduced in [Solhint 1.1.5](https://github.com/protofire/solhint/tree/v1.1.5) diff --git a/lib/rules/best-practises/no-empty-blocks.js b/lib/rules/best-practises/no-empty-blocks.js index f49bd935..52ae07f0 100644 --- a/lib/rules/best-practises/no-empty-blocks.js +++ b/lib/rules/best-practises/no-empty-blocks.js @@ -6,8 +6,25 @@ const meta = { type: 'best-practises', docs: { - description: 'Code contains empty block.', + description: 'Code block has zero statements inside. Exceptions apply.', category: 'Best Practise Rules', + examples: { + bad: [ + { description: 'Empty block on if statement', code: 'if (condition) { }' }, + { description: 'Empty contract', code: 'contract Foo { }' }, + { + description: 'Empty block in constructor without parent initialization', + code: 'constructor () { }', + }, + ], + good: [ + { description: 'Empty fallback function', code: 'fallback () external { }' }, + { + description: 'Empty constructor with member initialization list', + code: 'constructor(uint param) Foo(param) Bar(param*2) { }', + }, + ], + }, }, isDefault: false, diff --git a/package.json b/package.json index 76bbf50c..9d27df97 100644 --- a/package.json +++ b/package.json @@ -41,8 +41,6 @@ "chalk": "^4.1.2", "commander": "^10.0.0", "cosmiconfig": "^8.0.0", - "cross-spawn": "^7.0.3", - "execa": "^4.1.0", "fast-diff": "^1.2.0", "glob": "^8.0.3", "ignore": "^5.2.4",