reason-string
July 2, 2025 ยท View on GitHub
The {"extends": "solhint:recommended"} property in a configuration file enables this rule.
Description
Require or revert statement must have a reason string and check that each reason string is at most N characters long.
Options
This rule accepts an array of options:
| Index | Description | Default Value |
|---|---|---|
| 0 | Rule severity. Must be one of "error", "warn", "off". | warn |
| 1 | A JSON object with a single property "maxLength" specifying the max number of characters per reason string. | {"maxLength":32} |
Example Config
{
"rules": {
"reason-string": [
"warn",
{
"maxLength": 32
}
]
}
}
Examples
๐ Examples of correct code for this rule
Require with reason string
pragma solidity 0.4.4;
contract A {
function b() public {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
role.bearer[account] = true;
}
}
๐ Examples of incorrect code for this rule
Require without reason string
pragma solidity 0.4.4;
contract A {
function b() public {
require(!has(role, account));
role.bearer[account] = true;
role.bearer[account] = true;
}
}
Version
This rule was introduced in Solhint 5.0.4