kauri

2 min read - Posted 28 May 19

Lint your Solidity contracts with Ethlint

Ethlint (Formerly Solium) analyzes your Solidity code for style & security issues and fixes them.

Install

npm install -g ethlint
solium -V

For backward-compatibility, you can still use npm install -g solium.

If you're currently using the solium package for npm install, it is highly recommended that you move to ethlint. The solium package will not receive updates after December, 2019. There are no differences between the updates pushed to ethlint and solium packages.

Usage

In the root directory of your DApp:

solium --init

This creates 2 files for you: - .soliumignore - contains names of files and directories to ignore while linting - .soliumrc.json - contains configuration that tells Solium how to lint your project. You should modify this file to configure rules, plugins and sharable configs.

.soliumrc.json looks like:

{
  "extends": "solium:recommended",
  "plugins": ["security"],
  "rules": {
    "quotes": ["error", "double"],
    "indentation": ["error", 4],
    "linebreak-style": ["error", "unix"]
  }
}

To know which lint rules Solium applies for you, see Style rules and Security rules.

--- NOTE

Solium does not strictly adhere to the Solidity Style Guide. It aims to promote coding practices agreed upon by the community at large.


Lint
solium -f foobar.sol
solium -d contracts/
Configure with comments

Comment Directives can be used to configure Solium to ignore specific pieces of code. They follow the pattern solium-disable<optional suffix>.

If you only use the directive, Solium disables all rules for the marked code. If that's not desirable, specify the rules to disable after the directive, separated by comma.

  • Disable linting on a specific line
contract Foo {
    /* solium-disable-next-line */
    function() {
        bytes32 bar = 'Hello world';    // solium-disable-line quotes

        // solium-disable-next-line security/no-throw, indentation
                        throw;
    }
}
  • Disable linting on entire file
/* solium-disable */

contract Foo {
    ...
}
Fix

Solium automatically fixes your code to resolve whatever issues it can.

solium -d contracts/ --fix

Next steps

Created with Sketch.Content is"CC-BY-SA 4.0" licensed
Article On-chain
Article Author

Kauri Team

113

15

1

0 Comments
Related Articles
Lint your Solidity contracts with Solhint

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

Kauri Team

05 Jun 19

Using Besu, the Java Ethereum Client with Linux/MacOS

Toolbelt: Besu included! Original photo by Jesse Orrico Update: Pantheon is now Hyperledger Besu. For more information, see here. This is the Linux/MacOS version of an article on installing Besu, the Java client for Ethereum: Linux Windows Having some powerful tools in your toolbelt is essential for a Java developer, and one of the crucial tools for an Ethereum blockchain developer is the network client. This is the piece of software that communicates data to and from the blockchain. Among other