Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename camel case rules to pascal case #614

Merged
merged 5 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conf/rulesets/solhint-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module.exports = Object.freeze({
'comprehensive-interface': 'warn',
quotes: ['error', 'double'],
'const-name-snakecase': 'warn',
'contract-name-camelcase': 'warn',
'event-name-camelcase': 'warn',
'contract-name-capwords': 'warn',
'event-name-capwords': 'warn',
'foundry-test-functions': ['warn', ['setUp']],
'func-name-mixedcase': 'warn',
'func-named-parameters': ['warn', 4],
Expand Down
4 changes: 2 additions & 2 deletions conf/rulesets/solhint-recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = Object.freeze({
'gas-custom-errors': 'warn',
quotes: ['error', 'double'],
'const-name-snakecase': 'warn',
'contract-name-camelcase': 'warn',
'event-name-camelcase': 'warn',
'contract-name-capwords': 'warn',
'event-name-capwords': 'warn',
'func-name-mixedcase': 'warn',
'immutable-vars-naming': [
'warn',
Expand Down
4 changes: 2 additions & 2 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ title: "Rule Index of Solhint"
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | ------------ | ----------- |
| [interface-starts-with-i](./rules/naming/interface-starts-with-i.md) | Solidity Interfaces names should start with an `I` | | |
| [const-name-snakecase](./rules/naming/const-name-snakecase.md) | Constant name must be in capitalized SNAKE_CASE. (Does not check IMMUTABLES, use immutable-vars-naming) | $~~~~~~~~$✔️ | |
| [contract-name-camelcase](./rules/naming/contract-name-camelcase.md) | Contract, Structs and Enums should be in CamelCase. | $~~~~~~~~$✔️ | |
| [event-name-camelcase](./rules/naming/event-name-camelcase.md) | Event name must be in CamelCase. | $~~~~~~~~$✔️ | |
| [contract-name-capwords](./rules/naming/contract-name-capwords.md) | Contract, Structs and Enums should be in CapWords. | $~~~~~~~~$✔️ | |
| [event-name-capwords](./rules/naming/event-name-capwords.md) | Event name 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. | $~~~~~~~~$✔️ | |
| [func-named-parameters](./rules/naming/func-named-parameters.md) | Enforce named parameters for function calls with 4 or more arguments. This rule may have some false positives | | |
Expand Down
42 changes: 42 additions & 0 deletions docs/rules/naming/contract-name-capwords.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "contract-name-capwords | Solhint"
---

# contract-name-capwords
![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
Contract, Structs and Enums should be in CapWords.

## Options
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Defaults to warn.

### Example Config
```json
{
"rules": {
"contract-name-capwords": "warn"
}
}
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` option
- The FIX will only change first letter and remove underscores

## Examples
This rule does not have examples.

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

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/naming/contract-name-capwords.js)
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/naming/contract-name-capwords.md)
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/naming/contract-name-capwords.js)
42 changes: 42 additions & 0 deletions docs/rules/naming/contract-name-pascalcase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "contract-name-pascalcase | Solhint"
---

# contract-name-pascalcase
![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
Contract, Structs and Enums should be in PascalCase.

## Options
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Defaults to warn.

### Example Config
```json
{
"rules": {
"contract-name-pascalcase": "warn"
}
}
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` option
- The FIX will only change first letter and remove underscores

## Examples
This rule does not have examples.

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

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/naming/contract-name-pascalcase.js)
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/naming/contract-name-pascalcase.md)
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/naming/contract-name-pascalcase.js)
42 changes: 42 additions & 0 deletions docs/rules/naming/event-name-capwords.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "event-name-capwords | Solhint"
---

# event-name-capwords
![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
Event name must be in CapWords.

## Options
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Defaults to warn.

### Example Config
```json
{
"rules": {
"event-name-capwords": "warn"
}
}
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` option
- The FIX will only change first letter and remove underscores

## Examples
This rule does not have examples.

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

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/naming/event-name-capwords.js)
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/naming/event-name-capwords.md)
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/naming/event-name-capwords.js)
42 changes: 42 additions & 0 deletions docs/rules/naming/event-name-pascalcase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
warning: "This is a dynamically generated file. Do not edit manually."
layout: "default"
title: "event-name-pascalcase | Solhint"
---

# event-name-pascalcase
![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
Event name must be in PascalCase.

## Options
This rule accepts a string option of rule severity. Must be one of "error", "warn", "off". Defaults to warn.

### Example Config
```json
{
"rules": {
"event-name-pascalcase": "warn"
}
}
```

### Notes
- Solhint allows this rule to automatically fix the code with `--fix` option
- The FIX will only change first letter and remove underscores

## Examples
This rule does not have examples.

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

## Resources
- [Rule source](https://github.com/protofire/solhint/blob/master/lib/rules/naming/event-name-pascalcase.js)
- [Document source](https://github.com/protofire/solhint/blob/master/docs/rules/naming/event-name-pascalcase.md)
- [Test cases](https://github.com/protofire/solhint/blob/master/test/rules/naming/event-name-pascalcase.js)
5 changes: 0 additions & 5 deletions e2e/08-autofix/contract-name-camelcase/.solhint.json

This file was deleted.

5 changes: 5 additions & 0 deletions e2e/08-autofix/contract-name-capwords/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"contract-name-capwords": "error"
}
}
5 changes: 0 additions & 5 deletions e2e/08-autofix/event-name-camelcase/.solhint.json

This file was deleted.

5 changes: 5 additions & 0 deletions e2e/08-autofix/event-name-capwords/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"event-name-capwords": "error"
}
}
8 changes: 4 additions & 4 deletions e2e/autofix-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ describe('e2e', function () {
})
})

