Skip to content
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 state variables #8532

Merged
merged 3 commits into from
May 19, 2020

Conversation

aarlt
Copy link
Member

@aarlt aarlt commented Mar 24, 2020

Fixes #3418.
replaces #8399

@aarlt aarlt force-pushed the structured-docs-variables-aarlt branch 4 times, most recently from 9e6d5c4 to 84f27c4 Compare March 25, 2020 00:04
@chriseth
Copy link
Contributor

Please squash.

@aarlt aarlt force-pushed the structured-docs-variables-aarlt branch from 0302dd8 to 7c0ee1a Compare March 25, 2020 21:55
@aarlt
Copy link
Member Author

aarlt commented Mar 27, 2020

@chriseth i'm not sure whether it is good to forbid notice on non-public state variables. it is used a lot by contract developers. Some examples:

  • colonyNetwork @ contracts/ReputationMiningCycle.sol
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
  ...
}
  • OpenZeppelin @ contracts/drafts/ERC20Migrator.sol:
contract ERC20Migrator {
    using SafeERC20 for IERC20;

    /// Address of the old token contract
    IERC20 private _legacyToken;

    /// Address of the new token contract
    ERC20Mintable private _newToken;
    ...
}
  • Solidity Documentation
    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;
        }
    }

@aarlt aarlt force-pushed the structured-docs-variables-aarlt branch 12 times, most recently from 8d0f2ec to 7fa485e Compare March 31, 2020 02:29
@chriseth
Copy link
Contributor

chriseth commented Apr 1, 2020

@aarlt @notice is useless on non-public functions. We can add a warning now and disallow it in 0.7.0.

@aarlt aarlt force-pushed the structured-docs-variables-aarlt branch 5 times, most recently from fb7f327 to c248c78 Compare May 13, 2020 19:34
@chriseth
Copy link
Contributor

Needs rebase.

@aarlt aarlt force-pushed the structured-docs-variables-aarlt branch 2 times, most recently from cab1760 to ce68386 Compare May 14, 2020 17:22
@leonardoalt
Copy link
Member

Needs rebase again. solc-js tests might be fixed then

@aarlt aarlt force-pushed the structured-docs-variables-aarlt branch from ce68386 to 0a38ec8 Compare May 18, 2020 11:05
@chriseth
Copy link
Contributor

Needs rebase.

@@ -82,10 +85,10 @@ Tag
=========== =============================================================================== =============================
``@title`` A title that should describe the contract/interface contract, interface
``@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``@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

``@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``@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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats true, @return should only be allowed on public state-variables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap this line.

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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap this line.

@aarlt aarlt force-pushed the structured-docs-variables-aarlt branch from 0a38ec8 to fc8b934 Compare May 19, 2020 15:57
fulldecent and others added 3 commits May 19, 2020 11:01
- adds natspec generation for state variables.
- exports structured docs for state variables to JSON.
@aarlt aarlt force-pushed the structured-docs-variables-aarlt branch from fc8b934 to af8bb5f Compare May 19, 2020 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow NatSpec comments for variables
7 participants