-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow NatSpec comments for variables #3418
Comments
This depends on accepting #3411 first. |
#3411 is closed |
Since NatSpec currently does NOT apply to public state variables (see ethereum/solidity#3418).
* Support the documentation of global variables Following [this feature-request](#43), extending the `solidity-docgen` package to support the documentation of global variables, which are implicitly added by the compiler as getter functions in the contract. This should allow users to get the natspec-documentation of their global variables added into the `solidity-docgen` output by extending the input template (hbs) file. For example: ``` {{#if ownVariables}} # Variables: {{#ownVariables}} - [`{{type}} {{name}}`](#{{anchor}}) {{/ownVariables}} {{/if}} {{#ownVariables}} # Variable `{{type}} {{name}}` {#{{anchor~}} } {{#if natspec.devdoc}}{{natspec.devdoc}}{{else}}No description{{/if}} {{/ownVariables}} ``` Note that this PR is incomplete, since the `devdoc` of a global variable is always `undefined`. For this reason, I also had to override function `SolidityContractItem.natspec()` in class `SolidityVariable` with a slightly different implementation (since `this.astNode.documentation === undefined`). * Fix function `SolidityVariable.type()` * Throw error in function SolidityVariable.natspec Since NatSpec currently does NOT apply to public state variables (see ethereum/solidity#3418). * Add `this.variables` to the array returned by `linkable` As requested at #44 (comment). * Update src/solidity.ts Co-Authored-By: Francisco Giordano <frangio.1@gmail.com> * Add the definition of `interface VariableDeclaration` As requested at #44 (comment). * Fix the `VariableDeclaration` interface Remove the n/a `documentation` field. * Fix class `SolidityVariable` Let this class implement `Linkable` instead of extending `SolidityContractItem`. * add missing semicolons and commas * rename typeName to type * add necessary members in variable ast node interface * remove unused constructor argument * finish implementation of state variable documentation * add tests for state variables * add warning for state variable natspec
summary from the call: waiting for further clarification from @fulldecent |
Updated issue with test case for 0.6 |
Also added PR for documentation (which is blocked against here). #7857 |
This is up for grabs again. Please see #8399. |
Since #3514 was fixed, the (in my opinion) best pattern is using interfaces to define public functions and those have to be NatSpec documented. Interfaces can't have "getters", but getters can implement functions of interfaces. This removes the need for NatSpec documenting internal functions -- probably the bigger questions is defining the goals and use case of NatSpec to properly decide its features. |
Yes agreed. All is good in the world, there is no need for this feature. Closing. There is no harm in implementing this feature and it can be opened later if desired but there is no need for it. |
Hm, it seems this was a duplicate for #2795. |
* Support the documentation of global variables Following [this feature-request](OpenZeppelin/solidity-docgen#43), extending the `solidity-docgen` package to support the documentation of global variables, which are implicitly added by the compiler as getter functions in the contract. This should allow users to get the natspec-documentation of their global variables added into the `solidity-docgen` output by extending the input template (hbs) file. For example: ``` {{#if ownVariables}} # Variables: {{#ownVariables}} - [`{{type}} {{name}}`](#{{anchor}}) {{/ownVariables}} {{/if}} {{#ownVariables}} # Variable `{{type}} {{name}}` {#{{anchor~}} } {{#if natspec.devdoc}}{{natspec.devdoc}}{{else}}No description{{/if}} {{/ownVariables}} ``` Note that this PR is incomplete, since the `devdoc` of a global variable is always `undefined`. For this reason, I also had to override function `SolidityContractItem.natspec()` in class `SolidityVariable` with a slightly different implementation (since `this.astNode.documentation === undefined`). * Fix function `SolidityVariable.type()` * Throw error in function SolidityVariable.natspec Since NatSpec currently does NOT apply to public state variables (see ethereum/solidity#3418). * Add `this.variables` to the array returned by `linkable` As requested at OpenZeppelin/solidity-docgen#44 (comment). * Update src/solidity.ts Co-Authored-By: Francisco Giordano <frangio.1@gmail.com> * Add the definition of `interface VariableDeclaration` As requested at OpenZeppelin/solidity-docgen#44 (comment). * Fix the `VariableDeclaration` interface Remove the n/a `documentation` field. * Fix class `SolidityVariable` Let this class implement `Linkable` instead of extending `SolidityContractItem`. * add missing semicolons and commas * rename typeName to type * add necessary members in variable ast node interface * remove unused constructor argument * finish implementation of state variable documentation * add tests for state variables * add warning for state variable natspec
* Support the documentation of global variables Following [this feature-request](OpenZeppelin/solidity-docgen#43), extending the `solidity-docgen` package to support the documentation of global variables, which are implicitly added by the compiler as getter functions in the contract. This should allow users to get the natspec-documentation of their global variables added into the `solidity-docgen` output by extending the input template (hbs) file. For example: ``` {{#if ownVariables}} # Variables: {{#ownVariables}} - [`{{type}} {{name}}`](#{{anchor}}) {{/ownVariables}} {{/if}} {{#ownVariables}} # Variable `{{type}} {{name}}` {#{{anchor~}} } {{#if natspec.devdoc}}{{natspec.devdoc}}{{else}}No description{{/if}} {{/ownVariables}} ``` Note that this PR is incomplete, since the `devdoc` of a global variable is always `undefined`. For this reason, I also had to override function `SolidityContractItem.natspec()` in class `SolidityVariable` with a slightly different implementation (since `this.astNode.documentation === undefined`). * Fix function `SolidityVariable.type()` * Throw error in function SolidityVariable.natspec Since NatSpec currently does NOT apply to public state variables (see ethereum/solidity#3418). * Add `this.variables` to the array returned by `linkable` As requested at OpenZeppelin/solidity-docgen#44 (comment). * Update src/solidity.ts Co-Authored-By: Francisco Giordano <frangio.1@gmail.com> * Add the definition of `interface VariableDeclaration` As requested at OpenZeppelin/solidity-docgen#44 (comment). * Fix the `VariableDeclaration` interface Remove the n/a `documentation` field. * Fix class `SolidityVariable` Let this class implement `Linkable` instead of extending `SolidityContractItem`. * add missing semicolons and commas * rename typeName to type * add necessary members in variable ast node interface * remove unused constructor argument * finish implementation of state variable documentation * add tests for state variables * add warning for state variable natspec
* Support the documentation of global variables Following [this feature-request](OpenZeppelin/solidity-docgen#43), extending the `solidity-docgen` package to support the documentation of global variables, which are implicitly added by the compiler as getter functions in the contract. This should allow users to get the natspec-documentation of their global variables added into the `solidity-docgen` output by extending the input template (hbs) file. For example: ``` {{#if ownVariables}} # Variables: {{#ownVariables}} - [`{{type}} {{name}}`](#{{anchor}}) {{/ownVariables}} {{/if}} {{#ownVariables}} # Variable `{{type}} {{name}}` {#{{anchor~}} } {{#if natspec.devdoc}}{{natspec.devdoc}}{{else}}No description{{/if}} {{/ownVariables}} ``` Note that this PR is incomplete, since the `devdoc` of a global variable is always `undefined`. For this reason, I also had to override function `SolidityContractItem.natspec()` in class `SolidityVariable` with a slightly different implementation (since `this.astNode.documentation === undefined`). * Fix function `SolidityVariable.type()` * Throw error in function SolidityVariable.natspec Since NatSpec currently does NOT apply to public state variables (see ethereum/solidity#3418). * Add `this.variables` to the array returned by `linkable` As requested at OpenZeppelin/solidity-docgen#44 (comment). * Update src/solidity.ts Co-Authored-By: Francisco Giordano <frangio.1@gmail.com> * Add the definition of `interface VariableDeclaration` As requested at OpenZeppelin/solidity-docgen#44 (comment). * Fix the `VariableDeclaration` interface Remove the n/a `documentation` field. * Fix class `SolidityVariable` Let this class implement `Linkable` instead of extending `SolidityContractItem`. * add missing semicolons and commas * rename typeName to type * add necessary members in variable ast node interface * remove unused constructor argument * finish implementation of state variable documentation * add tests for state variables * add warning for state variable natspec
* Support the documentation of global variables Following [this feature-request](OpenZeppelin/solidity-docgen#43), extending the `solidity-docgen` package to support the documentation of global variables, which are implicitly added by the compiler as getter functions in the contract. This should allow users to get the natspec-documentation of their global variables added into the `solidity-docgen` output by extending the input template (hbs) file. For example: ``` {{#if ownVariables}} # Variables: {{#ownVariables}} - [`{{type}} {{name}}`](#{{anchor}}) {{/ownVariables}} {{/if}} {{#ownVariables}} # Variable `{{type}} {{name}}` {#{{anchor~}} } {{#if natspec.devdoc}}{{natspec.devdoc}}{{else}}No description{{/if}} {{/ownVariables}} ``` Note that this PR is incomplete, since the `devdoc` of a global variable is always `undefined`. For this reason, I also had to override function `SolidityContractItem.natspec()` in class `SolidityVariable` with a slightly different implementation (since `this.astNode.documentation === undefined`). * Fix function `SolidityVariable.type()` * Throw error in function SolidityVariable.natspec Since NatSpec currently does NOT apply to public state variables (see ethereum/solidity#3418). * Add `this.variables` to the array returned by `linkable` As requested at OpenZeppelin/solidity-docgen#44 (comment). * Update src/solidity.ts Co-Authored-By: Francisco Giordano <frangio.1@gmail.com> * Add the definition of `interface VariableDeclaration` As requested at OpenZeppelin/solidity-docgen#44 (comment). * Fix the `VariableDeclaration` interface Remove the n/a `documentation` field. * Fix class `SolidityVariable` Let this class implement `Linkable` instead of extending `SolidityContractItem`. * add missing semicolons and commas * rename typeName to type * add necessary members in variable ast node interface * remove unused constructor argument * finish implementation of state variable documentation * add tests for state variables * add warning for state variable natspec
Test case
Run the command:
Then test output with:
jq .methods outputDirectory/*
Expected outcome
Documentation is output for
doesEat
andname
public functions.Actual outcome
Follow on work
The text was updated successfully, but these errors were encountered: