npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@b00ste/hardhat-dodoc

v0.3.16

Published

Zero-config Hardhat plugin to generate documentation for all your Solidity contracts

Downloads

55

Readme

Dodoc

version npm license

Zero-config Hardhat plugin to generate documentation for all your Solidity contracts.

  • 🤪 Zero-configuration required
  • ✅ Compatible with latest Solidity versions (>= 0.8.0)
  • 🔍 Supports events, errors and external / public functions
  • 📖 Default output to Markdown
  • 🔧 Extendable using custom templates

Want to see a live example? Check out Primitive documentation!

📦 Installation

First thing to do is to install the plugin in your Hardhat project:

# Using yarn
yarn add @b00ste/hardhat-dodoc

# Or using npm
npm i @b00ste/hardhat-dodoc

Next step is simply to include the plugin into your hardhat.config.js or hardhat.config.ts file:

// Using JavaScript
require('@b00ste/hardhat-dodoc');

// Using ES6 or TypeScript
import '@b00ste/hardhat-dodoc';

And you're done! Documentation will be automatically generated on the next compilation and saved into the docs folder at the root of your project.

📝 Usage

The only requirement to use Dodoc is to comment your Solidity contracts using NatSpec format. For example, given the following function:

/// @notice Does another thing when the function is called.
/// @dev More info about doing another thing when the function is called.
/// @param num A random number
/// @return A random variable
/// @custom:requirement Must be at lease 18 years old to use this function.
/// @custom:danger Another thing is extremely random, use at your own risk!
/// @custom:info Another thing 2 coming soon.
function anotherThing(uint256 num) external pure returns (uint256);

Dodoc will take care of everything and will generate the following output:

Methods

anotherThing

function anotherThing(uint256 num) external pure returns (uint256)

Does another thing when the function is called.

More info about doing another thing when the function is called.

Requirement: Must be at lease 18 years old to use this function.

Danager: Another thing is extremely random, use at your own risk!

Info: Another thing 2 coming soon.

Parameters

| Name | Type | Description | | ---- | ------- | --------------- | | num | uint256 | A random number |

Returns

| Name | Type | Description | | ---- | ------- | ----------------- | | _0 | uint256 | A random variable |

Dodoc is compatible with all the NatSpec tags (except custom ones for now), and can generate documentation for events, custom errors and external / public functions.

By default Dodoc generates new documentation after each compilation, but you can also trigger the task with the following command:

# Using yarn
yarn hardhat dodoc

# Or using npx
npx hardhat dodoc

🔧 Config

Dodoc comes with a default configuration but you can still tweak some parameters. To do it, change your Hardhat config file like this:

import { HardhatUserConfig } from 'hardhat/config';
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-ethers';
import '@b00ste/hardhat-dodoc';

const config: HardhatUserConfig = {
  // Your Hardhat config...
  dodoc: {
    runOnCompile: true,
    debugMode: true,
    // More options...
  },
};

export default config;

Here are all the configuration parameters that are currently available, but as said above, all of them are entirely optional:

| Parameter | Description | Default value | | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------- | | runOnCompile | True if the plugin should generate the documentation on every compilation | true | | include | List of all the contract / interface / library relative paths or names to include in the documentation generation. An empty array will generate documentation for everything | [] | | exclude | List of all the contract / interface / library relative paths or names to exclude from the documentation generation | [] | | libraries | Used to separate the generated docs into two folders: 1. contracts & 2. libraries. Add the relative paths or name of the library to the array if you want to separate it to the libraries folder. | [] | | outputDir | Output directory of the documentation | docs | | templatePath | Path to the documentation template | ./template.sqrl | | debugMode | Test mode generating additional JSON files used for debugging | false | | keepFileStructure | True if you want to preserve your contracts file structure in the output directory | true | | freshOutput | True if you want to clean the output directory before generating new documentation | true | | helpers | List of objects with helperName & helperFunc, helperFunc MUST be of type HelperFunction from squirrelly.js | [] |

💅 Customize

Dodoc integrates a super cool template engine called SquirrellyJS, allowing anyone to create new output formats easily.

You can checkout the default Markdown template to get some inspiration, as well as SquirrellyJS documentation to learn more about it. Feel free to be creative, any kind of output such as Markdown, MDX, HTML or even JSON is supported!

Once you're satisfied, simply refer to your template using the templatePath parameter in your configuration and Dodoc will use it to output the documentation!

⛑ Help

Feel free to open an issue if you need help or if you encounter a problem! Here are some already known problems though:

  • Due to the technical limitations of the Solidity compiler, the documentation of private functions is not rendered.
  • Functions that are not commented at all might not be rendered.
  • State variables overriding functions defined by an interface might "erase" the name of the parameters. A current workaround is to name the function parameters using the _0, _1, ... format.