From 1c9ecac8f51171eec67526112c7e21eb213190ef Mon Sep 17 00:00:00 2001 From: Dristpunk Date: Mon, 5 Feb 2024 14:31:49 +0300 Subject: [PATCH] fix: ignore receive and fallback --- sample-data/BasicSample.sol | 10 ++++++++++ src/validator.ts | 5 +++++ test/validator.test.ts | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/sample-data/BasicSample.sol b/sample-data/BasicSample.sol index 489d999..f002a00 100644 --- a/sample-data/BasicSample.sol +++ b/sample-data/BasicSample.sol @@ -100,4 +100,14 @@ contract BasicSample is AbstractBasic { modifier transferFee(uint256 _receiver) { _; } + + /** + * @dev This func must be ignored + */ + receive() external payable {} + + /** + * @dev This func must be ignored + */ + fallback() external {} } diff --git a/src/validator.ts b/src/validator.ts index 3cc50a6..94f7644 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -18,6 +18,11 @@ export class Validator { } validate(node: NodeToProcess, natspec: Natspec): string[] { + // Ignore fallback and receive + if (node instanceof FunctionDefinition && (node.kind === 'receive' || node.kind === 'fallback')) { + return []; + } + // There is inheritdoc, no other validation is needed if (natspec.inheritdoc) return []; diff --git a/test/validator.test.ts b/test/validator.test.ts index 26746a6..faac28b 100644 --- a/test/validator.test.ts +++ b/test/validator.test.ts @@ -339,6 +339,17 @@ describe('Validator', () => { expect(result).toContainEqual(`@param ${paramName2} is missing`); }); + it('should ignore receive and fallback', () => { + node = contract.vFunctions.find(({ kind }) => kind === 'receive' || kind === 'fallback')!; + natspec = { + tags: [], + params: [], + returns: [], + }; + const result = validator.validate(node, natspec); + expect(result).toEqual([]); + }); + describe('with enforced inheritdoc', () => { beforeAll(async () => { config = {