Skip to content

Commit 22df6fa

Browse files
authored
Add an exception to our `naming-convention` rule to support `rippled`'s silly usage of property name casing to indicate calculated vs real properties.
1 parent 699e5a0 commit 22df6fa

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
99

1010
## [Unreleased]
1111

12+
## 0.3.2 - May 27, 2020
13+
14+
- Add an exception to our `naming-convention` rule
15+
16+
`rippled` uses casing of object property names to indicate whether a property is calculated or "real". So, we need to allow `PascalCase` property names when we use `gRPC`. The way this is currently implemented is an override for all `*.ts` files that live in a `/XRP/` directory.
17+
1218
## 0.3.1 - May 26, 2020
1319

1420
- Change config for `@typescript-eslint/array-type`

loose.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ module.exports = {
2121
// TODO: Definitely remove this one
2222
'max-params': ['warn', { max: 4 }],
2323

24-
// Disallows assigning any to variables and properties
24+
// Disallows assigning `any` to variables and properties
2525
'@typescript-eslint/no-unsafe-assignment': 'off',
2626
// Disallows calling (function calls) on an `any` type value.
2727
'@typescript-eslint/no-unsafe-call': 'off',
2828
// Disallows member access on an `any` type value.
2929
'@typescript-eslint/no-unsafe-member-access': 'off',
3030
// Disallows returning an `any` type value from a function.
3131
'@typescript-eslint/no-unsafe-return': 'off',
32+
3233
// This rule aims to standardize the use of type assertion style across the codebase.
3334
'@typescript-eslint/consistent-type-assertions': [
3435
'error',

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@xpring-eng/eslint-config-base",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "Xpring's base TS ESLint config, following our styleguide",
55
"main": "index.js",
66
"scripts": {

rules/@typescript-eslint.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ module.exports = {
165165
selector: 'enumMember',
166166
format: ['PascalCase', 'UPPER_CASE'],
167167
},
168-
// Allow property names to be snake_case
169168
{
170169
selector: 'property',
171170
format: ['camelCase'],
@@ -744,5 +743,72 @@ module.exports = {
744743
],
745744
},
746745
},
746+
// Exceptions because of rippled's gRPC stuff.
747+
{
748+
files: ['**/XRP/**/*.ts'],
749+
rules: {
750+
// rippled uses casing to distinguish calculated vs real property names.
751+
// Thus, we need to allow PascalCase property names for some scenarios.
752+
'@typescript-eslint/naming-convention': [
753+
'warn',
754+
{
755+
selector: 'default',
756+
format: ['camelCase'],
757+
leadingUnderscore: 'allow',
758+
trailingUnderscore: 'allow',
759+
},
760+
761+
{
762+
selector: 'variable',
763+
format: ['camelCase', 'UPPER_CASE'],
764+
leadingUnderscore: 'allow',
765+
trailingUnderscore: 'allow',
766+
},
767+
768+
{
769+
selector: 'typeLike',
770+
format: ['PascalCase'],
771+
},
772+
// Enforce that boolean variables are prefixed with an allowed verb.
773+
{
774+
selector: 'variable',
775+
types: ['boolean'],
776+
// This isn't really PascalCase, because the prefix gets removed.
777+
// So something like "isValidPayID" would get the prefix stripped
778+
// and "ValidPayID" is in PascalCase.
779+
format: ['PascalCase'],
780+
prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
781+
},
782+
// Enforce that type parameters (generics) are prefixed with T
783+
{
784+
selector: 'typeParameter',
785+
format: ['PascalCase'],
786+
prefix: ['T'],
787+
},
788+
// Enforce that enums are singular, and do not end with 's' (for type theory reasons)
789+
{
790+
selector: 'enum',
791+
format: ['PascalCase'],
792+
filter: {
793+
regex: 'Status$',
794+
match: false,
795+
},
796+
custom: {
797+
regex: 's$',
798+
match: false,
799+
},
800+
},
801+
// Enforce that enumMembers are PascalCase
802+
{
803+
selector: 'enumMember',
804+
format: ['PascalCase', 'UPPER_CASE'],
805+
},
806+
{
807+
selector: 'property',
808+
format: ['camelCase', 'PascalCase'],
809+
},
810+
],
811+
},
812+
},
747813
],
748814
}

0 commit comments

Comments
 (0)