-
-
Notifications
You must be signed in to change notification settings - Fork 634
/
Copy patheslint.config.ts
181 lines (167 loc) · 4.76 KB
/
eslint.config.ts
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
181
import { globalIgnores } from 'eslint/config';
import prettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tsEslint from 'typescript-eslint';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
const config = tsEslint.config([
globalIgnores([
// compiled code
'node_package/lib/',
// used for tests only
'spec/react_on_rails/dummy-for-generators',
// temporary and generated files
'spec/dummy/.yalc',
'spec/dummy/public',
'spec/dummy/vendor',
'spec/dummy/tmp',
'spec/dummy/app/assets/config/manifest.js',
'spec/dummy/client/app/packs/server-bundle.js',
'**/*.res.js',
'**/coverage',
'**/assets/webpack/**/*',
'**/public/webpack/**/*',
'**/generated/**/*',
'**/app/assets/javascripts/application.js',
'**/cable.js',
'**/public/packs*/*',
'**/gen-examples/',
'**/bundle/',
// dependencies
'**/node_modules/**/*',
]),
{
files: ['**/*.[jt]s', '**/*.[jt]sx', '**/*.[cm][jt]s'],
},
js.configs.recommended,
compat.extends('eslint-config-shakacode'),
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.mocha,
...globals.jest,
__DEBUG_SERVER_ERRORS__: true,
__SERVER_ERRORS__: true,
},
parserOptions: {
requireConfigFile: false,
babelOptions: {
presets: ['@babel/preset-env', '@babel/preset-react'],
},
},
},
settings: {
'import/core-modules': ['react-redux'],
'import/resolver': {
alias: [['Assets', './spec/dummy/client/app/assets']],
node: {
extensions: ['.js', '.jsx', '.ts', '.d.ts'],
},
},
},
rules: {
'no-shadow': 'off',
'no-console': 'off',
'function-paren-newline': 'off',
'object-curly-newline': 'off',
'no-restricted-syntax': ['error', 'SequenceExpression'],
'no-void': [
'error',
{
allowAsStatement: true,
},
],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
},
],
'import/first': 'off',
'import/no-extraneous-dependencies': 'off',
// The rule seems broken: it's reporting errors on imports in files using `export` too,
// not just `module.exports`.
'import/no-import-module-exports': 'off',
'import/no-unresolved': [
'error',
{
ignore: ['\\.res\\.js$'],
},
],
'react/destructuring-assignment': [
'error',
'always',
{
ignoreClassFields: true,
},
],
'react/forbid-prop-types': 'off',
'react/function-component-definition': [
'error',
{
namedComponents: ['arrow-function', 'function-declaration'],
unnamedComponents: 'arrow-function',
},
],
'react/jsx-props-no-spreading': 'off',
'react/static-property-placement': 'off',
'jsx-a11y/anchor-is-valid': 'off',
},
},
{
files: ['lib/generators/react_on_rails/templates/**/*'],
rules: {
// It doesn't use package.json from the template
'import/no-unresolved': 'off',
// We have `const [name, setName] = useState(props.name)` so can't just destructure props
'react/destructuring-assignment': 'off',
},
},
{
files: ['**/*.ts', '**/*.tsx'],
extends: tsEslint.configs.strictTypeChecked,
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['eslint.config.ts', 'knip.ts', 'node_package/tests/*.test.ts'],
// Needed because `import * as ... from` instead of `import ... from` doesn't work in this file
// for some imports.
defaultProject: 'tsconfig.eslint.json',
},
},
},
rules: {
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-confusing-void-expression': [
'error',
{
ignoreArrowShorthand: true,
},
],
// Too many false positives
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
// must be the last config in the array
// https://github.com/prettier/eslint-plugin-prettier?tab=readme-ov-file#configuration-new-eslintconfigjs
prettierRecommended,
]);
export default config;