@jmlweb/eslint-config-react 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +45 -10
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
## 📦 Installation
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
|
|
26
|
+
pnpm add -D @jmlweb/eslint-config-react eslint @eslint/js typescript-eslint eslint-config-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-simple-import-sort @jmlweb/eslint-config-base
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
> 💡 **Upgrading from a previous version?** See the [Migration Guide](#-migration-guide) for breaking changes and upgrade instructions.
|
|
@@ -156,9 +156,47 @@ import { Component } from './component';
|
|
|
156
156
|
Fix import order automatically:
|
|
157
157
|
|
|
158
158
|
```bash
|
|
159
|
-
|
|
159
|
+
pnpm exec eslint --fix .
|
|
160
160
|
```
|
|
161
161
|
|
|
162
|
+
## 🤔 Why Use This?
|
|
163
|
+
|
|
164
|
+
> **Philosophy**: React components should be predictable, composable, and easy to reason about. Strict linting catches bugs before they reach production.
|
|
165
|
+
|
|
166
|
+
This package extends the base TypeScript config with React-specific rules that enforce best practices, prevent common pitfalls, and ensure proper Hook usage. React's declarative nature requires different patterns than traditional imperative code.
|
|
167
|
+
|
|
168
|
+
### Design Decisions
|
|
169
|
+
|
|
170
|
+
**React Hooks Rules (`eslint-plugin-react-hooks`)**: Enforces Rules of Hooks and exhaustive dependencies
|
|
171
|
+
|
|
172
|
+
- **Why**: Hooks rely on call order and closure capture. Violating Hook rules causes subtle bugs that are hard to debug. Exhaustive dependencies prevent stale closures and missing reactive updates
|
|
173
|
+
- **Trade-off**: May require adding dependencies you think are unnecessary, but this prevents bugs from stale values
|
|
174
|
+
- **When to override**: Never for rules of hooks. For exhaustive deps, only when you understand the implications (use `eslint-disable-next-line` with a comment explaining why)
|
|
175
|
+
|
|
176
|
+
**JSX Accessibility (`eslint-plugin-jsx-a11y`)**: Enforces accessibility best practices (included via recommended)
|
|
177
|
+
|
|
178
|
+
- **Why**: Accessibility is not optional. Many common React patterns create inaccessible UIs by default. These rules catch issues early
|
|
179
|
+
- **Trade-off**: May require more verbose markup (explicit labels, ARIA attributes), but creates inclusive applications
|
|
180
|
+
- **When to override**: Rarely. If you must, document why the pattern is accessible despite the warning
|
|
181
|
+
|
|
182
|
+
**Modern JSX Transform**: Configured for React 17+ (no `React` import needed)
|
|
183
|
+
|
|
184
|
+
- **Why**: The new JSX transform is more efficient and doesn't require importing React in every file. It's the modern standard
|
|
185
|
+
- **Trade-off**: None - this is the recommended approach for React 17+
|
|
186
|
+
- **When to override**: If stuck on React 16 or earlier (but you should upgrade)
|
|
187
|
+
|
|
188
|
+
**Component Display Names**: Enforces display names for debugging
|
|
189
|
+
|
|
190
|
+
- **Why**: Display names improve debugging in React DevTools and error messages. Anonymous components are harder to track down
|
|
191
|
+
- **Trade-off**: Requires naming arrow function components or adding explicit displayName
|
|
192
|
+
- **When to override**: For simple, obvious components where the name is clear from context (rare)
|
|
193
|
+
|
|
194
|
+
**Extends Base TypeScript Config**: Inherits all strict type checking rules
|
|
195
|
+
|
|
196
|
+
- **Why**: React components benefit from strict typing. Props, state, and event handlers should all be explicitly typed
|
|
197
|
+
- **Trade-off**: More verbose component definitions, but prevents prop drilling bugs and refactoring issues
|
|
198
|
+
- **When to override**: Follow the same guidelines as the base TypeScript config
|
|
199
|
+
|
|
162
200
|
## 🎯 When to Use
|
|
163
201
|
|
|
164
202
|
Use this configuration when you want:
|
|
@@ -213,8 +251,8 @@ Add linting scripts to your `package.json`:
|
|
|
213
251
|
Then run:
|
|
214
252
|
|
|
215
253
|
```bash
|
|
216
|
-
|
|
217
|
-
|
|
254
|
+
pnpm lint # Lint all files
|
|
255
|
+
pnpm lint:fix # Fix auto-fixable issues
|
|
218
256
|
```
|
|
219
257
|
|
|
220
258
|
## 📋 Requirements
|
|
@@ -319,7 +357,7 @@ useEffect(() => {
|
|
|
319
357
|
Ensure React is installed:
|
|
320
358
|
|
|
321
359
|
```bash
|
|
322
|
-
|
|
360
|
+
pnpm add react
|
|
323
361
|
```
|
|
324
362
|
|
|
325
363
|
Or explicitly specify the React version:
|
|
@@ -360,7 +398,7 @@ This config should handle `.tsx` files automatically. If you're having issues:
|
|
|
360
398
|
2. Verify TypeScript is installed:
|
|
361
399
|
|
|
362
400
|
```bash
|
|
363
|
-
|
|
401
|
+
pnpm add -D typescript
|
|
364
402
|
```
|
|
365
403
|
|
|
366
404
|
3. Check that your tsconfig.json is in the project root
|
|
@@ -378,10 +416,7 @@ npm install --save-dev typescript
|
|
|
378
416
|
**Solution:**
|
|
379
417
|
|
|
380
418
|
```bash
|
|
381
|
-
#
|
|
382
|
-
npm install --legacy-peer-deps
|
|
383
|
-
|
|
384
|
-
# Or use pnpm which handles peer deps automatically
|
|
419
|
+
# pnpm automatically handles peer dependencies
|
|
385
420
|
pnpm install
|
|
386
421
|
```
|
|
387
422
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jmlweb/eslint-config-react",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "ESLint configuration for React libraries with TypeScript, extending base config with React-specific rules",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
55
55
|
"eslint-plugin-simple-import-sort": "^12.0.0",
|
|
56
56
|
"typescript-eslint": "^8.0.0",
|
|
57
|
-
"@jmlweb/eslint-config-base": "2.0.
|
|
57
|
+
"@jmlweb/eslint-config-base": "2.0.4"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@jmlweb/eslint-config-base": "2.0.
|
|
60
|
+
"@jmlweb/eslint-config-base": "2.0.4"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/js": "^9.39.2",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"tsup": "^8.5.1",
|
|
71
71
|
"typescript": "^5.9.3",
|
|
72
72
|
"typescript-eslint": "^8.34.1",
|
|
73
|
-
"@jmlweb/eslint-config-base": "2.0.
|
|
73
|
+
"@jmlweb/eslint-config-base": "2.0.4",
|
|
74
74
|
"@jmlweb/tsconfig-internal": "0.0.1"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|