Solium: Write your Solidity code with style

Chih-Cheng Liang
Taipei Ethereum Meetup
3 min readJul 27, 2017
Solium linting in Visual Studio Code

Like most of the programming languages these days, the currently most widely used smart contract language, Solidity, has a linter that helps your team write high quality code with good coding style. Solium, maintained by duaraghav8 and other contributors, is the tool.

Getting started

Solium is a nodejs package, install with:

npm install -g git+https://github.com/duaraghav8/Solium.git

It’s highly configurable. You’ll need to initialize some configs in your project directory, we’ll explain these later.

solium --init

Let’s lint through the directory.

solium --dir .

That’s it! You should now see a bunch of coding style warnings and errors.

Customization

solium --init gives you two configs, .soliumrc.json and .soliumignore. Specify what rules you would (not) like to follow in former, what files you would not like to lint in later.

The package is well documented, reading more at it’s Github repository is highly recommended.

Integrate with Visual Studio Code

Visual Studio Code is by far the best editor I’ve been enjoying with, and is of course the default editor I use to develop Solidity code.

You can use Solium with Visual Studio in two ways.

The easy way: Solidity Extended

Install Solidity Extended, a Visual Studio Code package maintained by beaugunderson, done.

The downside is, the Solium customization feature is currently not available.

The hacky way: Visual Studio Code Task

Visual Studio Code allows you to customize build or test tasks specific to your project directory.

In Mac, enter Cmd+shift+b in the editor and see a popup message shows.

Click the “Configure Build Task” and paste the following to the tasks.json .

Enter Cmd+shift+b again, and you should see the linter run. Voila! warnings and errors will shown directly on your source code.

Recommend and subscribe to Taipei Ethereum Meetup Publication.

Ether address: 0x004864DeD3ca499D2f46BF74246E29b494610f5E

References

--

--