4.5.4 • Published 14 days ago

solhint v4.5.4

Weekly downloads
14,944
License
MIT
Repository
github
Last release
14 days ago

npm.io npm.io Donate with Ethereum NPM version Coverage Status MIT licensed

This is an open source project for linting Solidity code. This project provides both Security and Style Guide validations. VISIT OUR WEBSITE JOIN OUR DISCORD SERVER

Installation

You can install Solhint using npm:

npm install -g solhint

# verify that it was installed correctly
solhint --version

Usage

First initialize a configuration file, if you don't have one:

solhint --init

This will create a .solhint.json file with the default rules enabled. Then run Solhint with one or more Globs as arguments. For example, to lint all files inside contracts directory, you can do:

solhint 'contracts/**/*.sol'

To lint a single file:

solhint contracts/MyToken.sol

Run solhint without arguments to get more information:

Usage: solhint [options] <file> [...other_files]

Linter for Solidity programming language

Options:

  -V, --version                           output the version number
  -f, --formatter [name]                  report formatter name (stylish, table, tap, unix, json, compact, sarif)
  -w, --max-warnings [maxWarningsNumber]  number of allowed warnings
  -c, --config [file_name]                file to use as your .solhint.json
  -q, --quiet                             report errors only - default: false
  --ignore-path [file_name]               file to use as your .solhintignore
  --fix                                   automatically fix problems and show report
  --noPrompt                              do not suggest to backup files when any `fix` option is selected
  --init                                  create configuration file for solhint
  --disc                                  do not check for solhint updates
  --save                                  save report to file on current folder
  -h, --help                              output usage information

Commands:

  stdin [options]                         linting of source code data provided to STDIN
  list-rules                              display covered rules of current .solhint.json

Notes

  • Solhint checks if there are newer versions. The --disc option avoids that check.
  • --save option will create a file named as YYYYMMDDHHMMSS_solhintReport.txt on current folder with default or specified format

Fix

This option currently works on:

  • avoid-throw
  • avoid-sha3
  • no-console
  • explicit-types
  • private-vars-underscore
  • payable-fallback
  • quotes
  • contract-name-camelcase
  • avoid-suicide

Configuration

You can use a .solhint.json file to configure Solhint for the whole project.

To generate a new sample .solhint.json file in current folder you can do:

solhint --init 

This file has the following format:

Default

{
  "extends": "solhint:default"
}

Note

The solhint:default configuration contains only two rules: max-line-length & no-console

Sample

  {
    "extends": "solhint:recommended",
    "plugins": [],
    "rules": {
      "avoid-suicide": "error",
      "avoid-sha3": "warn"
    }
  }

A full list of all supported rules can be found here.

To ignore files that do not require validation you can use a .solhintignore file. It supports rules in the .gitignore format.

node_modules/
additional-tests.sol

Extendable rulesets

The default rulesets provided by solhint are the following:

  • solhint:default
  • solhint:recommended

Use one of these as the value for the "extends" property in your configuration file.

Configure the linter with comments

You can use comments in the source code to configure solhint in a given line or file.

For example, to disable all validations in the line following a comment:

  // solhint-disable-next-line
  uint[] a;

You can disable specific rules on a given line. For example:

  // solhint-disable-next-line not-rely-on-time, not-rely-on-block-hash
  uint pseudoRand = uint(keccak256(abi.encodePacked(now, blockhash(block.number))));

Disable validation on current line:

  uint pseudoRand = uint(keccak256(abi.encodePacked(now, blockhash(block.number)))); // solhint-disable-line

Disable specific rules on current line:

   uint pseudoRand = uint(keccak256(abi.encodePacked(now, blockhash(block.number)))); // solhint-disable-line not-rely-on-time, not-rely-on-block-hash

You can disable a rule for a group of lines:

  /* solhint-disable avoid-tx-origin */
  function transferTo(address to, uint amount) public {
    require(tx.origin == owner);
    to.call.value(amount)();
  }
  /* solhint-enable avoid-tx-origin */

Or disable all validations for a group of lines:

  /* solhint-disable */
  function transferTo(address to, uint amount) public {
    require(tx.origin == owner);
    to.call.value(amount)();
  }
  /* solhint-enable */

Rules

Security Rules

Full list with all supported Security Rules

