Skip to content

Commit

Permalink
Add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodge committed Apr 15, 2024
1 parent c0fee1f commit eeb1d39
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 11 deletions.
81 changes: 79 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
# eslint-plugin-handle-errors
# ESLint Plugin Handle Errors

ESLint rules for handling errors
[![npm](https://img.shields.io/npm/v/eslint-plugin-handle-errors)](https://www.npmjs.com/package/eslint-plugin-handle-errors)

ESLint rules for handling errors.

## Installation

npm

```bash
npm install -D eslint-plugin-handle-errors
```

Yarn

```bash
yarn add -D eslint-plugin-handle-errors
```

pnpm

```bash
pnpm add -D eslint-plugin-handle-errors
```

## Usage

[Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new)
(**eslint.config.js**)

```javascript
import handleErrors from 'eslint-plugin-handle-errors';

export default [
{
...handleErrors.configs['flat/recommended'],
files: ['src/**'],
},
];
```

[Legacy config](https://eslint.org/docs/latest/use/configure/configuration-files)
(**.eslintrc**)

```json
{
"extends": ["plugin:handle-errors/recommended"],
"plugins": ["handle-errors"]
}
```

## Settings

### Logger functions

You can customize the logger functions that are used to log errors in your project.

```json
{
"settings": {
"handle-errors": {
"loggerFunctions": ["console.error", "console.warn", "Sentry.captureException", "logError"]
}
}
}
```

## Rules

✅ Set in the `recommended` configuration\
🔧 Automatically fixable by the [`--fix`](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
CLI option\
💡 Manually fixable by
[editor suggestions](https://eslint.org/docs/latest/developer-guide/working-with-rules#providing-suggestions)

| Rule | Description || 🔧 | 💡 |
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | :-: | :-: | :-: |
| [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 || | |
| [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 || | |
8 changes: 3 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-handle-errors",
"version": "0.1.0",
"version": "0.1.1",
"description": "ESLint rules for handling errors",
"keywords": [
"eslint",
Expand Down Expand Up @@ -46,8 +46,10 @@
"test": "vitest",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@babel/types": "^7.24.0"
},
"devDependencies": {
"@babel/types": "^7.24.0",
"@eslint/js": "^9.0.0",
"@types/eslint": "^8.56.9",
"dedent": "^1.5.3",
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { recommededConfig } from './configs/recommended';
import { logErrorInPromises } from './rules/log-error-in-promises';
import { logErrorInTrycatch } from './rules/log-error-in-trycatch';

const index = {
configs: {},
rules: {
'log-error-in-trycatch': logErrorInTrycatch,
'log-error-in-promises': logErrorInPromises,
},
};

const legacyConfig = {
...recommededConfig,
rules: recommededConfig,
plugins: ['handle-errors'],
};

const flatConfig = {
...recommededConfig,
rules: recommededConfig,
plugins: {
'handle-errors': index,
},
};

export = {
meta: {
name: 'eslint-plugin-handle-errors',
version: '0.1.1',
},
...index,
configs: {
'flat/recommended': flatConfig,
Expand Down

0 comments on commit eeb1d39

Please sign in to comment.