forked from oasisprotocol/wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
180 lines (170 loc) · 7.11 KB
/
.eslintrc.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// @ts-check
// Find google translate issues: https://github.com/facebook/react/issues/11538#issuecomment-390386520
const noGoogleTranslateCrashingSyntax = [
// Ban `condition && text node`
{
selector:
'JSXElement > JSXExpressionContainer > LogicalExpression[operator="&&"]' +
'[right.type!="JSXElement"][right.type!="JSXFragment"]',
message:
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.',
},
// Ban `condition && <>text node</>`
{
selector:
'JSXElement > JSXExpressionContainer > LogicalExpression[operator="&&"]' +
' > JSXFragment > .children:not(JSXElement, JSXText[value=/^\\s+$/])',
message:
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.',
},
// Ban text nodes before or after a condition `text {condition && <span/>} text`
{
selector:
'JSXElement:has(JSXExpressionContainer.children > LogicalExpression[operator="&&"])' +
' > JSXText[value!=/^\\s+$/]',
message:
'Plain text nodes before or after a condition could break React if used with Google Translate. Wrap text into an element.',
},
// Ban variables before or after `{var} {condition && <span/>} {var}` (just in case they return a string)
{
selector:
'JSXElement:has(JSXExpressionContainer.children > LogicalExpression[operator="&&"])' +
' > JSXExpressionContainer:matches([expression.type="Identifier"], [expression.type="CallExpression"])',
message:
'Plain text nodes before or after a condition could break React if used with Google Translate. Identifier could possibly return a string, so wrap it into an element.',
},
// Ban `condition ? text node : <span/>`
{
selector:
'JSXElement > JSXExpressionContainer > ConditionalExpression' +
' > :matches(.consequent, .alternate):not(JSXElement, JSXFragment)',
message:
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.',
},
// Ban `condition ? <>text node</> : <span/>`
{
selector:
'JSXElement > JSXExpressionContainer > ConditionalExpression' +
' > JSXFragment > .children:not(JSXElement, JSXText[value=/^\\s+$/])',
message:
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.',
},
// Ban text nodes before or after a condition `text {condition ? <span/> : <span/>} text`
{
selector:
'JSXElement:has(JSXExpressionContainer.children > ConditionalExpression)' +
' > JSXText[value!=/^\\s+$/]',
message:
'Plain text nodes before or after a condition could break React if used with Google Translate. Wrap text into an element.',
},
// Ban variables before or after `{var} {condition ? <span/> : <span/>} {var}` (just in case they return a string)
{
selector:
'JSXElement:has(JSXExpressionContainer.children > ConditionalExpression)' +
' > JSXExpressionContainer:matches([expression.type="Identifier"], [expression.type="CallExpression"])',
message:
'Plain text nodes before or after a condition could break React if used with Google Translate. Identifier could possibly return a string, so wrap it into an element.',
},
// TODO: Nesting is not supported. Detect it as error for now
{
selector: 'JSXElement > JSXExpressionContainer > ConditionalExpression > ConditionalExpression',
message: 'noGoogleTranslateCrashingSyntax can not check nested conditions.',
},
{
selector: 'JSXElement > JSXExpressionContainer > ConditionalExpression > LogicalExpression',
message: 'noGoogleTranslateCrashingSyntax can not check nested conditions.',
},
]
/** @type { import('eslint').Linter.Config } */
const config = {
extends: [
'eslint:recommended', // https://eslint.org/docs/rules/
'plugin:react/recommended', // https://github.com/jsx-eslint/eslint-plugin-react#list-of-supported-rules
'plugin:@typescript-eslint/recommended', // https://typescript-eslint.io/rules/
'react-app', // https://github.com/facebook/create-react-app/blob/main/packages/eslint-config-react-app/index.js
'plugin:prettier/recommended', // See .prettierrc
],
plugins: ['react-refresh'],
parser: '@typescript-eslint/parser',
settings: {
// Warn about <a target="_blank" rel="noopener"> in components other than "a"
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md#custom-link-components
linkComponents: ['Button', 'MediaButton', 'SidebarButton', 'Anchor', 'Link', 'AnchorLink'],
},
reportUnusedDisableDirectives: true,
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'redux-saga/effects',
message: "Import 'typed-redux-saga' instead, and use matchers.select in tests.",
},
{
name: '@reduxjs/toolkit',
importNames: ['createSlice'],
message: "Import 'utils/@reduxjs/toolkit' instead.",
},
{
name: 'react-data-table-component',
importNames: ['default', 'DataTable', 'IDataTableColumn', 'IDataTableProps'],
message: "Import 'TypeSafeDataTable' instead.",
},
{
name: 'grommet',
message: "Import 'grommet/es6/*' instead.",
},
{
name: 'grommet/es6/components',
message: "Import 'grommet/es6/components/*' instead.",
},
{
name: 'grommet-icons',
message: "Import 'grommet-icons/es6/*' instead.",
},
{
name: 'grommet-icons/es6/icons',
message: "Import 'grommet-icons/es6/icons/*' instead.",
},
],
patterns: [
{
group: ['grommet/*', '!grommet/es6'],
message: "Import 'grommet/es6/*' instead.",
},
{
group: ['grommet-icons/*', '!grommet-icons/es6'],
message: "Import 'grommet-icons/es6/*' instead.",
},
],
},
],
'prefer-template': 'error',
'no-restricted-syntax': ['error', ...noGoogleTranslateCrashingSyntax],
'react/jsx-no-target-blank': ['error', { allowReferrer: true }],
'react/react-in-jsx-scope': 'off', // Not needed after React v17
'react/display-name': 'off', // TODO: Maybe enable
'react-refresh/only-export-components': 'error',
'@typescript-eslint/no-empty-function': 'off', // Allow empty reducers for saga
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/no-explicit-any': 'off', // TODO: Maybe enable
'@typescript-eslint/no-empty-interface': 'off', // TODO: Enable. Empty interfaces aren't safe (equivalent to "any")
},
overrides: [
{
files: ['**/*.ts?(x)'],
rules: { 'prettier/prettier': 'warn' },
},
{
files: ['internals/**'],
rules: { '@typescript-eslint/no-var-requires': 'off' },
},
{
files: ['**/*.js'],
rules: { '@typescript-eslint/no-var-requires': 'off' },
},
],
}
module.exports = config