Skip to content

Latest commit

 

History

History

solhint-graph-config

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

solhint-graph-config

This repository contains shared linting and formatting rules for Solidity projects.

Code linting

Installation

⚠️ Unfortunately there isn't a way to install peer dependencies using Yarn v4, so we need to install them manually.

# Install with peer packages
yarn add --dev solhint solhint-graph-config

# For projects on this monorepo
yarn add --dev solhint solhint-graph-config@workspace:^x.y.z

Configuration

Run solhint with node_modules/solhint-graph-config/index.js as the configuration file. We suggest creating an npm script to make it easier to run:

{
  "scripts": {
    "lint": "solhint --fix --noPrompt contracts/**/*.sol --config node_modules/solhint-graph-config/index.js"
  }
}

Code formatting

Installation

⚠️ Unfortunately there isn't a way to install peer dependencies using Yarn v4, so we need to install them manually.

# Install with peer packages
yarn add --dev solhint-graph-config prettier prettier-plugin-solidity

# For projects on this monorepo
yarn add --dev solhint-graph-config@workspace:^x.y.z prettier prettier-plugin-solidity

Configuration: formatting

Create a configuration file for prettier at prettier.config.js:

const prettierGraphConfig = require('solhint-graph-config/prettier')
module.exports = prettierGraphConfig

Running prettier will automatically pick up the configuration file. We suggest creating an npm script to make it easier to run:

{
  "scripts": {
    "format": "prettier --write 'contracts/**/*.sol'"
  }
}

Tooling

This package uses the following tools:

VSCode support

If you are using VSCode you can install the Solidity extension by Nomic Foundation. Unfortunately there is currently no way of getting real-time linting output from solhint, but this extension will provide formatting support using our prettier config and will also provide inline code validation using solc compiler output.

For formatting, the following settings should be added to your settings.json file:

  "[solidity]": {
    "editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
  },

Additionally you can configure the Format document keyboard shortcut to run prettier --write on demand.