Giter Club home page Giter Club logo

primitive-dodoc's Introduction

Dodoc

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 @primitivefi/hardhat-dodoc

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

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

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

// Using ES6 or TypeScript
import '@primitivefi/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
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.

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), and can generate documentation for events, custom errors and external / public functions.

🔧 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 '@primitivefinance-dodoc';

const config: HardhatUserConfig = {
  // Your Hardhat config...
  dodoc: {
    runOnCompile: true,
    testMode: 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 names to include in the documentation generation. An empty array will generate documentation for everything []
exclude List of all the contract / interface / library names to exclude from the documentation generation []
outputDir Output directory of the documentation docs
templatePath Path to the documentation template ./template.sqrl
testMode Test mode generating additional JSON files used for debugging false

💅 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 and internal functions is not rendered. Hence, the documentation of libraries might be close to empty!
  • 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.
  • Special functions such as constructor, fallback and receive might not be rendered.
  • Custom NatSpec tags @custom:... are not rendered (yet).

primitive-dodoc's People

Contributors

clemlak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.