Skip to content

Commit eeb1d39

Browse files
committed
Add readme
1 parent c0fee1f commit eeb1d39

File tree

4 files changed

+94
-11
lines changed

4 files changed

+94
-11
lines changed

README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,80 @@
1-
# eslint-plugin-handle-errors
1+
# ESLint Plugin Handle Errors
22

3-
ESLint rules for handling errors
3+
[![npm](https://img.shields.io/npm/v/eslint-plugin-handle-errors)](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 || | |

package-lock.json

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-handle-errors",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "ESLint rules for handling errors",
55
"keywords": [
66
"eslint",
@@ -46,8 +46,10 @@
4646
"test": "vitest",
4747
"typecheck": "tsc --noEmit"
4848
},
49+
"dependencies": {
50+
"@babel/types": "^7.24.0"
51+
},
4952
"devDependencies": {
50-
"@babel/types": "^7.24.0",
5153
"@eslint/js": "^9.0.0",
5254
"@types/eslint": "^8.56.9",
5355
"dedent": "^1.5.3",

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
import { recommededConfig } from './configs/recommended';
2+
import { logErrorInPromises } from './rules/log-error-in-promises';
23
import { logErrorInTrycatch } from './rules/log-error-in-trycatch';
34

45
const index = {
56
configs: {},
67
rules: {
78
'log-error-in-trycatch': logErrorInTrycatch,
9+
'log-error-in-promises': logErrorInPromises,
810
},
911
};
1012

1113
const legacyConfig = {
12-
...recommededConfig,
14+
rules: recommededConfig,
1315
plugins: ['handle-errors'],
1416
};
1517

1618
const flatConfig = {
17-
...recommededConfig,
19+
rules: recommededConfig,
1820
plugins: {
1921
'handle-errors': index,
2022
},
2123
};
2224

2325
export = {
26+
meta: {
27+
name: 'eslint-plugin-handle-errors',
28+
version: '0.1.1',
29+
},
2430
...index,
2531
configs: {
2632
'flat/recommended': flatConfig,

0 commit comments

Comments
 (0)