Comments (11)
Thanks, Diego!
What do you mean it doesn't make sense to name the nested ones ?
Let's take a simpler example:
mapping(uint foo => mapping(uint bar => uint256 baz));
The above is totally fine. What is not fine is to name the nested mapping itself, like this:
mapping(uint foo => mapping(uint bar => uint256 baz) nestedMapping);
The code above compiles but it doesn't make sense to define the nested mapping.
from solhint.
Ok, I will review this one I think the two nested mapping inside one is causing the false positive...
But regarding the other comment...
What do you mean it doesn't make sense to name the nested ones ?
This example names the nested mapping and in my opinion it does make sense
mapping(address owner => mapping(address token => uint256 balance)) public tokenBalances
Maybe I misunderstood your point ?
from solhint.
Also: I think the second snippet that Paul shared shouldn't be enforced, but it shouldn't be forbidden either. I don't think anyone will add names there, but forbidding it doesn't seem necessary.
from solhint.
Yup, agree; not enforcing but not forbidding either sounds like the best approach to take here.
from solhint.
Really ? The point of this addition it is just giving information about the enter key to the mapping and what the mapping contains in each "cell" on top of the mapping name...
This example that was mention (@PaulRBerg)
mapping(uint foo => mapping(uint bar => uint256 baz));
Is missing the mapping name, so what do you mean by 'it is totally fine' ?...
So, as I understand, you agree that this information only makes sense in the MAIN mapping, but it is useless in the nested ones ?
mapping(address owner => mapping(address token => uint256 balance)) public tokenBalances
This one shows info about the main enter key, the second enter key and the content... Don't see anything that doesn't make sense here... At most it is a bit 'over explained' ?
But it's ok. You guys are here long before me and your approach is simpler in terms of coding... I can fix it that way...
So if the rule is ON:
Will check only the naming of the KEY of the MAIN mapping and give an error if it is not present
And left alone the other named parameters on the mapping (doesn't matter if they exist or not)... no report of them...
Is that OK ?
@fvictorio
from solhint.
Shoot, I made an error in the OP. I meant to say that the name of the parent mapping SHOULD be enforced, but not the names of the nested mappings. I forgot to name the parent mapping in my example.
you agree that this information only makes sense in the MAIN mapping, but it is useless in the nested ones ?
Yes.
Will check only the naming of the KEY of the MAIN mapping and give an error if it is not present
Yes.
from solhint.
@PaulRBerg what about a simple mapping ?
Following the logic of your example... this is OK:
mapping(address token => uint256) public tokenBalances;
and this is also ok
mapping(address token => uint256 balance) public tokenBalances;
Naming of the uint256 (balance)
should not be enforced in a simple mapping, right ?
Or the no-enforcement applies only to nested mappings ?
from solhint.
I was mostly thinking about nested mappings; I think the naming should still be enforced for values because they may not be inferable from the name of the parent mapping.
from solhint.
@PaulRBerg
Ok , so to be clear. The rule will work as follow:
For regular mapping, this is the only way to write them and both variable naming should be enforced:
mapping(address token => uint256 balance) public tokenBalances;
For nested mapping
- The MAIN KEY variable (the entrance of the main mapping) should be named and this is enforced...
- Every other variable can be named or not... this is not enforced
from solhint.
Yes.
from solhint.
fixed on #421
from solhint.
Related Issues (20)
- the reentrancy rules is out-of-date HOT 1
- The `var-name-mixedcase` rule triggers when using `$` as a variable name HOT 1
- Default is not catching any errors. HOT 4
- Setup solhint to fail github CI on any warning with `--max-warnings 0` HOT 4
- dynamic loading of rules breaks bundlers HOT 3
- New rule `func-named-parameters` enforced on built-in functions HOT 9
- Enforce underscore for internal or private functions HOT 1
- Low sensitivity of explicit-types HOT 3
- Can't install solhint through yarn/npm package manager HOT 2
- "no-empty-blocks": ["error", { "ignoreConstructors": true }] not working HOT 6
- e2e tests to fixable rules and store report to file (?)
- Make custom-errors rules check only from version it appearead HOT 1
- Allow Solhint report to be exported to file HOT 1
- The comprehensive-interface rule results in compiler warning: Interface functions are implicitly "virtual" HOT 7
- Add an official docker image for solhint HOT 3
- private-vars-leading-underscore on internal functions in libraries is not a best practice HOT 2
- Make fallback functions 'external' HOT 1
- Solhint npm installed executable won't run - throws error "Unexpected Token" HOT 1
- `explicit-types` autofix issues HOT 3
- When throwing ConfigMissingError, keep error message succint HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solhint.