solhint icon indicating copy to clipboard operation
solhint copied to clipboard

allow immutable state variables to be named in CAPS_SNAKE_CASE

Open quezak opened this issue 4 years ago • 5 comments

This is more of a question than a bug report -- IMO immutable variables should be allowed to be treated as constants, since they in fact cannot be changed.

Currently the code below returns a warning Variable name must be in mixedCase when linted with the recommended ruleset.

contract Test {
  uint16 public immutable TEST_MODE;
  constructor(uint16 _testMode) { TEST_MODE = _testMode; }
}

quezak avatar Jul 31 '20 13:07 quezak

I think we need to rethink the whole approach to naming, since it's hard to make some calls. For example, the linked docs use mixedCase for immutable variables, but I agree that it makes sense to use SNAKE_CASE.

The quick and backward compatible fix here is to add an option to the var-name-mixedcase. Something like { ignoreImmutable: true }. The problem is, if you do that you would also need to add a mirror option to const-name-snakecase, something like { allowImmutable: true }. What do you think?

fvictorio avatar Aug 05 '20 14:08 fvictorio

It's hard to think of a good single setting here, since it really concerns two rules. The simplest way would be to have some "general config" option treat-immutable-vars-as-constants, but that's kinda bad design since it's not really a general option, just a two-rule option... Maybe it will be enough to add a treat-immutable-var-as-constant: true option to both these rules? You'd have to turn on both to have immutable variables linted in CAPS_SNAKE_CASE, and without them it would lint them in mixedCase.

quezak avatar Aug 05 '20 14:08 quezak

Yeah, I'd be fine with that. Especially because having such a long and ugly option would motivate me to totally redo the naming rules in the next major :smile:

fvictorio avatar Aug 05 '20 14:08 fvictorio

I don't know what is the state of this issue now but having support for this would be great 👍

benesjan avatar May 30 '22 11:05 benesjan

Plus one, would love to see this!

maxholloway avatar Aug 31 '22 18:08 maxholloway

+1 on this, would be great, Optimism prefers SCREAMING_SNAKE_CASE for immutables

smartcontracts avatar Nov 01 '22 23:11 smartcontracts

+1 here too guys

hktitof avatar Nov 05 '22 19:11 hktitof