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

fix: compile contracts before generating docs #7369

Merged
merged 3 commits into from
Mar 12, 2024

Conversation

kamuik16
Copy link
Contributor

Motivation

While solving the issue #7331, I tested the forge doc on a sample contract.

Example to reproduce the issue:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface IERC20 {
    /**
    * @notice Mints `amount` token to `recipient`.
    * @param  recipient The address of the account receiving minted token.
    * @param  amount    The amount of token to mint.
    */
    function mint(address recipient, uint256 amount) external;
}

contract Test is IERC20 {
    /// @inheritdoc IERC20
    function mint(someType recipient, someType amount) external onlyOwner {}
}

Here you can some issues like someType is not a valid variable type and also onlyOwner isn't defined. But if we run forge doc here, it runs successfully without giving any errors and gives an output like this.

**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`recipient`|`someType`|The address of the account receiving minted token.|
|`amount`|`someType`|   The amount of token to mint.|

You can see in the type someType comes which is not a valid solidity type.

Solution

compile contracts before running forge doc.

If we now run the forge doc, it will give an error of something like this:

[⠒] Compiling...
[⠢] Compiling 1 files with 0.8.24
[⠆] Solc 0.8.24 finished in 25.80ms
Error:
Compiler run failed:
Error (7920): Identifier not found or not unique.
  --> src/Test.sol:15:19:
   |
15 |     function mint(someType recipient, someType amount) external onlyOwner {}
   |                   ^^^^^^^^

Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

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

lgtm

@onbjerg onbjerg changed the title 7331 extended: forge doc doesn't compile the contracts before generating the doc fix: compile contracts before generating docs Mar 12, 2024
@kamuik16
Copy link
Contributor Author

lgtm

Hey @onbjerg! I have made this changes, just letting you know.
let compiler = ProjectCompiler::new(); --> let compiler = ProjectCompiler::new().quiet(true); to run the forge compile silently.

@onbjerg
Copy link
Member

onbjerg commented Mar 12, 2024

sgtm

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

that makes sense, ty

@mattsse mattsse merged commit d3b8d15 into foundry-rs:master Mar 12, 2024
19 checks passed
@kamuik16 kamuik16 deleted the issue7331-extended branch March 12, 2024 12:19
@MOZGIII
Copy link

MOZGIII commented Jun 28, 2024

This broke ignore option as it is not respected when the contract is compiled

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.

4 participants