Skip to content

Commit

Permalink
Merge pull request #466 from islishude/dont-check-no-empty-block-for-…
Browse files Browse the repository at this point in the history
…receive-func

disable no-empty-blocks for receive function
  • Loading branch information
dbale-altoros authored Aug 3, 2023
2 parents 1d89d69 + a676cf8 commit 3810fc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rules/best-practises/no-empty-blocks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const BaseChecker = require('../base-checker')
const { isFallbackFunction } = require('../../common/ast-types')
const { isFallbackFunction, isReceiveFunction } = require('../../common/ast-types')

const ruleId = 'no-empty-blocks'
const meta = {
Expand Down Expand Up @@ -50,8 +50,9 @@ class NoEmptyBlocksChecker extends BaseChecker {
}

const isFallbackFunctionBlock = isFallbackFunction(node.parent)
if (isFallbackFunctionBlock) {
// ignore empty blocks in fallback functions
const isReceiveFunctionBlock = isReceiveFunction(node.parent)
if (isFallbackFunctionBlock || isReceiveFunctionBlock) {
// ignore empty blocks in fallback or receive functions
return
}
this._validateChildrenCount(node, 'statements')
Expand Down
2 changes: 2 additions & 0 deletions test/rules/best-practises/no-empty-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe('Linter - no-empty-blocks', () => {

const BLOCKS_WITH_DEFINITIONS = [
contractWith('function () public payable { make1(); }'),
contractWith('receive() external payable {}'),
contractWith('fallback() external payable {}'),
funcWith('if (a < b) { make1(); }'),
contractWith('struct Abc { uint a; }'),
contractWith('enum Abc { Test1 }'),
Expand Down

0 comments on commit 3810fc2

Please sign in to comment.