LoginSignup
6
1

More than 3 years have passed since last update.

solhintのすゝめ

Last updated at Posted at 2020-11-30

結論

Solidityのコードフォーマット、セキュリティチェックはsolhintを使おう

経緯

  1. 今までsoliumを使って、lintをかけていた
  2. 新しいモジュールの開発はSolidity0.5系から0.6系に変更することにした
  3. soliumの開発が現在止まっており、0.6から使えるようになったoverrideやabstractなどの構文に対応していなかった、とても困った
  4. そういえばopenzeppelinは0.6で書かれていたはず、あっちはどうしてるんだろうと思い調べた
  5. openzeppelinはsolhintなるものを使っていた。
  6. 試しに使ってみたらめっちゃいい感じだった。

soliumからsolhitへの移行手順

1. uninstall & install
npmやyarnで置き換えて、package.jsonなどを更新

例)
npm uninstall ethlint   // soliumはethlintに入っている。
npm install solhint

2. 無視ファイルのリネーム
中身の形式はそのままなので、ファイル名だけ変更すればOK

.soliumignoreを.solhintignoreに変更する

3. 設定ファイルの修正
設定ファイルを修正し、中身を書き換える。基本的な記述方法は同じだが、細かい設定はsolhintのdocsを参照して修正する

.soliumrc.jsonを.solhint.jsonに変更する
例)
.soliumrc.jsonの中身
{
    "extends": "solium:recommended",
    "plugins": ["security"],
    "rules": {
        "indentation": ["error", "tab"]
    }
}

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

.solhint.jsonの中身
{
    "extends": "solhint:recommended",
    "rules": {
        "no-empty-blocks": "off",
        "compiler-version": ["error", "0.6.12"]
    }
}

4. エディターの設定変更
以下はVSコードの場合

Code->Preference->Settings
からの
Search settingsで「solidity」で検索
Solidity:Linterを「solhint」に設定

package.jsonのscripts設定

pre-commitなどでlintをかけている場合、コマンドが変更されるので、修正する。
細かなオプションはsolhintのreadmeを参照のこと。

例)
[soliumの場合]
solium --dir contracts --fix

[solhintの場合]
solhint --fix --max-warnings 0 \"contracts/**/*.sol\"
6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1