-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy patheslint.config.js
More file actions
183 lines (168 loc) · 5.12 KB
/
Copy patheslint.config.js
File metadata and controls
183 lines (168 loc) · 5.12 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
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
182
183
// eslint.config.js
import globals from 'globals'
import pluginJs from '@eslint/js'
import pluginReact from 'eslint-plugin-react'
import pluginReactHooks from 'eslint-plugin-react-hooks'
import pluginJsdoc from 'eslint-plugin-jsdoc'
import pluginTypeScript from '@typescript-eslint/eslint-plugin'
import parserTypeScript from '@typescript-eslint/parser'
// Testing Plugins
import pluginJest from 'eslint-plugin-jest'
import pluginPlaywright from 'eslint-plugin-playwright' // Used for Jest-Playwright E2E tests
// Formatting/Parser Plugins
import babelParser from '@babel/eslint-parser'
import configPrettier from 'eslint-config-prettier'
import pluginPrettier from 'eslint-plugin-prettier'
export default [
// --- CORE CONFIGURATION (APPLIES TO ALL JS/JSX) ---
// 1. Basic JavaScript Configuration & Parser Setup (using Babel)
{
...pluginJs.configs.recommended,
files: ['**/*.js', '**/*.jsx'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
// Use Babel as the custom parser
parser: babelParser,
parserOptions: {
requireConfigFile: false,
babelOptions: {
presets: ['@babel/preset-react', '@babel/preset-env'],
},
jsx: true,
},
globals: {
...globals.browser, // Standard React (browser) globals
...globals.node, // Standard Node.js globals (backend/config files)
},
},
rules: {
'no-console': 'warn',
'prefer-const': 'error',
},
},
// 2. TypeScript Configuration.
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
parser: parserTypeScript,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.browser,
...globals.node,
},
},
plugins: {
'@typescript-eslint': pluginTypeScript,
},
rules: {
...pluginTypeScript.configs.recommended.rules,
'no-console': 'warn',
'no-unused-vars': 'off',
'prefer-const': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-explicit-any': 'off', // Allow 'any' type (can be relaxed later if needed)
},
},
// 3. React and React Hooks Configuration (for all JSX files)
{
files: ['**/*.jsx', '**/*.js', '**/*.tsx', '**/*.ts'],
plugins: {
react: pluginReact,
'react-hooks': pluginReactHooks,
},
settings: {
react: { version: 'detect' },
},
rules: {
// Recommended React rules
...pluginReact.configs.recommended.rules,
// Recommended React Hooks rules
...pluginReactHooks.configs.recommended.rules,
'react/display-name': 'off',
// React 17+ Obsolete Rules
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'warn',
},
},
// 4. JSDoc Configuration
{
files: ['**/*.js', '**/*.jsx'],
plugins: {
jsdoc: pluginJsdoc,
},
rules: {
...pluginJsdoc.configs['recommended-typescript-flavor'].rules,
'jsdoc/require-description': 'warn',
},
},
// --- TESTING CONFIGURATIONS (APPLIES ONLY TO TEST FILES) ---
// 5. Jest (Unit/Integration Tests) Configuration
{
// Apply this to files matching Jest naming convention
files: ['test/**/*.js', 'test/**/*.ts', '**/*.test.js', '**/*.spec.js', '**/*.test.ts', '**/*.spec.ts'],
plugins: {
jest: pluginJest,
},
languageOptions: {
// Add Jest environment globals (describe, test, expect, etc.)
globals: {
...globals.jest,
},
},
rules: {
// Recommended Jest rules (e.g., no-focused-tests)
...pluginJest.configs.recommended.rules,
'jest/prefer-to-be': 'warn', // Example Jest rule
'jest/no-focused-tests': 'error',
'jest/no-export': 'off',
},
},
// 6. Jest-Playwright (E2E Tests) Configuration
{
// Apply this to files matching Playwright test naming convention (often different than Jest unit tests)
files: ['test/e2e/**/*.js', 'test/e2e/**/*.jsx', 'test/e2e/**/*.ts', 'test/e2e/**/*.tsx'],
plugins: {
playwright: pluginPlaywright,
},
rules: {
// Use the recommended Playwright rules
...pluginPlaywright.configs['playwright-test'].rules,
// Playwright-specific rules (e.g., forcing async/await usage on Playwright methods)
// 'playwright/prefer-web-first-assertions': 'error',
// 'playwright/await-expect': 'error',
},
},
// --- FINAL FORMATTING & IGNORE ---
// 7. Prettier Integration (Must be the LAST configuration)
{
files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'],
plugins: {
prettier: pluginPrettier,
},
// Extends the config that turns off formatting rules
...configPrettier,
rules: {
// Runs Prettier and flags any formatting conflict as an ESLint error
'prettier/prettier': 'error',
},
},
// 8. Ignore Configuration
{
ignores: [
'node_modules/',
'dist/',
'build/',
'.cache/',
'coverage/', // Ignore test coverage directories
'webapp/components/Map/L.KML.js',
],
},
]