UNPKG

solhint

Version:
185 lines (131 loc) 6.28 kB
# Solhint Project [![Build Status](https://travis-ci.org/protofire/solhint.svg?branch=master)](https://travis-ci.org/protofire/solhint) [![NPM version](https://badge.fury.io/js/solhint.svg)](https://npmjs.org/package/solhint) [![Coverage Status](https://coveralls.io/repos/github/protofire/solhint/badge.svg?branch=master)]( https://coveralls.io/github/protofire/solhint?branch=master) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/protofire/solhint/master/LICENSE) [![dependencies Status](https://david-dm.org/protofire/solhint/status.svg)](https://david-dm.org/protofire/solhint) [![devDependencies Status](https://david-dm.org/protofire/solhint/dev-status.svg)](https://david-dm.org/protofire/solhint?type=dev) This is an open source project for linting [Solidity](http://solidity.readthedocs.io/en/develop/) code. This project provides both **Security** and **Style Guide** validations. ## Installation You can install Solhint using **npm**: ```sh npm install -g solhint # verify that it was installed correctly solhint -V ``` ## Usage For linting Solidity files you need to run Solhint with one or more [Globs](https://en.wikipedia.org/wiki/Glob_(programming)) as arguments. For example, to lint all files inside `contracts` directory, you can do: ```sh solhint "contracts/**/*.sol" ``` To lint a single file: ```sh solhint contracts/MyToken.sol ``` Solhint command description: ```text 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) -w, --max-warnings [maxWarningsNumber] number of warnings to trigger nonzero -q --quiet report errors only - default: false --ignore-path [file_name] file to use as your .solhintignore -h, --help output usage information Commands: stdin [options] put source code to stdin of this utility init-config create sample solhint config in current folder ``` ## Configuration You can use a `.solhint.json` file to configure Solhint globally. This file has the following format: ```json { "extends": "default", "rules": { "avoid-throw": false, "avoid-suicide": "error", "avoid-sha3": "warn", "indent": ["warn", 4] } } ``` To ignore files / folders that do not require validation you may use `.solhintignore` file. It supports rules in `.gitignore` format. ```git exclude node_modules/ additiona-tests.sol ``` ### Configure 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: ```javascript // solhint-disable-next-line uint[] a; ``` You can disable a single rule on a given line. For example, to disable validation of fixed compiler version in the next line: ```text // solhint-disable-next-line compiler-fixed, compiler-gt-0_4 pragma solidity ^0.4.4; ``` Disable validation on current line: ```text pragma solidity ^0.4.4; // solhint-disable-line ``` Disable validation of fixed compiler version validation on current line: ```text pragma solidity ^0.4.4; // solhint-disable-line compiler-fixed, compiler-gt-0_4 ``` You can disable a rule for a group of lines: ```javascript /* solhint-disable avoid-throw */ if (a > 1) { throw; } /* solhint-enable avoid-throw */ ``` Or disable all validations for a group of lines: ```javascript /* solhint-disable */ if (a > 1) { throw; } /* solhint-enable */ ``` ## Rules ### Security Rules [Full list with all supported Security Rules](https://github.com/protofire/solhint/blob/master/docs/rules.md#security-rules) ### Style Guide Rules [Full list with all supported Style Guide Rules](https://github.com/protofire/solhint/blob/master/docs/rules.md#style-guide-rules) ### Best Practices Rules [Full list with all supported Best Practices Rules](https://github.com/protofire/solhint/blob/master/docs/rules.md#best-practise-rules) ## Documentation Related documentation you may find [there](https://protofire.github.io/solhint/). ## IDE Integrations - **[Sublime Text 3](https://packagecontrol.io/search/solhint)** - **[Atom](https://atom.io/packages/atom-solidity-linter)** - **[Vim](https://github.com/sohkai/syntastic-local-solhint)** - **[JetBrains IDEA, WebStorm, CLion, etc.](https://plugins.jetbrains.com/plugin/10177-solidity-solhint)** - **[VS Code: Solidity by Juan Blanco]( https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity)** - **[VS Code: Solidity Language Support by CodeChain.io]( https://marketplace.visualstudio.com/items?itemName=kodebox.solidity-language-server)** ## Acknowledgements The grammar used by solhint was created and is maintained by [Federico Bond](https://github.com/federicobond). You can find it [here](https://github.com/solidityj/solidity-antlr4). ## Licence MIT ## Who uses solhint? [<img src="https://avatars2.githubusercontent.com/u/28943015?s=200&v=4" width="75px" height="75px" alt="POA Network - Public EVM Sidechain" title="POA Network - Public EVM Sidechain" style="margin: 20px 20px 0 0" />](https://github.com/poanetwork) [<img src="https://avatars3.githubusercontent.com/u/24832717?s=200&v=4" width="75px" height="75px" alt="0x" title="0x" style="margin: 20px 20px 0 0" />](https://github.com/0xProject) [<img src="https://avatars1.githubusercontent.com/u/24954468?s=200&v=4" width="75px" height="75px" alt="GNOSIS" title="GNOSIS" style="margin: 20px 20px 0 0"/>](https://github.com/gnosis) ### Projects - POA Network - Public EVM Sidechain: - [Proof of Physical Address (PoPA)](https://github.com/poanetwork/poa-popa) - [Proof of Bank Account (PoBA)](https://github.com/poanetwork/poa-poba) - [0x](https://github.com/0xProject/0x-monorepo/tree/development/packages/contracts) - Gnosis: - [Gnosis Prediction Market Contracts](https://github.com/gnosis/pm-contracts) - [The DutchX decentralized trading protocol](https://github.com/gnosis/dex-contracts)