Socket
Socket
Sign inDemoInstall

solhint

Package Overview
Dependencies
5
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

solhint


Version published
Maintainers
1
Install size
15.6 MB
Created

Readme

Source

Solhint Project

Build Status npm version Coverage Status

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

Installation

For install project you need to execute next commands

npm install -g solhint
solhint -V

Usage

For linting Solidity files you need to execute next command

solhint *.sol **/*.sol <any_other_glob_pattern>

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

Configuration file has next format:

  {
    "extends": "default",
    "rules": {
      "avoid-throw": false,
      "avoid-suicide": "error",
      "avoid-sha3": "warn",
      "indent": ["warn", 4]
    }
  }

Configure linter with comments

Disable validation on next line

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

Disable validation of fixed compiler version validation on 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

Disable linter rules for code fragment

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

Disable all linter rules for code fragment

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

Security Rules

Rule IDError
reentrancyPossible reentrancy vulnerabilities. Avoid state changes after transfer.
avoid-sha3Use "keccak256" instead of deprecated "sha3"
avoid-suicideUse "selfdestruct" instead of deprecated "suicide"
avoid-throw"throw" is deprecated, avoid to use it
func-visibilityExplicitly mark visibility in function
state-visibilityExplicitly mark visibility of state
check-send-resultCheck result of "send" call
avoid-call-valueAvoid to use ".call.value()()"
compiler-fixedCompiler version must be fixed
compiler-gt-0_4Use at least '0.4' compiler version
no-complex-fallbackFallback function must be simple
mark-callable-contractsExplicitly mark all external contracts as trusted or untrusted
multiple-sendsAvoid multiple calls of "send" method in single transaction
no-simple-event-func-nameEvent and function names must be different
avoid-tx-originAvoid to use tx.origin
no-inline-assemblyAvoid to use inline assembly. It is acceptable only in rare cases
not-rely-on-block-hashDo not rely on "block.blockhash". Miners can influence its value.
avoid-low-level-callsAvoid to use low level calls.

* - All security rules implemented according ConsenSys Guide for Smart Contracts

Style Guide Rules

Rule IDError
func-name-mixedcaseFunction name must be in camelCase
func-param-name-mixedcaseFunction param name must be in mixedCase
var-name-mixedcaseVariable name must be in mixedCase
event-name-camelcaseEvent name must be in CamelCase
const-name-snakecaseConstant name must be in capitalized SNAKE_CASE
modifier-name-mixedcaseModifier name must be in mixedCase
contract-name-camelcaseContract name must be in CamelCase
use-forbidden-nameAvoid to use letters 'I', 'l', 'O' as identifiers
visibility-modifier-orderVisibility modifier must be first in list of modifiers
imports-on-topImport statements must be on top
two-lines-top-level-separatorDefinition must be surrounded with two blank line indent
func-orderFunction order is incorrect
quotesUse double quotes for string literals
no-mix-tabs-and-spacesMixed tabs and spaces
indentIndentation is incorrect
bracket-alignOpen bracket must be on same line. It must be indented by other constructions by space
array-declaration-spacesArray declaration must not contains spaces
separate-by-one-line-in-contractDefinitions inside contract / library must be separated by one line
expression-indentExpression indentation is incorrect.
statement-indentStatement indentation is incorrect.
space-after-commaComma must be separated from next element by space
no-spaces-before-semicolonSemicolon must not have spaces before

* - All style guide rules implemented according Solidity Style Guide

Best Practise Rules

Rule IDError
max-line-lengthLine length must be no more than 120 but current length is 121.
payable-fallbackWhen fallback is not payable you will not be able to receive ethers
no-empty-blocksCode contains empty block
no-unused-varsVariable "name" is unused
function-max-linesFunction body contains "count" lines but allowed no more than "maxLines" lines
code-complexityFunction has cyclomatic complexity "current" but allowed no more than "max"
max-states-countContract has "curCount" states declarations but allowed no more than "max"

Documentation

Related documentation you may find there.

IDE Integrations

Licence

MIT

Keywords

FAQs

Last updated on 01 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc