-
Notifications
You must be signed in to change notification settings - Fork 18
/
.eslintrc.naming-convention.js
136 lines (134 loc) · 4.15 KB
/
.eslintrc.naming-convention.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* This RegExp patter validates the allowed camelCase patterns that should be used for the object literal property names.
*/
const camelCaseRegExpInput = '([a-z]+([A-Z])?[a-z]*)([A-Z][a-z]+|A11y|URL){0,}([$])?';
/**
* TypeScript Eslint naming convention configuration generator.
* @param {jestConfigs: boolean} options configuration options
* @returns @typescript-eslint/naming-convention configuration
*/
const namingConventionConfig = (options = { jestConfigs: false, testSetup: false }) => ({
'@typescript-eslint/naming-convention': [
'error', // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
{
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'parameter',
format: ['camelCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'objectLiteralProperty',
/**
* By default only camelCase is allowed.
* Exceptions:
* > FORCE_COLOR - nodejs environment property
* > Authorization, Content-Type - client http headers
* > Cache-Control, Expires, Pragma - api http headers
* > graphql-ws, subscriptions-transport-ws - api graphql object properties
* > graphQLErrors - gql client library property
* Valid examples:
* > property
* > propertyName
* > longPropertyName
* > databaseURL
*/
format: null, // ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: options.testSetup ? 'allow' : 'forbid',
trailingUnderscore: 'forbid',
custom: {
regex:
options.jestConfigs || options.testSetup
? `^(${camelCaseRegExpInput}|ts-jest|[^0-9]+)$` // [^0-9]+ expression negates all numeric characters, allowing any other characters
: `^(${camelCaseRegExpInput}|FORCE_COLOR|Authorization|Content-Type|Cache-Control|Expires|Pragma|graphql-ws|subscriptions-transport-ws|graphQLErrors)$`,
match: true,
},
},
{
selector: 'property',
/**
* By default only camelCase is allowed.
* Exceptions:
* > Cypress - cypress e2e testing window property
* Valid examples:
* > property
* > propertyName
* > longPropertyName
* > databaseURL
* > observable$
* > observableProperty$
*/
format: null, // ['camelCase', 'PascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
custom: {
regex: options.jestConfigs ? `^(${camelCaseRegExpInput})$` : `^(${camelCaseRegExpInput}|Cypress)$`,
match: true,
},
},
{
selector: 'function',
format: ['camelCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'enum',
format: ['UPPER_CASE'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'enumMember',
format: ['UPPER_CASE'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'memberLike',
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'typeAlias',
prefix: ['T'],
format: ['StrictPascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'typeParameter',
format: ['StrictPascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'interface',
prefix: ['I'],
format: ['StrictPascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'class',
prefix: ['App'],
format: ['StrictPascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
],
});
exports.namingConventionConfig = namingConventionConfig;