The {“extends”: “solhint:recommended”} property in a configuration file enables this rule.
Immutable variables should not be used in state variable initializers before they are declared.
This rule accepts a string option for rule severity. Must be one of “error”, “warn”, “off”. Defaults to warn.
{
"rules": {
"no-immutable-before-declaration": "warn"
}
}
contract Immutables {
uint256 internal immutable immB = 25;
uint256 public immA = immB + 100; // OK, immB is already declared
}
contract Immutables {
uint256 public constA = constB + 100; // OK, constants are compile-time
uint256 internal constant constB = 50;
}
contract Immutables {
uint256 public immA = immB + 100; // BAD: immB declared later
uint256 internal immutable immB = 25;
}
This rule was introduced in the latest version.