From 39400b78bac7562e4c600787fc22be3c9c4d58d8 Mon Sep 17 00:00:00 2001 From: Francisco Date: Wed, 4 Oct 2023 12:54:49 -0300 Subject: [PATCH] Ensure constant getters show in docs (#4649) --- docs/templates/contract.hbs | 2 +- docs/templates/helpers.js | 2 +- docs/templates/properties.js | 17 ++++++++++++++++- package-lock.json | 8 ++++---- package.json | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/templates/contract.hbs b/docs/templates/contract.hbs index a4716825ab6..e4c8e92060c 100644 --- a/docs/templates/contract.hbs +++ b/docs/templates/contract.hbs @@ -86,7 +86,7 @@ import "@openzeppelin/{{__item_context.file.absolutePath}}"; {{#each functions}} [.contract-item] [[{{anchor}}]] -==== `[.contract-item-name]#++{{name}}++#++({{typed-params params}}){{#if returns}} → {{typed-params returns}}{{/if}}++` [.item-kind]#{{visibility}}# +==== `[.contract-item-name]#++{{name}}++#++({{typed-params params}}){{#if returns2}} → {{typed-params returns2}}{{/if}}++` [.item-kind]#{{visibility}}# {{{natspec.dev}}} diff --git a/docs/templates/helpers.js b/docs/templates/helpers.js index 65f168eba74..1b6383549dc 100644 --- a/docs/templates/helpers.js +++ b/docs/templates/helpers.js @@ -6,7 +6,7 @@ module.exports['readme-path'] = opts => { return 'contracts/' + opts.data.root.id.replace(/\.adoc$/, '') + '/README.adoc'; }; -module.exports.names = params => params.map(p => p.name).join(', '); +module.exports.names = params => params?.map(p => p.name).join(', '); module.exports['typed-params'] = params => { return params?.map(p => `${p.type}${p.indexed ? ' indexed' : ''}${p.name ? ' ' + p.name : ''}`).join(', '); diff --git a/docs/templates/properties.js b/docs/templates/properties.js index 584c0abcac7..7e041056776 100644 --- a/docs/templates/properties.js +++ b/docs/templates/properties.js @@ -1,4 +1,4 @@ -const { isNodeType } = require('solidity-ast/utils'); +const { isNodeType, findAll } = require('solidity-ast/utils'); const { slug } = require('./helpers'); module.exports.anchor = function anchor({ item, contract }) { @@ -39,6 +39,21 @@ module.exports['has-errors'] = function ({ item }) { return item.inheritance.some(c => c.errors.length > 0); }; +module.exports.functions = function ({ item }) { + return [ + ...[...findAll('FunctionDefinition', item)].filter(f => f.visibility !== 'private'), + ...[...findAll('VariableDeclaration', item)].filter(f => f.visibility === 'public'), + ]; +}; + +module.exports.returns2 = function ({ item }) { + if (isNodeType('VariableDeclaration', item)) { + return [{ type: item.typeDescriptions.typeString }]; + } else { + return item.returns; + } +}; + module.exports['inherited-functions'] = function ({ item }) { const { inheritance } = item; const baseFunctions = new Set(inheritance.flatMap(c => c.functions.flatMap(f => f.baseFunctions ?? []))); diff --git a/package-lock.json b/package-lock.json index 30d6561d91c..0f4f9f55e4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@nomicfoundation/hardhat-network-helpers": "^1.0.3", "@nomiclabs/hardhat-truffle5": "^2.0.5", "@nomiclabs/hardhat-web3": "^2.0.0", - "@openzeppelin/docs-utils": "^0.1.4", + "@openzeppelin/docs-utils": "^0.1.5", "@openzeppelin/test-helpers": "^0.5.13", "@openzeppelin/upgrade-safe-transpiler": "^0.3.32", "@openzeppelin/upgrades-core": "^1.20.6", @@ -2299,9 +2299,9 @@ } }, "node_modules/@openzeppelin/docs-utils": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/@openzeppelin/docs-utils/-/docs-utils-0.1.4.tgz", - "integrity": "sha512-2I56U1GhnNlymz0gGmJbyZKhnErGIaJ+rqtKTGyNf7YX3jgeS9/Twv8H0T+OgLV4dimtCHPz/27w6CYhWQ/TGg==", + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/@openzeppelin/docs-utils/-/docs-utils-0.1.5.tgz", + "integrity": "sha512-GfqXArKmdq8rv+hsP+g8uS1VEkvMIzWs31dCONffzmqFwJ+MOsaNQNZNXQnLRgUkzk8i5mTNDjJuxDy+aBZImQ==", "dev": true, "dependencies": { "@frangio/servbot": "^0.2.5", diff --git a/package.json b/package.json index d5ab8289b74..55a89746e4e 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@nomicfoundation/hardhat-network-helpers": "^1.0.3", "@nomiclabs/hardhat-truffle5": "^2.0.5", "@nomiclabs/hardhat-web3": "^2.0.0", - "@openzeppelin/docs-utils": "^0.1.4", + "@openzeppelin/docs-utils": "^0.1.5", "@openzeppelin/test-helpers": "^0.5.13", "@openzeppelin/upgrade-safe-transpiler": "^0.3.32", "@openzeppelin/upgrades-core": "^1.20.6",