-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bb8a28
commit acf4cea
Showing
25 changed files
with
329 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ convertLib.sol | |
antlr4.jar | ||
/docs/.sass-cache/ | ||
_temp/ | ||
.solhint.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
warning: "This is a dynamically generated file. Do not edit manually." | ||
layout: "default" | ||
title: "immutable-vars-naming | Solhint" | ||
--- | ||
|
||
# immutable-vars-naming | ||
![Recommended Badge](https://img.shields.io/badge/-Recommended-brightgreen) | ||
![Category Badge](https://img.shields.io/badge/-Style%20Guide%20Rules-informational) | ||
![Default Severity Badge warn](https://img.shields.io/badge/Default%20Severity-warn-yellow) | ||
> The {"extends": "solhint:recommended"} property in a configuration file enables this rule. | ||
|
||
## Description | ||
Check Immutable variables. Capitalized SNAKE_CASE or mixedCase depending on configuration. | ||
|
||
## 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 "immutablesAsConstants" as boolean specifying if immutable variables should be treated as constants | {"immutablesAsConstants":true} | | ||
|
||
|
||
### Example Config | ||
```json | ||
{ | ||
"rules": { | ||
"immutable-vars-naming": ["warn",{"immutablesAsConstants":true}] | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Examples | ||
This rule does not have examples. | ||
|
||
## Version | ||
This rule is introduced in the latest version. | ||
|
||
## Resources | ||
- [Rule source](https://github.com/protofire/solhint/tree/master/lib/rules/naming/immutable-vars-naming.js) | ||
- [Document source](https://github.com/protofire/solhint/tree/master/docs/rules/naming/immutable-vars-naming.md) | ||
- [Test cases](https://github.com/protofire/solhint/tree/master/test/rules/naming/immutable-vars-naming.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const BaseChecker = require('../base-checker') | ||
const naming = require('../../common/identifier-naming') | ||
const { severityDescription } = require('../../doc/utils') | ||
|
||
const DEFAULT_INMUTABLE_AS_CONSTANTS = true | ||
const DEFAULT_SEVERITY = 'warn' | ||
const DEFAULT_OPTION = { immutablesAsConstants: DEFAULT_INMUTABLE_AS_CONSTANTS } | ||
|
||
const ruleId = 'immutable-vars-naming' | ||
const meta = { | ||
type: 'naming', | ||
|
||
docs: { | ||
description: | ||
'Check Immutable variables. Capitalized SNAKE_CASE or mixedCase depending on configuration.', | ||
category: 'Style Guide Rules', | ||
options: [ | ||
{ | ||
description: severityDescription, | ||
default: DEFAULT_SEVERITY, | ||
}, | ||
{ | ||
description: | ||
'A JSON object with a single property "immutablesAsConstants" as boolean specifying if immutable variables should be treated as constants', | ||
default: JSON.stringify(DEFAULT_OPTION), | ||
}, | ||
], | ||
}, | ||
|
||
isDefault: false, | ||
recommended: true, | ||
defaultSetup: [DEFAULT_SEVERITY, DEFAULT_OPTION], | ||
|
||
schema: { | ||
type: 'object', | ||
properties: { | ||
immutablesAsConstants: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
class ImmutableVarsNamingChecker extends BaseChecker { | ||
constructor(reporter, config) { | ||
super(reporter, ruleId, meta) | ||
|
||
this.treatImmutablesAsConstants = | ||
config && | ||
config.getObjectPropertyBoolean( | ||
ruleId, | ||
'immutablesAsConstants', | ||
DEFAULT_INMUTABLE_AS_CONSTANTS | ||
) | ||
} | ||
|
||
VariableDeclaration(node) { | ||
if (node.isImmutable) { | ||
if (this.treatImmutablesAsConstants) { | ||
this.validateImmutableAsConstantName(node) | ||
} else { | ||
this.validateImmutableAsRegularVariables(node) | ||
} | ||
} | ||
} | ||
|
||
validateImmutableAsConstantName(node) { | ||
if (naming.isNotUpperSnakeCase(node.name)) { | ||
this.error(node, 'Immutable variables name are set to be in capitalized SNAKE_CASE') | ||
} | ||
} | ||
|
||
validateImmutableAsRegularVariables(node) { | ||
if (naming.isNotMixedCase(node.name)) { | ||
this.error(node, 'Immutable variables names are set to be in mixedCase') | ||
} | ||
} | ||
} | ||
|
||
module.exports = ImmutableVarsNamingChecker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.