Git Product home page Git Product logo

solhint's Introduction

Solhint Project

Donate with Ethereum

Gitter chat Build Status NPM version Coverage Status MIT licensed dependencies Status devDependencies Status

This is an open source project for linting Solidity code. This project provides both Security and Style Guide validations.

Installation

You can install Solhint using npm:

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 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

Solhint command description:

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
  -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
  -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:

  {
    "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.

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:

  // 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:

  // solhint-disable-next-line compiler-fixed, compiler-gt-0_4
  pragma solidity ^0.4.4;

Disable validation on current line:

  pragma solidity ^0.4.4; // solhint-disable-line

Disable validation of fixed compiler version validation on current line:

  pragma solidity ^0.4.4; // solhint-disable-line compiler-fixed, compiler-gt-0_4

You can disable a rule for a group of lines:

  /* solhint-disable avoid-throw */
  if (a > 1) {
    throw;
  }
  /* solhint-enable avoid-throw */

Or disable all validations for a group of lines:

  /* solhint-disable */
  if (a > 1) {
    throw;
  }
  /* 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

Prettier (experimental)

If you have prettier-plugin-solidity installed, you can use the prettier/prettier rule for reporting differences between your code and how prettier would format it. If you enable this rule, you should disable some of the style guides rules (mainly quotes, indent and two-lines-top-level-separator).

Documentation

Related documentation you may find there.

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 ❤️ contributions. This describes how you can contribute to the Solhint Project.

Acknowledgements

The grammar used by solhint was created and is maintained by Federico Bond. You can find it here.

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

Who uses Solhint?

OpenZeppelin POA Network - Public EVM Sidechain 0x GNOSIS

Projects

solhint's People

Contributors

idrabenia avatar fvictorio avatar florblue avatar pablofullana avatar nventuro avatar unjapones avatar mgarciap avatar mariano-aguero avatar maurelian avatar sohkai avatar dreigada avatar fernandomg avatar

Watchers

James Cloos avatar Bigdot avatar  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.