solhint

named-parameters-mapping

Category Badge Default Severity Badge warn

Description

Solidity v0.8.18 introduced named parameters on the mappings definition.

Options

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

Example Config

{
  "rules": {
    "named-parameters-mapping": "warn"
  }
}

Examples

👍 Examples of correct code for this rule

To enter “users” mapping the key called “name” is needed to get the “balance”

mapping(string name => uint256 balance) public users;

To enter owner token balance, the main key “owner” enters another mapping which its key is “token” to get its “balance”

mapping(address owner => mapping(address token => uint256 balance)) public tokenBalances;

Main key of mapping is enforced. On nested mappings other naming are not neccesary

mapping(address owner => mapping(address => uint256)) public tokenBalances;

Main key of the parent mapping is enforced. No naming in nested mapping uint256

mapping(address owner => mapping(address token => uint256)) public tokenBalances;

Main key of the parent mapping is enforced. No naming in nested mapping address

mapping(address owner => mapping(address => uint256 balance)) public tokenBalances;

👎 Examples of incorrect code for this rule

No naming at all in regular mapping

mapping(address => uint256)) public tokenBalances;

Missing any variable name in regular mapping uint256

mapping(address token => uint256)) public tokenBalances;

Missing any variable name in regular mapping address

mapping(address => uint256 balance)) public tokenBalances;

No MAIN KEY naming in nested mapping. Other naming are not enforced

mapping(address => mapping(address token => uint256 balance)) public tokenBalances;

Version

This rule was introduced in Solhint 3.4.0

Resources