Part 1: Linter

Solhint and Ethlint (formerly Solium) are two fantastic community linters for the Solidity language. They’re like automatic code reviewers who flag up security errors and instills best practices across the team.

For this tutorial, we’ll focus on Solhint, though I highly recommend you take Ethlint out for a spin as well.

Solhint

First, make sure you are in the project root directory and then use NPM or Yarn to add the solhint module.

> npm install --save-dev solhint

Configuring Solhint

Initialize solhint with a basic configuration file.

> ./node_modules/.bin/solhint init-config

This should create a ./solhint.json file in your project’s root directory. This file specifies exactly which rules you want Solhint to lint for. Solhint has a pretty amazing coverage of Security Rules, Style Guide rules, and Best Practice rules.

One big gotcha: very few of the rules are turned on by default. After some trial and error, I found that solhint:recommended was slightly better (vs. solhint:default that Solhint lists in the documentation.

I’d highly recommend going through the rule lists and adding the ones you want to ./solhint.json . I’ve personally found the security rules and best practices very useful.

Solhint ignores

Similar to .gitignore , you can get solhint to ignore files and folders

node_modules/

migrations/

Solhint Script

Edit your package.json to include a new script to run Solhint.

"solhint": "./node_modules/.bin/solhint -f table contracts/**/*.sol"

The command above has a couple of things to note:

Solhint runs on globs that match a file pattern. In the above, it runs on all **/*.sol files in the contracts directory

runs on globs that match a file pattern. In the above, it runs on all files in the directory -f table presents the findings in a table format. You can choose from other options (e.g. unix , tap )

Solhint in action

> npm run solhint

You’ll likely see a bunch of errors, especially indentation and styling errors. You don’t need to fix these manually! Our next tool (the formatter) will help a lot with this.