@jmlweb/eslint-config-react 2.0.3 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +194 -4
  3. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @jmlweb/eslint-config-react
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 4a9ece1: Update documentation to use pnpm commands instead of npm
8
+ - Updated dependencies [4a9ece1]
9
+ - @jmlweb/eslint-config-base@2.0.4
10
+
11
+ ## 2.0.4
12
+
13
+ ### Patch Changes
14
+
15
+ - 6b73301: Add changelog section with link to CHANGELOG.md in package READMEs
16
+ - Updated dependencies [6b73301]
17
+ - @jmlweb/eslint-config-base@2.0.3
18
+
3
19
  ## 2.0.3
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -23,9 +23,11 @@
23
23
  ## 📦 Installation
24
24
 
25
25
  ```bash
26
- npm install --save-dev @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
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
+ > 💡 **Upgrading from a previous version?** See the [Migration Guide](#-migration-guide) for breaking changes and upgrade instructions.
30
+
29
31
  ## 🚀 Quick Start
30
32
 
31
33
  Create an `eslint.config.js` file in your project root:
@@ -154,9 +156,47 @@ import { Component } from './component';
154
156
  Fix import order automatically:
155
157
 
156
158
  ```bash
157
- npx eslint --fix .
159
+ pnpm exec eslint --fix .
158
160
  ```
159
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
+
160
200
  ## 🎯 When to Use
161
201
 
162
202
  Use this configuration when you want:
@@ -211,8 +251,8 @@ Add linting scripts to your `package.json`:
211
251
  Then run:
212
252
 
213
253
  ```bash
