Allow NatSpec comments for state variables#8532
Conversation
9e6d5c4 to
84f27c4
Compare
|
Please squash. |
0302dd8 to
7c0ee1a
Compare
|
@chriseth i'm not sure whether it is good to forbid
contract ReputationMiningCycle is ReputationMiningCycleStorage, PatriciaTreeProofs, DSMath {
/// @notice Minimum reputation mining stake in CLNY
uint256 constant MIN_STAKE = 2000 * WAD;
/// @notice Size of mining window in seconds
uint256 constant MINING_WINDOW_SIZE = 60 * 60 * 24; // 24 hours
...
}
contract ERC20Migrator {
using SafeERC20 for IERC20;
/// Address of the old token contract
IERC20 private _legacyToken;
/// Address of the new token contract
ERC20Mintable private _newToken;
...
}
contract Fund {
/// Mapping of ether shares of the contract.
mapping(address => uint) shares;
/// Withdraw your share.
function withdraw() public {
(bool success,) = msg.sender.call{value: shares[msg.sender]}("");
if (success)
shares[msg.sender] = 0;
}
} |
8d0f2ec to
7fa485e
Compare
|
@aarlt |
| { | ||
| if (_variable.isStateVariable()) | ||
| { | ||
| static set<string> const validPublicTags = set<string>{"dev", "notice", "title", "author"}; |
There was a problem hiding this comment.
Is author not only for contract?
There was a problem hiding this comment.
Yes, they are normally only allowed on contract. The thing is that some contract authors in the past put this "accidentally" in front of a state variable. It was ok in the past, because there was no check on state variables implemented. Looks like that they never noticed that title and author was never set. However, I added the checks here to inform the authors that this will not be allowed anymore.
| else | ||
| { | ||
| parseDocStrings(_variable, _variable.annotation(), validPublicTags, "non-public state variables"); | ||
| if (_variable.annotation().docTags.find("notice") != _variable.annotation().docTags.end()) |
There was a problem hiding this comment.
Please use contains or count
| if (_variable.annotation().docTags.find("notice") != _variable.annotation().docTags.end()) | ||
| m_errorReporter.warning(9098_error, _variable.documentation()->location(), "Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly."); | ||
| } | ||
| if (_variable.annotation().docTags.find("title") != _variable.annotation().docTags.end() || |
libsolidity/parsing/Parser.cpp
Outdated
| } | ||
|
|
||
| if (!_options.isStateVariable && documentation != nullptr) | ||
| parserWarning(2837_error, "Only state variables can retrieve a docstring. This will be disallowed in 0.7.0."); |
There was a problem hiding this comment.
| parserWarning(2837_error, "Only state variables can retrieve a docstring. This will be disallowed in 0.7.0."); | |
| parserWarning(2837_error, "Only state variables can have a docstring. This will be disallowed in 0.7.0."); |
| char const* sourceCode = R"( | ||
| contract test { | ||
| /// @notice example of notice | ||
| /// @dev example of dev |
There was a problem hiding this comment.
Can you check if @returns works here?
There was a problem hiding this comment.
Right now only @dev and @notice is allowed, but it could also make sense to allow @return here too.
There was a problem hiding this comment.
For contract
contract test {
/// @notice example of notice
/// @dev example of dev
/// @return returns something
uint public state;
}devdoc will now look like this:
{
"methods": {},
"stateVariables":
{
"state":
{
"details": "example of dev",
"return": "returns something"
}
}
}- multiple return tags on a state-variable will result in a parsing error.
fb7f327 to
c248c78
Compare
|
Needs rebase. |
cab1760 to
ce68386
Compare
|
Needs rebase again. |
ce68386 to
0a38ec8
Compare
|
Needs rebase. |
docs/natspec-format.rst
Outdated
| ``@author`` The name of the author contract, interface, function | ||
| ``@notice`` Explain to an end user what this does contract, interface, function | ||
| ``@dev`` Explain to a developer any extra details contract, interface, function | ||
| ``@notice`` Explain to an end user what this does contract, interface, function, state variable |
There was a problem hiding this comment.
| ``@notice`` Explain to an end user what this does contract, interface, function, state variable | |
| ``@notice`` Explain to an end user what this does contract, interface, function, public state variable |
docs/natspec-format.rst
Outdated
| ``@dev`` Explain to a developer any extra details contract, interface, function, state variable | ||
| ``@param`` Documents a parameter just like in doxygen (must be followed by parameter name) function | ||
| ``@return`` Documents the return variables of a contract's function function | ||
| ``@return`` Documents the return variables of a contract's function function, state variable |
There was a problem hiding this comment.
| ``@return`` Documents the return variables of a contract's function function, state variable | |
| ``@return`` Documents the return variables of a contract's function function, public state variable |
There was a problem hiding this comment.
Thats true, @return should only be allowed on public state-variables.
There was a problem hiding this comment.
I added now a check: @return is now only allowed on public state-variables. I added also a test for this.
| if (returnTagsVisited > 1) | ||
| appendError( | ||
| _node.documentation()->location(), | ||
| "Documentation tag \"@" + docTag.first + "\" is only allowed once on state-variables."); |
There was a problem hiding this comment.
| "Documentation tag \"@" + docTag.first + "\" is only allowed once on state-variables."); | |
| "Documentation tag \"@" + docTag.first + "\" is only allowed once on state-variables." | |
| ); |
| { | ||
| parseDocStrings(_variable, _variable.annotation(), validPublicTags, "non-public state variables"); | ||
| if (_variable.annotation().docTags.count("notice") > 0) | ||
| m_errorReporter.warning(9098_error, _variable.documentation()->location(), "Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly."); |
| m_errorReporter.warning(9098_error, _variable.documentation()->location(), "Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly."); | ||
| } | ||
| if (_variable.annotation().docTags.count("title") > 0 || _variable.annotation().docTags.count("author") > 0) | ||
| m_errorReporter.warning(4822_error, _variable.documentation()->location(), "Documentation tag @title and @author is only allowed on contract definitions. It will be disallowed in 0.7.0."); |
0a38ec8 to
fc8b934
Compare
- adds natspec generation for state variables. - exports structured docs for state variables to JSON.
fc8b934 to
af8bb5f
Compare
Fixes #3418.
replaces #8399