Skip to content

Latest commit

 

History

History
147 lines (103 loc) · 2.94 KB

ordering.md

File metadata and controls

147 lines (103 loc) · 2.94 KB
warning layout title
This is a dynamically generated file. Do not edit manually.
default
ordering | Solhint

ordering

Category Badge Default Severity Badge warn

Description

Check order of elements in file and inside each contract, according to the style guide

Options

This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Default to warn.

Example Config

{
  "rules": {
    "ordering": "warn"
  }
}

Examples

👍 Examples of correct code for this rule

All units are in order

pragma solidity ^0.6.0;

import "./some/library.sol";
import "./some/other-library.sol";

    enum MyEnum {
        Foo,
        Bar
    }

    struct MyStruct {
        uint x;
        uint y;
    }

interface IBox {
    function getValue() public;
    function setValue(uint) public;
}

library MyLibrary {
    function add(uint a, uint b, uint c) public returns (uint) {
        return a + b + c;
    }
}

contract MyContract {
    using MyLibrary for uint;

    struct InnerStruct {
        bool flag;
    }

    enum InnerEnum {
        A, B, C
    }

    address payable owner;
    uint public x;
    uint public y;

    event MyEvent(address a);

    modifier onlyOwner {
        require(
            msg.sender == owner,
            "Only owner can call this function."
        );
        _;
    }

    constructor () public {}

    fallback () external {}

    function myExternalFunction() external {}
    function myExternalViewFunction() external view {}
    function myExternalPureFunction() external pure {}

    function myPublicFunction() public {}
    function myPublicViewFunction() public view {}
    function myPublicPureFunction() public pure {}

    function myInternalFunction() internal {}
    function myInternalViewFunction() internal view {}
    function myInternalPureFunction() internal pure {}

    function myPrivateFunction() private {}
    function myPrivateViewFunction() private view {}
    function myPrivatePureFunction() private pure {}
}

👎 Examples of incorrect code for this rule

State variable declaration after function

  contract MyContract {
    function foo() public {}

    uint a;
  }

Library after contract

  contract MyContract {}

  library MyLibrary {}

Interface after library

  library MyLibrary {}

  interface MyInterface {}

Version

This rule was introduced in Solhint 3.2.0

Resources