Skip to content

Commit

Permalink
Ensure constant getters show in docs (#4649)
Browse files Browse the repository at this point in the history
(cherry picked from commit 39400b7)
  • Loading branch information
frangio committed Oct 4, 2023
1 parent 21ef813 commit e49fcbe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/templates/contract.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}

Expand Down
2 changes: 1 addition & 1 deletion docs/templates/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ');
Expand Down
17 changes: 16 additions & 1 deletion docs/templates/properties.js
Original file line number Diff line number Diff line change
@@ -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 }) {
Expand Down Expand Up @@ -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 ?? [])));
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e49fcbe

Please sign in to comment.