Published on

Solidity Style Hint - Definition must be surrounded with two blank line indent - two-lines-top-level-separator

Authors

I was working through an older Solidity contract and came across the following Solhint warning:

Definition must be surrounded with two blank line indent [two-lines-top-level-separator]

I ideally try to get rid of as many warnings in code as possible to avoid any potential nasty errors in future. This warning is more cosmetic but it is still one less thing to worry about.

The piece of code in issue was the following:

pragma solidity ^0.5.0;

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// Safe maths

// ----------------------------------------------------------------------------
contract SafeMath {
...

The line it was giving the error on was the contract SafeMath { one.

I tried different things and Googled this warning but could not work out how to resolve this warning. Eventually after fiddling for a while I worked out that the linder adds up the space before the contract definition ignoring the comments until it hits the pragma block. There are 3 spaces if you use this approach. I changed it to the following and resolved the warning:

pragma solidity ^0.5.0;

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
...

Note the new line that was removed after // Safe maths