describe('autofix rule: contract-name-camelcase', () => {
describe('autofix rule: contract-name-capwords', () => {
before(function () {
params = retrieveParams('contract-name-camelcase/')
params = retrieveParams('contract-name-capwords/')
currentConfig = `${params.path}${params.subpath}.solhint.json`
currentFile = `${params.path}${params.subpath}Foo1.sol`
beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol`
Expand Down Expand Up @@ -522,9 +522,9 @@ describe('e2e', function () {
})
})

describe('autofix rule: event-name-camelcase', () => {
describe('autofix rule: event-name-capwords', () => {
before(function () {
params = retrieveParams('event-name-camelcase/')
params = retrieveParams('event-name-capwords/')
currentConfig = `${params.path}${params.subpath}.solhint.json`
currentFile = `${params.path}${params.subpath}Foo1.sol`
beforeFixFile = `${params.path}${params.subpath}Foo1BeforeFix.sol`
Expand Down
6 changes: 3 additions & 3 deletions lib/common/identifier-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ module.exports = {
return !this.isMixedCase(text)
},

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

isNotCamelCase(text) {
return !this.isCamelCase(text)
isNotCapWords(text) {
return !this.isCapWords(text)
},

isUpperSnakeCase(text) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const BaseChecker = require('../base-checker')
const naming = require('../../common/identifier-naming')

const ruleId = 'contract-name-camelcase'
const ruleId = 'contract-name-capwords'
const meta = {
type: 'naming',

docs: {
description: 'Contract, Structs and Enums should be in CamelCase.',
description: 'Contract, Structs and Enums should be in CapWords.',
category: 'Style Guide Rules',
notes: [
{
Expand All @@ -25,7 +25,7 @@ const meta = {
schema: null,
}

class ContractNameCamelcaseChecker extends BaseChecker {
class ContractNameCapWordsChecker extends BaseChecker {
constructor(reporter) {
super(reporter, ruleId, meta)
}
Expand All @@ -43,7 +43,7 @@ class ContractNameCamelcaseChecker extends BaseChecker {
}

validateName(node, type) {
if (naming.isNotCamelCase(node.name)) {
if (naming.isNotCapWords(node.name)) {
this._error(node, type)
}
}
Expand Down Expand Up @@ -73,10 +73,10 @@ class ContractNameCamelcaseChecker extends BaseChecker {
_error(node, type) {
this.error(
node,
'Contract, Structs and Enums should be in CamelCase',
'Contract, Structs and Enums should be in CapWords',
this.fixStatement(node, type)
)
}
}

module.exports = ContractNameCamelcaseChecker
module.exports = ContractNameCapWordsChecker
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const BaseChecker = require('../base-checker')
const naming = require('../../common/identifier-naming')

const ruleId = 'event-name-camelcase'
const ruleId = 'event-name-capwords'
const meta = {
type: 'naming',

docs: {
description: 'Event name must be in CamelCase.',
description: 'Event name must be in CapWords.',
category: 'Style Guide Rules',
notes: [
{
Expand All @@ -25,7 +25,7 @@ const meta = {
schema: null,
}

class EventNameCamelcaseChecker extends BaseChecker {
class EventNameCapWordsChecker extends BaseChecker {
constructor(reporter) {
super(reporter, ruleId, meta)
}
Expand Down Expand Up @@ -53,10 +53,10 @@ class EventNameCamelcaseChecker extends BaseChecker {
}

EventDefinition(node) {
if (naming.isNotCamelCase(node.name)) {
this.error(node, 'Event name must be in CamelCase', this.fixStatement(node))
if (naming.isNotCapWords(node.name)) {
this.error(node, 'Event name must be in CapWords', this.fixStatement(node))
}
}
}

module.exports = EventNameCamelcaseChecker
module.exports = EventNameCapWordsChecker
8 changes: 4 additions & 4 deletions lib/rules/naming/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ConstNameSnakecaseChecker = require('./const-name-snakecase')
const ContractNameCamelcaseChecker = require('./contract-name-camelcase')
const EventNameCamelcaseChecker = require('./event-name-camelcase')
const ContractNameCapWordsChecker = require('./contract-name-capwords')
const EventNameCapWordsChecker = require('./event-name-capwords')
const FuncNameMixedcaseChecker = require('./func-name-mixedcase')
const FuncParamNameMixedcaseChecker = require('./func-param-name-mixedcase')
const ModifierNameMixedcaseChecker = require('./modifier-name-mixedcase')
Expand All @@ -16,8 +16,8 @@ const ImportsOrderChecker = require('./imports-order')
module.exports = function checkers(reporter, config) {
return [
new ConstNameSnakecaseChecker(reporter),
new ContractNameCamelcaseChecker(reporter),
new EventNameCamelcaseChecker(reporter),
new ContractNameCapWordsChecker(reporter),
new EventNameCapWordsChecker(reporter),
new FuncNameMixedcaseChecker(reporter),
new FuncParamNameMixedcaseChecker(reporter),
new ModifierNameMixedcaseChecker(reporter),
Expand Down
Loading
Loading