Skip to content

Commit 5cb0ce4

Browse files
authored
refactor: use meta.defaultOptions in preserve-caught-error (#20080)
1 parent f9f7cb5 commit 5cb0ce4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/rules/preserve-caught-error.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ function findParentCatch(node) {
138138
module.exports = {
139139
meta: {
140140
type: "suggestion",
141+
142+
defaultOptions: [
143+
{
144+
requireCatchParameter: false,
145+
},
146+
],
147+
141148
docs: {
142149
description:
143150
"Disallow losing originally caught error when re-throwing custom errors",
@@ -158,7 +165,6 @@ module.exports = {
158165
properties: {
159166
requireCatchParameter: {
160167
type: "boolean",
161-
default: false,
162168
description:
163169
"Requires the catch blocks to always have the caught error parameter so it is not discarded.",
164170
},
@@ -185,7 +191,7 @@ module.exports = {
185191

186192
create(context) {
187193
const sourceCode = context.sourceCode;
188-
const options = context.options[0] || {};
194+
const [{ requireCatchParameter }] = context.options;
189195

190196
//----------------------------------------------------------------------
191197
// Helpers
@@ -273,7 +279,7 @@ module.exports = {
273279

274280
// Check if there are throw statements and caught error is being ignored
275281
if (!caughtError) {
276-
if (options.requireCatchParameter) {
282+
if (requireCatchParameter) {
277283
context.report({
278284
node: throwStatement,
279285
messageId: "missingCatchErrorParam",

lib/types/rules.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,6 +4812,9 @@ export interface ESLintRules extends Linter.RulesRecord {
48124812
"preserve-caught-error": Linter.RuleEntry<
48134813
[
48144814
Partial<{
4815+
/**
4816+
* @default false
4817+
*/
48154818
requireCatchParameter: boolean;
48164819
}>,
48174820
]

0 commit comments

Comments
 (0)