-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.cjs
More file actions
149 lines (134 loc) · 3.3 KB
/
eslint.config.cjs
File metadata and controls
149 lines (134 loc) · 3.3 KB
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 js = require('@eslint/js');
const typescript = require('@typescript-eslint/eslint-plugin');
const typescriptParser = require('@typescript-eslint/parser');
const react = require('eslint-plugin-react');
const reactHooks = require('eslint-plugin-react-hooks');
// Shared configuration objects
const commonGlobals = {
// Node.js globals
console: 'readonly',
process: 'readonly',
Buffer: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
module: 'readonly',
require: 'readonly',
global: 'readonly',
// Browser globals
window: 'readonly',
document: 'readonly',
navigator: 'readonly',
crypto: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
// Node.js types
NodeJS: 'readonly'
};
const jestGlobals = {
// Jest globals
describe: 'readonly',
it: 'readonly',
test: 'readonly',
expect: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
beforeAll: 'readonly',
afterAll: 'readonly',
jest: 'readonly'
};
const commonPlugins = {
'@typescript-eslint': typescript,
'react': react,
'react-hooks': reactHooks
};
const commonParserOptions = {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
};
const commonRules = {
// TypeScript rules
...typescript.configs.recommended.rules,
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
// React rules
...react.configs.recommended.rules,
'react/prop-types': 'off', // TypeScript handles this
'react/react-in-jsx-scope': 'off', // Not needed in React 17+
'react/no-unescaped-entities': 'warn',
'react/display-name': 'warn',
// React Hooks rules
...reactHooks.configs.recommended.rules,
'react-hooks/exhaustive-deps': 'warn',
// General ESLint rules
'no-useless-escape': 'warn',
'no-control-regex': 'warn'
};
const commonSettings = {
react: {
version: 'detect'
}
};
module.exports = [
// Base JavaScript configuration
js.configs.recommended,
// Configuration for production TypeScript and React files
{
files: ['src/**/*.{ts,tsx}'],
ignores: ['src/__tests__/**'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
...commonParserOptions,
project: './tsconfig.json'
},
globals: {
...commonGlobals
// Note: Jest globals intentionally excluded from production
}
},
plugins: commonPlugins,
rules: {
...commonRules,
'@typescript-eslint/no-require-imports': 'warn' // Stricter for production
},
settings: commonSettings
},
// Configuration for test files
{
files: ['src/__tests__/**/*.{ts,tsx}'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
...commonParserOptions,
project: './tsconfig.test.json'
},
globals: {
...commonGlobals,
...jestGlobals
}
},
plugins: commonPlugins,
rules: {
...commonRules,
'@typescript-eslint/no-require-imports': 'off' // Allow require() in tests
},
settings: commonSettings
},
// Ignore patterns
{
ignores: [
'dist/**',
'release/**',
'node_modules/**',
'*.config.js',
'*.config.ts',
'webpack.config.js',
'webpack.config.cjs'
]
}
];