214
- npm run lint # Lint all files
215
- npm run lint:fix # Fix auto-fixable issues
254
+ pnpm lint # Lint all files
255
+ pnpm lint:fix # Fix auto-fixable issues
216
256
  ```
217
257
 
218
258
  ## 📋 Requirements
@@ -244,10 +284,160 @@ See real-world usage examples:
244
284
 
245
285
  ## 🔗 Related Packages
246
286
 
287
+ ### Internal Packages
288
+
247
289
  - [`@jmlweb/eslint-config-base`](../eslint-config-base) - Base TypeScript ESLint config (extended by this package)
248
290
  - [`@jmlweb/tsconfig-react`](../tsconfig-react) - TypeScript configuration for React libraries
249
291
  - [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
250
292
 
293
+ ### External Tools
294
+
295
+ - [ESLint](https://eslint.org/) - Pluggable linting utility for JavaScript and TypeScript
296
+ - [TypeScript ESLint](https://typescript-eslint.io/) - TypeScript tooling for ESLint
297
+ - [React](https://react.dev/) - JavaScript library for building user interfaces
298
+ - [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) - React-specific linting rules
299
+ - [eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks) - Enforces Rules of Hooks
300
+ - [Prettier](https://prettier.io/) - Opinionated code formatter
301
+
302
+ ## ⚠️ Common Issues
303
+
304
+ > **Note:** This section documents known issues and their solutions. If you encounter a problem not listed here, please [open an issue](https://github.com/jmlweb/tooling/issues/new).
305
+
306
+ ### React Hooks Exhaustive Dependencies Warning
307
+
308
+ **Symptoms:**
309
+
310
+ - Warning: "React Hook useEffect has a missing dependency"
311
+ - ESLint suggests adding dependencies to the dependency array
312
+
313
+ **Cause:**
314
+
315
+ - `eslint-plugin-react-hooks` enforces the Rules of Hooks
316
+ - Missing dependencies can cause stale closures and bugs
317
+
318
+ **Solution:**
319
+
320
+ Add the missing dependencies:
321
+
322
+ ```typescript
323
+ // Before
324
+ useEffect(() => {
325
+ fetchData(userId);
326
+ }, []); // Missing dependency: userId
327
+
328
+ // After
329
+ useEffect(() => {
330
+ fetchData(userId);
331
+ }, [userId]); // Include all dependencies
332
+ ```
333
+
334
+ If you intentionally want to omit a dependency (use sparingly):
335
+
336
+ ```typescript
337
+ useEffect(() => {
338
+ fetchData(userId);
339
+ // eslint-disable-next-line react-hooks/exhaustive-deps
340
+ }, []); // Explicitly disable the rule with a comment
341
+ ```
342
+
343
+ ### React Version Not Detected
344
+
345
+ **Symptoms:**
346
+
347
+ - Warning: "Warning: React version not specified in eslint-plugin-react settings"
348
+ - Or incorrect React version being used
349
+
350
+ **Cause:**
351
+
352
+ - This config uses `detect` to auto-detect React version from package.json
353
+ - May fail if React is not installed or in an unexpected location
354
+
355
+ **Solution:**
356
+
357
+ Ensure React is installed:
358
+
359
+ ```bash
360
+ pnpm add react
361
+ ```
362
+
363
+ Or explicitly specify the React version:
364
+
365
+ ```javascript
366
+ // eslint.config.js
367
+ import reactConfig from '@jmlweb/eslint-config-react';
368
+
369
+ export default [
370
+ ...reactConfig,
371
+ {
372
+ settings: {
373
+ react: {
374
+ version: '18.2', // Specify your React version
375
+ },
376
+ },
377
+ },
378
+ ];
379
+ ```
380
+
381
+ ### JSX Not Recognized in .tsx Files
382
+
383
+ **Symptoms:**
384
+
385
+ - Parsing errors in `.tsx` files with JSX
386
+ - "Unexpected token <" errors
387
+
388
+ **Cause:**
389
+
390
+ - TypeScript parser not configured correctly
391
+ - File extension not recognized
392
+
393
+ **Solution:**
394
+
395
+ This config should handle `.tsx` files automatically. If you're having issues:
396
+
397
+ 1. Ensure your file has the `.tsx` extension (not `.ts`)
398
+ 2. Verify TypeScript is installed:
399
+
400
+ ```bash
401
+ pnpm add -D typescript
402
+ ```
403
+
404
+ 3. Check that your tsconfig.json is in the project root
405
+
406
+ ### Peer Dependency Warnings
407
+
408
+ **Symptoms:**
409
+
410
+ - npm warnings about unmet peer dependencies for `eslint-plugin-react` or `eslint-plugin-react-hooks`
411
+
412
+ **Cause:**
413
+
414
+ - These plugins may not have updated peer dependencies for ESLint 9.x yet
415
+
416
+ **Solution:**
417
+
418
+ ```bash
419
+ # pnpm automatically handles peer dependencies
420
+ pnpm install
421
+ ```
422
+
423
+ The warnings are usually safe to ignore if linting works correctly.
424
+
425
+ ## 🔄 Migration Guide
426
+
427
+ ### Upgrading to a New Version
428
+
429
+ > **Note:** If no breaking changes were introduced in a version, it's safe to upgrade without additional steps.
430
+
431
+ **No breaking changes have been introduced yet.** This package follows semantic versioning. When breaking changes are introduced, detailed migration instructions will be provided here.
432
+
433
+ For version history, see the [Changelog](./CHANGELOG.md).
434
+
435
+ **Need Help?** If you encounter issues during migration, please [open an issue](https://github.com/jmlweb/tooling/issues/new).
436
+
437
+ ## 📜 Changelog
438
+
439
+ See [CHANGELOG.md](./CHANGELOG.md) for version history and release notes.
440
+
251
441
  ## 📄 License
252
442
 
253
443
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jmlweb/eslint-config-react",
3
- "version": "2.0.3",
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.2"
57
+ "@jmlweb/eslint-config-base": "2.0.4"
58
58
  },
59
59
  "dependencies": {
60
- "@jmlweb/eslint-config-base": "2.0.2"
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.2",
73
+ "@jmlweb/eslint-config-base": "2.0.4",
74
74
  "@jmlweb/tsconfig-internal": "0.0.1"
75
75
  },
76
76
  "scripts": {