Move improvements to the NatSpec documentation

This commit is contained in:
Alex Beregszaszi 2021-03-25 11:03:43 +00:00
parent 15fe07bebe
commit a99e0eb5cb
3 changed files with 18 additions and 41 deletions

View File

@ -335,27 +335,6 @@ Single-line comments (``//``) and multi-line comments (``/*...*/``) are possible
(these are NEL, LS and PS), it will lead to a parser error. (these are NEL, LS and PS), it will lead to a parser error.
Additionally, there is another type of comment called a NatSpec comment, Additionally, there is another type of comment called a NatSpec comment,
which is detailed in the :ref:`style guide<natspec>` section. They are written with a which is detailed in the :ref:`style guide<style_guide_natspec>`. They are written with a
triple slash (``///``) or a double asterisk block(``/** ... */``) and triple slash (``///``) or a double asterisk block (``/** ... */``) and
they should be used directly above function declarations or statements. they should be used directly above function declarations or statements.
In the following example we document the title of the contract, the explanation
for the two function parameters and two return variables.
::
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.21 <0.9.0;
/** @title Shape calculator. */
contract ShapeCalculator {
/// @dev Calculates a rectangle's surface and perimeter.
/// @param w Width of the rectangle.
/// @param h Height of the rectangle.
/// @return s The calculated surface.
/// @return p The calculated perimeter.
function rectangle(uint w, uint h) public pure returns (uint s, uint p) {
s = w * h;
p = 2 * (w + h);
}
}

View File

@ -8,7 +8,7 @@ Solidity contracts can use a special form of comments to provide rich
documentation for functions, return variables and more. This special form is documentation for functions, return variables and more. This special form is
named the Ethereum Natural Language Specification Format (NatSpec). named the Ethereum Natural Language Specification Format (NatSpec).
.. note: .. note::
NatSpec was inspired by `Doxygen <https://en.wikipedia.org/wiki/Doxygen>`_. NatSpec was inspired by `Doxygen <https://en.wikipedia.org/wiki/Doxygen>`_.
While it uses Doxygen-style comments and tags, there is no intention to keep While it uses Doxygen-style comments and tags, there is no intention to keep
@ -36,17 +36,16 @@ tools.
Documentation Example Documentation Example
===================== =====================
Documentation is inserted above each ``class``, ``interface`` and Documentation is inserted above each ``contract``, ``interface``,
``function`` using the Doxygen notation format. ``function``, and ``event`` using the Doxygen notation format.
A ``public`` state variable is equivalent to a ``function``
Note: a ``public`` state variable is equivalent to a ``function``
for the purposes of NatSpec. for the purposes of NatSpec.
- For Solidity you may choose ``///`` for single or multi-line - For Solidity you may choose ``///`` for single or multi-line
comments, or ``/**`` and ending with ``*/``. comments, or ``/**`` and ending with ``*/``.
- For Vyper, use ``"""`` indented to the inner contents with bare - For Vyper, use ``"""`` indented to the inner contents with bare
comments. See `Vyper comments. See the `Vyper
documentation <https://vyper.readthedocs.io/en/latest/natspec.html>`__. documentation <https://vyper.readthedocs.io/en/latest/natspec.html>`__.
The following example shows a contract and a function using all available tags. The following example shows a contract and a function using all available tags.
@ -57,6 +56,8 @@ The following example shows a contract and a function using all available tags.
public. You are welcome to use similar comments for your internal and public. You are welcome to use similar comments for your internal and
private functions, but those will not be parsed. private functions, but those will not be parsed.
This may change in the future.
.. code:: Solidity .. code:: Solidity
// SPDX-License-Identifier: GPL-3.0 // SPDX-License-Identifier: GPL-3.0
@ -125,11 +126,10 @@ Tag
=============== ====================================================================================== ============================= =============== ====================================================================================== =============================
If your function returns multiple values, like ``(int quotient, int remainder)`` If your function returns multiple values, like ``(int quotient, int remainder)``
then use multiple ``@return`` statements in the same format as the then use multiple ``@return`` statements in the same format as the ``@param`` statements.
``@param`` statements.
Custom tags start with ``@custom:`` and can contain lowercase characters and hyphens following that. Custom tags start with ``@custom:`` and must be followed by one or more lowercase letters or hyphens.
They can be used everywhere and are part of the developer documentation. It cannot start with a hyphen however. They can be used everywhere and are part of the developer documentation.
.. _header-dynamic: .. _header-dynamic:
@ -237,7 +237,7 @@ file should also be produced and should look like this:
"kind" : "dev", "kind" : "dev",
"author" : "Larry A. Gardner", "author" : "Larry A. Gardner",
"details" : "All function calls are currently implemented without side effects", "details" : "All function calls are currently implemented without side effects",
"custom:experimental": "This is an experimental contract.", "custom:experimental" : "This is an experimental contract.",
"methods" : "methods" :
{ {
"age(uint256)" : "age(uint256)" :

View File

@ -1136,16 +1136,15 @@ Avoiding Naming Collisions
This convention is suggested when the desired name collides with that of a This convention is suggested when the desired name collides with that of a
built-in or otherwise reserved name. built-in or otherwise reserved name.
.. _style_guide_natspec:
******* *******
NatSpec NatSpec
******* *******
Solidity contracts can have a form of comments that are the basis of the Solidity contracts can also contain NatSpec comments. They are written with a
Ethereum Natural Language Specification Format. triple slash (``///``) or a double asterisk block (``/** ... */``) and
they should be used directly above function declarations or statements.
Add comments above functions or contracts following `doxygen <https://www.doxygen.nl>`_ notation
of one or multiple lines starting with ``///`` or a
multiline comment starting with ``/**`` and ending with ``*/``.
For example, the contract from :ref:`a simple smart contract <simple-smart-contract>` with the comments For example, the contract from :ref:`a simple smart contract <simple-smart-contract>` with the comments
added looks like the one below:: added looks like the one below::
@ -1153,7 +1152,6 @@ added looks like the one below::
// SPDX-License-Identifier: GPL-3.0 // SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0; pragma solidity >=0.4.16 <0.9.0;
/// @author The Solidity Team /// @author The Solidity Team
/// @title A simple storage example /// @title A simple storage example
contract SimpleStorage { contract SimpleStorage {