-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathxo.config.cjs
149 lines (148 loc) · 3.65 KB
/
xo.config.cjs
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
137
138
139
140
141
142
143
144
145
146
147
148
149
const getNamingConventionRule = ({isTsx}) => ({
'@typescript-eslint/naming-convention': [
'error',
{
/// selector: ['variableLike', 'memberLike', 'property', 'method'],
// Note: Leaving out `parameter` and `typeProperty` because of the mentioned known issues.
// Note: We are intentionally leaving out `enumMember` as it's usually pascal-case or upper-snake-case.
selector: [
'variable',
'function',
'classProperty',
'objectLiteralProperty',
'parameterProperty',
'classMethod',
'objectLiteralMethod',
'typeMethod',
'accessor',
],
format: ['strictCamelCase', isTsx && 'StrictPascalCase'].filter(Boolean),
// We allow double underscore because of GraphQL type names and some React names.
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allow',
// Ignore `{'Retry-After': retryAfter}` type properties.
// filter: {
// regex: '[- ]',
// match: false,
// },
},
{
selector: 'typeLike',
format: ['StrictPascalCase'],
},
{
selector: 'variable',
types: ['boolean'],
format: ['StrictPascalCase'],
prefix: ['is', 'has', 'can', 'should', 'will', 'did'],
},
// Allow UPPER_CASE in global constants.
{
selector: 'variable',
modifiers: ['const', 'global'],
format: [
'strictCamelCase',
isTsx && 'StrictPascalCase',
'UPPER_CASE',
].filter(Boolean),
},
{
selector: 'variable',
types: ['boolean'],
modifiers: ['const', 'global'],
format: ['UPPER_CASE'],
prefix: ['IS_', 'HAS_', 'CAN_', 'SHOULD_', 'WILL_', 'DID_'],
filter: '[A-Z]{2,}',
},
{
// Interface name should not be prefixed with `I`.
selector: 'interface',
filter: /^(?!I)[A-Z]/.source,
format: ['StrictPascalCase'],
},
{
// Type parameter name should either be `T` or a descriptive name.
selector: 'typeParameter',
filter: /^T$|^[A-Z][a-zA-Z]+$/.source,
format: ['StrictPascalCase'],
},
// Allow these in non-camel-case when quoted.
{
selector: ['classProperty', 'objectLiteralProperty'],
format: null,
modifiers: ['requiresQuotes'],
},
],
});
/** @type {import('xo').Options & {overrides?: Array<{files: string} & import('xo').Options>}} */
module.exports = {
prettier: true,
extends: [
'xo-react',
/** @see https://github.com/yannickcr/eslint-plugin-react#configuration */
'plugin:react/jsx-runtime',
'plugin:cypress/recommended',
'plugin:@next/next/core-web-vitals',
],
ignores: ['next-env.d.ts', 'yarn.lock'],
rules: {
'import/extensions': 'off',
'import/order': [
'warn',
{
'newlines-between': 'always',
'alphabetize': {
order: 'asc',
caseInsensitive: true,
},
},
],
'react/function-component-definition': [
2,
{
namedComponents: ['arrow-function'],
},
],
/** @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/781 */
'unicorn/no-array-callback-reference': 'off',
/** @see https://github.com/webpack/webpack/issues/13290 */
'unicorn/prefer-node-protocol': 'off',
},
overrides: [
{
files: '**/*.{ts,tsx}',
rules: {
...getNamingConventionRule({isTsx: false}),
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
},
],
},
},
{
files: '**/*.tsx',
rules: {
...getNamingConventionRule({isTsx: true}),
/** @see https://github.com/typescript-eslint/typescript-eslint/issues/1184 */
'@typescript-eslint/no-floating-promises': [
'error',
{
ignoreVoid: true,
},
],
'react/prop-types': 'off',
'unicorn/filename-case': [
'error',
{
cases: {
camelCase: true,
pascalCase: true,
},
},
],
},
},
],
};