Skip to content

Commit

Permalink
fix: ignore receive and fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
dristpunk committed Feb 5, 2024
1 parent 10034e3 commit 1c9ecac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sample-data/BasicSample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
5 changes: 5 additions & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];

Expand Down
11 changes: 11 additions & 0 deletions test/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 1c9ecac

Please sign in to comment.