Published on

Sane Solium Configuration for the Solidity VS Code Plugin

Authors

When I started deving dApps with solidity I found that VS code with the solidity extension were the lightest and easiest to use.

One thing that has driven me insane ever since using this setup is the "errors" that get flagged for spacing and single vs double quote warnings.

Today I looked into what can be configured for this plugin and came up with the below which marks quote and spacing issues as warnings instead of errors:

"solidity.enabledAsYouTypeCompilationErrorCheck": true,
  "solidity.validationDelay": 1500,
  "solidity.linter": "solium",
  "solidity.soliumRules": {
    "quotes": ["warning", "double"],
    "security/enforce-explicit-visibility": ["error"],
    "security/max-statements-in-func": ["error"],
    "security/no-var": ["error"],
    "indentation": ["warning", 4]
}

With the above configuration only actual errors will be underlined in red. Warnings will be green. This helps prevent plenty more errors as these spacing warnings were adding too much noise to code to actually see real errors. I also enabled:

  • "solidity.enabledAsYouTypeCompilationErrorCheck": true: Compilation as I type so I can see errors as soon as possible.
  • enforce-explicit-visibility: A security rule to force visibility to be specified explicitly otherwise mark it as an error.
  • max-statements-in-func: This by default gives an error if there are more than 25 statements in a function (more than 25 statements make code difficult to read - increasing the likelihood that a logic error could be introduced).

Solium rules are generally of the following format:

"rule-name-you-want": ["lint-severity", "param-1", "parma-2", ..., "param-n" ]
  • lint-severity: can be
    • error => a red squiggly in VS Code.
    • warning => a green squiggly in VS Code.
    • off => no visual indication will be given at all in VS Code if this rule is violated.
  • param: this is very dependent on the rule you are using and may not even be needed depending on the rule. This can be a string, number or boolean (just based on the rules I have seen anyway).

More on Solium:

  • Configuration can be found here.
  • Style rules can be found here.
  • Security rules (when using the security plugin) can be found here.