Skip to content

chore(lint): add exception to mixed-case-function rule when referring to constant functions in interfaceΒ #11315

@smol-ninja

Description

@smol-ninja

Component

Forge

Describe the feature you would like

Problem

Take the below example,

interface ICounter {
    function MAX_NUMBER() external view returns (uint256);
}

contract Counter is ICounter {
    uint256 public constant override MAX_NUMBER = 100;
}

forge lint would throw mixed-case-function: function names should use mixedCase whereas this is a valid function name since its referring to a constant (SNAKE_CASE) in the contract.

Solution

An exception could be added when the following rules are met:

  • Be declared in an interface.
  • Have external view visibility and mutability.
  • Have zero parameters.
  • Have exactly one return value.
  • The return type must be one of the following:
  • An elementary type (uint*, int*, bool, address, string, bytes, bytesN).
  • An enum.
  • A user-defined value type (UDVT) based on an elementary type (e.g. UD60x18).
  • A contract/interface type (e.g. IERC20).
  • Not allowed: arrays, tuples, structs, or any return type with a storageLocation (memory/calldata).

Also see protofire/solhint#699 where I raised a similar issue.

Note: this behaviour is a result of the latest foundry upgrade.

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Completed

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions