|
1 | | -# eslint-plugin-handle-errors |
| 1 | +# ESLint Plugin Handle Errors |
2 | 2 |
|
3 | | -ESLint rules for handling errors |
| 3 | +[](https://www.npmjs.com/package/eslint-plugin-handle-errors) |
| 4 | + |
| 5 | +ESLint rules for handling errors. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +npm |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install -D eslint-plugin-handle-errors |
| 13 | +``` |
| 14 | + |
| 15 | +Yarn |
| 16 | + |
| 17 | +```bash |
| 18 | +yarn add -D eslint-plugin-handle-errors |
| 19 | +``` |
| 20 | + |
| 21 | +pnpm |
| 22 | + |
| 23 | +```bash |
| 24 | +pnpm add -D eslint-plugin-handle-errors |
| 25 | +``` |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +[Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new) |
| 30 | +(**eslint.config.js**) |
| 31 | + |
| 32 | +```javascript |
| 33 | +import handleErrors from 'eslint-plugin-handle-errors'; |
| 34 | + |
| 35 | +export default [ |
| 36 | + { |
| 37 | + ...handleErrors.configs['flat/recommended'], |
| 38 | + files: ['src/**'], |
| 39 | + }, |
| 40 | +]; |
| 41 | +``` |
| 42 | + |
| 43 | +[Legacy config](https://eslint.org/docs/latest/use/configure/configuration-files) |
| 44 | +(**.eslintrc**) |
| 45 | + |
| 46 | +```json |
| 47 | +{ |
| 48 | + "extends": ["plugin:handle-errors/recommended"], |
| 49 | + "plugins": ["handle-errors"] |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## Settings |
| 54 | + |
| 55 | +### Logger functions |
| 56 | + |
| 57 | +You can customize the logger functions that are used to log errors in your project. |
| 58 | + |
| 59 | +```json |
| 60 | +{ |
| 61 | + "settings": { |
| 62 | + "handle-errors": { |
| 63 | + "loggerFunctions": ["console.error", "console.warn", "Sentry.captureException", "logError"] |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +## Rules |
| 70 | + |
| 71 | +✅ Set in the `recommended` configuration\ |
| 72 | +🔧 Automatically fixable by the [`--fix`](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) |
| 73 | +CLI option\ |
| 74 | +💡 Manually fixable by |
| 75 | +[editor suggestions](https://eslint.org/docs/latest/developer-guide/working-with-rules#providing-suggestions) |
| 76 | + |
| 77 | +| Rule | Description | ✅ | 🔧 | 💡 | |
| 78 | +| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | :-: | :-: | :-: | |
| 79 | +| [log-error-in-trycatch](https://github.com/Nodge/eslint-plugin-handle-errors/blob/main/src/rules/log-error-in-trycatch.ts) | Enforce error logging in Try-Catch blocks | ✅ | | | |
| 80 | +| [log-error-in-promises](https://github.com/Nodge/eslint-plugin-handle-errors/blob/main/src/rules/log-error-in-promises.ts) | Enforces error logging in Promise.catch handlers | ✅ | | | |
0 commit comments