Skip to content

Commit 23d9cd6

Browse files
authored
Fix inheritdoc with Modifiers (#24)
* Fixed inheritdoc with Modifiers * Cleaned up * Updated versions
1 parent a2b5a44 commit 23d9cd6

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.7",
3+
"version": "1.0.8",
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: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,30 @@ export class Parser {
393393
}
394394
}
395395

396+
findModifierDefinitionByContractName(node: ModifierDefinition, contractName: string): ModifierDefinition | undefined {
397+
// Since we cannot access the scope (Contract) in which the modifier is defined,
398+
// we are looking for the topmost parent modifier documentation without the @inheritdoc tag.
399+
const inheritDocsRegex = /@inheritdoc (\w+)/gm;
400+
const matches = inheritDocsRegex.exec(node.documentation?.text!);
401+
402+
if (!matches) {
403+
return node as ModifierDefinition;
404+
}
405+
406+
if (!node.baseModifiers) {
407+
return undefined;
408+
}
409+
410+
for (let i = 0; i < node.baseModifiers.length; i++) {
411+
const baseModifier = this.deref("ModifierDefinition", node.baseModifiers[i]);
412+
const result = this.findModifierDefinitionByContractName(baseModifier, contractName);
413+
414+
if (result) {
415+
return result;
416+
}
417+
}
418+
}
419+
396420
parseNameAndDescription(text: string): [name: string, description: string] {
397421
const nameAndDescriptionRegex = /^(\w+).? ([\s\S]*)?/gm;
398422
const matches = nameAndDescriptionRegex.exec(text);
@@ -556,7 +580,13 @@ export class Parser {
556580
}
557581

558582
const [, parentName] = matches;
559-
const parentNode = this.findFunctionDefinitionByContractName(node, parentName);
583+
584+
let parentNode;
585+
if (node.nodeType === "FunctionDefinition") {
586+
parentNode = this.findFunctionDefinitionByContractName(node, parentName);
587+
} else if (node.nodeType === "ModifierDefinition") {
588+
parentNode = this.findModifierDefinitionByContractName(node, parentName);
589+
}
560590

561591
if (!parentNode) {
562592
throw new Error(`Invalid inheritdoc tag: ${text}`);

0 commit comments

Comments
 (0)