Style Guide Rules

Full list with all supported Style Guide Rules

Best Practices Rules

Full list with all supported Best Practices Rules

Docker

Solhint has an official Docker Image

Go to docker folder and follow this instructions.

Documentation

Related documentation you may find here.

IDE Integrations

Table of Contents

  • Roadmap: The core project's roadmap - what the core team is looking to work on in the near future.
  • Contributing: The core Solhint team :heart: contributions. This describes how you can contribute to the Solhint Project.
  • Shareable configs: How to create and share your own configurations.
  • Writing plugins: How to extend Solhint with your own rules.

Plugins

Who uses Solhint?

Projects

Acknowledgements

The Solidity parser used is @solidity-parser/parser.

Licence

MIT

Back us

Solhint is free to use and open-sourced. If you value our effort and feel like helping us to keep pushing this tool forward, you can send us a small donation. We'll highly appreciate it :)

Donate with Ethereum

Related projects

  • eth-cli: CLI swiss army knife for Ethereum developers.
xbr@meetusvr/smart-contracts@everything-registry/sub-chunk-2795@axelar-network/token-linker@defi.org/web3-candies@defi-wonderland/solhint-plugin@ieigen/zkzru@idecentralize/pulsarcoc-sol@innoswap/core@hashgraph/stablecoin-npm-contractsbugscantea@materia-dex/materia-contracts-proxyguesser-contracts@layerzerolabs/solhint-config@cuongvn/state-relayer-bot-2@cuongvn/state-relayer-bot-1@cuongvn/state-relayer-bot-random@dev-extralabs/web3githereum@luxdefi/hardhat@m.arefev/nft@llllvvuu/vscode-solidity-langserver@mimic-fi/v1-contractstokenteasolidityscribesolidity-language-serversolivesolhint-config-mimicsolhint-plugin-defi-wonderlandsolhint-plugin-extsolhint-plugin-wonderlandsolhint-plugin-avoid-consoleroninjin10state-relayer-botstate-relayer-bot-1rewards-farmertruffle-plugin-solhintvscode-solidity-serverwepublic-contracts@carlos0202/local-testnet-deployer@soundxyz/protocolinherichain@withtally/local-testnet-deployer@wen-protocol/propel@richeroneren/fast-presale@nomiclabs/buidler-solhint@nomiclabs/hardhat-solhint@nori-dot-com/eslint-config-nori@ourz/our-contracts@settlemint/enteth-contractsembark-solhint@tracer-protocol/contracts@timeswap-labs/timeswap-v1-convenience@titan-suite/cli@etherisc/gif@ethronpi/solidity@ethronjs/plugin.solidity@flarenetwork/ftso_price_provider_kick_off_package_test@flarenetwork/ftso_price_provider_kick_off_packagenumbertowords-solidity@0xzebra/core@0xpropel/core@aaiello/arkive-hardhat@aaiello/hardhatasset-token@animoca/ethereum-contracts-core_librarygelato-relay-testgelato-thirdweb-relay@arx-research/ers-contracts
4.5.4

14 days ago

4.5.3

14 days ago

4.5.0

1 month ago

4.5.2

1 month ago

4.5.1

1 month ago

4.1.0

4 months ago

4.1.1

4 months ago

4.0.0

6 months ago

3.6.2

8 months ago

3.6.1

9 months ago

3.5.1

9 months ago

3.3.8

1 year ago

3.4.0

1 year ago

3.4.1

1 year ago

3.3.7

2 years ago

3.3.6

3 years ago

3.3.5

3 years ago

3.3.4

3 years ago

3.3.3

3 years ago

3.3.2

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago

3.0.0-rc.8

4 years ago

3.0.0-rc.7

4 years ago

2.3.1

4 years ago

3.0.0-rc.6

4 years ago

3.0.0-rc.5

4 years ago

3.0.0-rc.4

4 years ago

3.0.0-rc.3

4 years ago

3.0.0-rc.2

4 years ago

3.0.0-rc.1

4 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

2.0.0-beta.2

5 years ago

1.5.1

5 years ago

2.0.0-beta.1

5 years ago

2.0.0-alpha.3

5 years ago

2.0.0-alpha.2

5 years ago

2.0.0-alpha.1

5 years ago

2.0.0-alpha.0

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago