sort-modifiers
🔧 Problems reported by this rule can be automatically fixed by using the
--fixflag
Enforces a specific order for functions and state variable modifiers.
Rule details
Section titled “Rule details”The enforced order for functions is:
- Visibility modifiers (
public,private,internal,external) - State mutability modifiers (
pure,view,payable) - The
virtualmodifier - The
overridemodifier - Custom modifiers
The enforced order for state variables is:
- Visibility modifiers (
public,private,internal) - Storage location (
constant,immutable,transient)
Examples of correct code for this rule:
contract Example { uint public constant x = 1;
function f() public pure virtual override myModifier {}}Examples of incorrect code for this rule:
contract Example { uint immutable private x = 1;
function f() myModifier public pure virtual override {}}