Prechádzať zdrojové kódy

Ensure constant getters show in docs (#4649)

Francisco 2 rokov pred
rodič
commit
39400b78ba

+ 1 - 1
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}}}
 

+ 1 - 1
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(', ');

+ 16 - 1
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 ?? [])));

+ 4 - 4
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",

+ 1 - 1
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",