Skip to content

Commit

Permalink
Merge pull request #132 from solhint-community/casing-rule
Browse files Browse the repository at this point in the history
style-guide-casing rule
  • Loading branch information
juanpcapurro committed Jan 30, 2024
2 parents 8d72f6c + 83ffb24 commit 15e99eb
Show file tree
Hide file tree
Showing 26 changed files with 604 additions and 838 deletions.
7 changes: 1 addition & 6 deletions conf/rulesets/solhint-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ module.exports = Object.freeze({
'constructor-syntax': 'warn',
'comprehensive-interface': 'warn',
quotes: ['error', 'double'],
'const-name-snakecase': 'warn',
'definition-name-capwords': 'error',
'foundry-test-functions': ['warn', ['setUp']],
'func-name-mixedcase': 'warn',
'immutable-name-snakecase': ['warn'],
'modifier-name-mixedcase': 'warn',
'named-parameters-function': ['warn', 3],
'named-parameters-mapping': 'warn',
'named-return-values': ['warn', 1],
Expand All @@ -43,8 +38,8 @@ module.exports = Object.freeze({
strict: false,
},
],
'style-guide-casing': ['warn'],
'use-forbidden-name': 'warn',
'var-name-mixedcase': 'warn',
'imports-on-top': 'warn',
ordering: 'warn',
'visibility-modifier-order': 'warn',
Expand Down
6 changes: 1 addition & 5 deletions conf/rulesets/solhint-recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ module.exports = Object.freeze({
},
],
quotes: ['error', 'double'],
'const-name-snakecase': 'warn',
'definition-name-capwords': 'error',
'func-name-mixedcase': 'warn',
'modifier-name-mixedcase': 'warn',
'named-return-values': ['warn', 1],
'style-guide-casing': ['warn'],
'use-forbidden-name': 'warn',
'var-name-mixedcase': 'warn',
'imports-on-top': 'warn',
'visibility-modifier-order': 'warn',
'avoid-call-value': 'warn',
Expand Down
7 changes: 1 addition & 6 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,12 @@ title: "Rule Index of Solhint"
| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- | ----------- |
| [interface-starts-with-i](./rules/naming/interface-starts-with-i.md) | Interfaces name should start with `I` | ✔️ |
| [quotes](./rules/miscellaneous/quotes.md) | Use double quotes for string literals. Values must be 'single' or 'double'. | ✔️ |
| [const-name-snakecase](./rules/naming/const-name-snakecase.md) | Constant name must be in capitalized SNAKE_CASE. | ✔️ |
| [definition-name-capwords](./rules/naming/definition-name-capwords.md) | Contract, interface, library, struct, enum and event names must be in CapWords. | ✔️ |
| [foundry-test-functions](./rules/naming/foundry-test-functions.md) | Enforce naming convention on functions for Foundry test cases | |
| [func-name-mixedcase](./rules/naming/func-name-mixedcase.md) | Function name must be in mixedCase. | ✔️ |
| [immutable-name-snakecase](./rules/naming/immutable-name-snakecase.md) | Check Immutable variables are SNAKE_CASE. | |
| [modifier-name-mixedcase](./rules/naming/modifier-name-mixedcase.md) | Modifier name must be in mixedCase. | ✔️ |
| [named-parameters-mapping](./rules/naming/named-parameters-mapping.md) | Solidity v0.8.18 introduced named parameters on the mappings definition | |
| [named-return-values](./rules/naming/named-return-values.md) | Ensure function return parameters are named | ✔️ |
| [private-vars-leading-underscore](./rules/naming/private-vars-leading-underscore.md) | Private and internal names must start with a single underscore. | |
| [style-guide-casing](./rules/naming/style-guide-casing.md) | Check identifier and type name casing conforms to the style guide | ✔️ |
| [use-forbidden-name](./rules/naming/use-forbidden-name.md) | Avoid to use letters 'I', 'l', 'O' as identifiers. | ✔️ |
| [var-name-mixedcase](./rules/naming/var-name-mixedcase.md) | Identifier name must be in mixedCase. | ✔️ |
| [imports-on-top](./rules/order/imports-on-top.md) | Import statements must be on top. | ✔️ |
| [ordering](./rules/order/ordering.md) | Check order of elements in file and inside each contract, according to the style guide | |
| [visibility-modifier-order](./rules/order/visibility-modifier-order.md) | Visibility modifier must be first in list of modifiers. | ✔️ |
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/naming/definition-name-capwords.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct funStruct{}
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 4.0.0-rc01](https://github.com/solhint-community/solhint-community/tree/v4.0.0-rc01)

## Resources
- [Rule source](https://github.com/solhint-community/solhint-community/tree/master/lib/rules/naming/definition-name-capwords.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/naming/interface-starts-with-i.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface Foo { function foo () external; }
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 4.0.0-rc01](https://github.com/solhint-community/solhint-community/tree/v4.0.0-rc01)

## Resources
- [Rule source](https://github.com/solhint-community/solhint-community/tree/master/lib/rules/best-practises/interface-starts-with-i.js)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/naming/non-state-vars-leading-underscore.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ This rule accepts an array of options:
```

## Version
This rule is introduced in the latest version.
This rule was introduced in [Solhint 4.0.0-rc01](https://github.com/solhint-community/solhint-community/tree/v4.0.0-rc01)

## Resources
- [Rule source](https://github.com/solhint-community/solhint-community/tree/master/lib/rules/naming/non-state-vars-leading-underscore.js)
Expand Down
100 changes: 100 additions & 0 deletions docs/rules/naming/style-guide-casing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "style-guide-casing | Solhint"
---

# style-guide-casing
![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 identifier and type name casing conforms to the style guide

## Options
This rule accepts an array of options:

| Index | Description | Default Value |
| ----- | ----------------------------------------------------- | ------------- |
| 0 | Rule severity. Must be one of "error", "warn", "off". | warn |


### Example Config
```json
{
"rules": {
"style-guide-casing": ["warn"]
}
}
```


## Examples
### 👍 Examples of **correct** code for this rule

#### immutable/constant var name is capitalized snake case

```solidity
uint private immutable WAD_DECIMALS = 18
```

#### constant var name is capitalized snake case

```solidity
uint private constant WAD_DECIMALS = 18
```

#### function/modifier name in mixedCase

```solidity
function foo_bar() {}
```

#### contract/enum/struct name in CapWords

```solidity
contract Foo {}
```

### 👎 Examples of **incorrect** code for this rule

#### immutable/constant var name in lowercase snake_case

```solidity
uint private immutable wad_decimals = 18
```

#### function/modifier name in snake case

```solidity
function foo_bar() {}
```

#### function/modifier name in upper snake case

```solidity
modifier FOO_BAR() {}
```

#### mutable var name in upper snake case

```solidity
uint private FOO_BAR;
```

#### contract name not in CapWords

```solidity
contract foo {}
```

## Version
This rule is introduced in the latest version.

## Resources
- [Rule source](https://github.com/solhint-community/solhint-community/tree/master/lib/rules/naming/style-guide-casing.js)
- [Document source](https://github.com/solhint-community/solhint-community/tree/master/docs/rules/naming/style-guide-casing.md)
- [Test cases](https://github.com/solhint-community/solhint-community/tree/master/test/rules/naming/style-guide-casing.js)
4 changes: 2 additions & 2 deletions lib/common/identifier-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ function match(text, regex) {

module.exports = {
isMixedCase(text) {
return match(text, /[_]*[a-z$]+[a-zA-Z0-9$]*[_]?/)
return match(text, /[_]*[a-z$]+[a-zA-Z0-9$]*_?/)
},

isCapWords(text) {
return match(text, /[A-Z$]+[a-zA-Z0-9$]*/)
return match(text, /[A-Z$]+[a-zA-Z0-9$]*_?/)
},

isUpperSnakeCase(text) {
Expand Down
37 changes: 0 additions & 37 deletions lib/rules/naming/const-name-snakecase.js

This file was deleted.

105 changes: 0 additions & 105 deletions lib/rules/naming/definition-name-capwords.js

This file was deleted.

31 changes: 0 additions & 31 deletions lib/rules/naming/func-name-mixedcase.js

This file was deleted.

Loading

0 comments on commit 15e99eb

Please sign in to comment.