Home

Awesome

<p align="center"> <img width="300" src="https://github.com/Akronae/eslint-plugin-exception-handling/assets/17302866/43524856-1de6-4dac-982f-47323ea82ee4"> </p> <h1 align="center"> <sup>eslint-plugin-exception-handling</sup> <br> <h3 align="center"> <sup>💣 Lints unhandled functions that might throw errors & ensure best practices. For JavaScript/TypeScript eslint.</sup> </h3> <br/> <p align="center"> <a href="https://npm.im/eslint-plugin-exception-handling"><img src="https://badgen.net/npm/v/eslint-plugin-exception-handling"></a> <a href="https://npm.im/eslint-plugin-exception-handling"><img src="https://badgen.net/npm/dm/eslint-plugin-exception-handling"></a> </p> </h1>

image

no-unhandledmight-throwuse-error-cause
no-unhandledmight-throwcause

Installation

yarn add -D eslint-plugin-exception-handling
npm i -D eslint-plugin-exception-handling
pnpm add -D eslint-plugin-exception-handling

Usage

Sample eslint.config.js:

For TypeScript:

// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import { plugin as ex } from "eslint-plugin-exception-handling";

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommended,
  { plugins: { ex }, rules: { "ex/no-unhandled": "error" } }
);

For JavaScript:

import globals from "globals";
import pluginJs from "@eslint/js";
import { plugin as ex } from "eslint-plugin-exception-handling";

export default [
  { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
  { languageOptions: { globals: globals.browser } },
  pluginJs.configs.recommended,
  { plugins: { ex } },
  { rules: { "ex/no-unhandled": "error" } },
];

Limitations & Caveats

Rules

<!-- begin auto-generated rules list -->
Name           Description
might-throwWarns about function calls that might throw exceptions.
no-unhandledWarns about function calls that might throw exceptions and are not handled at all further up the stack.
use-error-causeOn Error re-thrown, forces the use of cause property in order to preserve stack traces. See: Error: cause
<!-- end auto-generated rules list -->