protofire / solhint

Solhint is an open-source project to provide a linting utility for Solidity code.
https://protofire.github.io/solhint/
MIT License
1.04k stars 160 forks source link

Strange behaviour in ordering #362

Closed gagiuntoli closed 1 year ago

gagiuntoli commented 2 years ago

I have the following case:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

contract Example {
    uint256 public a;

    constructor() {
        a = 2;
    }

    function functionPublicView() public view returns (bool) {
        return true;
    }

    // solhint-disable-next-line ordering
    function functionPublic() public {
        a = 1;
    }

    function functionExternal() external returns (bool) {
        return true;
    }
}

With this configuration:

{
  "extends": "solhint:recommended",
  "plugins": ["prettier"],
  "rules": {
    "code-complexity": ["error", 8],
    "compiler-version": ["error", ">=0.8.8"],
    "const-name-snakecase": "off",
    "constructor-syntax": "error",
    "func-visibility": ["error", { "ignoreConstructors": true }],
    "ordering": "warn",
    "max-line-length": ["error", 120],
    "not-rely-on-time": "off",
    "prettier/prettier": [
      "error",
      {
        "endOfLine": "auto"
      }
    ],
    "reason-string": ["warn", { "maxLength": 64 }]
  }
}

I would expect solhint to throw an error on the ordering. The external function is after the public ones. But actually, it doesn't throw anything (solhint --config ./.solhint.json file.sol).

Then, if I change in the order (also wrong):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

contract Example {
    uint256 public a;

    constructor() {
        a = 2;
    }

    // solhint-disable-next-line ordering
    function functionPublic() public {
        a = 1;
    }

    function functionPublicView() public view returns (bool) {
        return true;
    }

    function functionExternal() external returns (bool) {
        return true;
    }
}

it fails with the expected error:

contracts/v1/markets/Solhint.sol
  20:5  warning  Function order is incorrect, external  function can not go after public view function (line 16)  ordering

✖ 1 problem (0 errors, 1 warning)
dbale-altoros commented 1 year ago

@gagiuntoli Hello, sorry for the late response. Seems like what is not working is the // solhint-disable-next-line ordering Even tried like this /* solhint-disable */ function functionPublic() public { a = 1; } /* solhint-enable */

But it is still considering that function I will close this issue an open a new one with this bug

Please feel free to add any comment, we really appreciate your feedback We will be working on solhint in a regular basis to improve it !