Skip to content

Commit a9911b9

Browse files
Feat/correction of invalid tag (#23)
* Added autocorrecting an invalid '@param' tag to a valid '@return' one * Bumped version * Added second loop iteration for invalid tags
1 parent 93a1db7 commit a9911b9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solarity/hardhat-markup",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Customizable markdown smart contracts documentation",
55
"main": "dist/src/index.js",
66
"types": "dist/src/index.d.ts",

src/parser/Parser.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,10 @@ export class Parser {
434434

435435
const natSpecRegex = /^(?:@(\w+|custom:[a-z][a-z-]*) )?((?:(?!^@(?:\w+|custom:[a-z][a-z-]*) )[^])*)/gm;
436436

437-
for (const match of text.matchAll(natSpecRegex)) {
438-
const [, tag = "notice", rawText] = match;
437+
const matches = [...text.matchAll(natSpecRegex)];
438+
439+
for (let i = 0; i < matches.length; i++) {
440+
const [, tag = "notice", rawText] = matches[i];
439441
const text = this.replaceMultipleNewLinesWithOne(rawText);
440442

441443
switch (tag) {
@@ -484,8 +486,14 @@ export class Parser {
484486

485487
const variableDeclaration = params.find((param) => param.name == paramName);
486488

489+
// so that tag was not found, and it may be a return tag
487490
if (!variableDeclaration) {
488-
throw new Error(`Invalid param name: ${paramName}`);
491+
// protection from infinite loop
492+
if (node.nodeType !== "EventDefinition") {
493+
matches[i][1] = "return";
494+
i--;
495+
}
496+
break;
489497
}
490498

491499
const type = variableDeclaration.typeDescriptions?.typeString || undefined;
@@ -495,6 +503,13 @@ export class Parser {
495503
break;
496504
}
497505
case "return": {
506+
// there is no return tag in events, so it is a param tag
507+
if (node.nodeType === "EventDefinition") {
508+
matches[i][1] = "param";
509+
i--;
510+
break;
511+
}
512+
498513
natSpec.returns ??= [];
499514

500515
let currentParameter: VariableDeclaration = isNodeType("FunctionDefinition", node)

0 commit comments

Comments
 (0)