Solhint

Solhint

Community Analyzer

Solidity v0.8.18 introduced named parameters on the mappings definition SOLHINT-W1027

Style
Minor

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

Bad Practice

  1. No naming at all in regular mapping
mapping(address => uint256)) public tokenBalances;
  1. Missing any variable name in regular mapping uint256
mapping(address token => uint256)) public tokenBalances;
  1. Missing any variable name in regular mapping address
mapping(address => uint256 balance)) public tokenBalances;
  1. No MAIN KEY naming in nested mapping. Other naming are not enforced
mapping(address => mapping(address token => uint256 balance)) public tokenBalances;

Recommended

  1. To enter "users" mapping the key called "name" is needed to get the "balance"
mapping(string name => uint256 balance) public users;
  1. 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;
  1. Main key of mapping is enforced. On nested mappings other naming are not neccesary
mapping(address owner => mapping(address => uint256)) public tokenBalances;
  1. Main key of the parent mapping is enforced. No naming in nested mapping uint256
mapping(address owner => mapping(address token => uint256)) public tokenBalances;
  1. Main key of the parent mapping is enforced. No naming in nested mapping address
mapping(address owner => mapping(address => uint256 balance)) public tokenBalances;

Learn more

named-parameters-mapping on Solhint's documentation.