diff --git a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs index b7562dcfa6ec9..8f30da167992a 100644 --- a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs +++ b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs @@ -1,3 +1,4 @@ +use cow_utils::CowUtils; use lazy_regex::Regex; use oxc_ast::{ AstKind, @@ -149,7 +150,26 @@ impl Rule for CatchErrorName { impl CatchErrorName { fn is_name_allowed(&self, name: &str) -> bool { - self.name == name || self.ignore.iter().any(|s| s.is_match(name)) + // Allow exact match + if self.name == name { + return true; + } + + // strip all trailing underscores from the name. + let stripped_name = name.trim_end_matches('_').cow_to_lowercase(); + + if self.name == stripped_name.as_ref() { + return true; + } + + // Allow a qualified name, e.g. if we allow "error", + // should also allow "diagnostic_error" or "diagnosticError". + if stripped_name.ends_with(self.name.as_str().cow_to_lowercase().as_ref()) { + return true; + } + + // Check configured ignore patterns, do not use stripped name + self.ignore.iter().any(|s| s.is_match(name)) } fn check_function_arguments(&self, arg: &Argument, ctx: &LintContext) { @@ -215,81 +235,339 @@ fn test() { use crate::tester::Tester; let pass = vec![ - ("try { } catch (error) { }", None), - ("try { } catch (err) { }", Some(serde_json::json!([{"name": "err"}]))), - ("obj.catch(error => { })", None), - ("obj.then(undefined, error => { })", None), - ("obj.then(result => { }, error => { })", None), - ("obj.catch(() => { })", None), - ("obj.catch(err => { })", Some(serde_json::json!([{"name": "err"}]))), - ("obj.then(undefined, err => { })", Some(serde_json::json!([{"name": "err"}]))), - ("obj.catch(function (error) { })", None), - ("obj.then(undefined, function (error) { })", None), - ("obj.catch(function onReject(error) { })", None), - ("obj.then(undefined, function onReject(error) { })", None), - ("obj.then(function onFulfilled(result) { }, function onReject(error) { })", None), - ("obj.catch(function () { })", None), - ("obj.catch(function (err) { })", Some(serde_json::json!([{"name": "err"}]))), - ("obj.then(undefined, function (err) { })", Some(serde_json::json!([{"name": "err"}]))), + ("try {} catch (err) {}", Some(serde_json::json!([{"name": "err"}]))), + ( + "try { + } catch (outerError) { + try { + } catch (innerError) {} + }", + None, + ), + ( + "const handleError = error => { + try { + doSomething(); + } catch (error_) { + console.log(error_); + } + }", + None, + ), + ( + "const handleError = err => { + try { + doSomething(); + } catch (err_) { + console.log(err_); + } + }", + Some(serde_json::json!([{"name": "err"}])), + ), + ( + "const handleError = error => { + const error_ = new Error('๐Ÿฆ„'); + try { + doSomething(); + } catch (error__) { + console.log(error__); + } + }", + None, + ), + ("obj.catch(error => {})", None), + ("obj.catch?.(error => {})", None), + ("obj.then(undefined, error => {})", None), + ("obj.then(result => {}, error => {})", None), + ("obj.then?.(undefined, error => {})", None), + ("obj.then?.(result => {}, error => {})", None), + ( + "const handleError = error => { + obj.catch(error_ => { }); + }", + None, + ), + ( + "const handleError = error => { + obj.then(undefined, error_ => { }); + }", + None, + ), + ( + "const handleError = err => { + obj.catch(err_ => { }); + }", + Some(serde_json::json!([{"name": "err"}])), + ), + ( + "const handleError = err => { + obj.then(undefined, err_ => { }); + }", + Some(serde_json::json!([{"name": "err"}])), + ), + ( + "const handleError = error => { + const error_ = new Error('foo bar'); + obj.catch(error__ => { }); + }", + None, + ), + ( + "const handleError = error => { + const error_ = new Error('foo bar'); + obj.then(undefined, error__ => { }); + }", + None, + ), + ( + "const handleError = error => { + const error_ = new Error('foo bar'); + const error__ = new Error('foo bar'); + const error___ = new Error('foo bar'); + const error____ = new Error('foo bar'); + const error_____ = new Error('foo bar'); + const error______ = new Error('foo bar'); + const error_______ = new Error('foo bar'); + const error________ = new Error('foo bar'); + const error_________ = new Error('foo bar'); + obj.catch(error__________ => { }); + }", + None, + ), + ("obj.catch(() => {})", None), + ("obj.catch(err => {})", Some(serde_json::json!([{"name": "err"}]))), + ("obj.then(undefined, err => {})", Some(serde_json::json!([{"name": "err"}]))), + ( + "obj.catch( + outerError => { + return obj2.catch(innerError => {}) + } + )", + None, + ), + ("obj.catch(function (error) {})", None), + ("obj.then(undefined, function (error) {})", None), + ("obj.catch(function onReject(error) {})", None), + ("obj.then(undefined, function onReject(error) {})", None), + ("obj.then(function onFulfilled(result) {}, function onReject(error) {})", None), + ("obj.catch(function () {})", None), + ("obj.catch(function (err) {})", Some(serde_json::json!([{"name": "err"}]))), + ("obj.then(undefined, function (err) {})", Some(serde_json::json!([{"name": "err"}]))), + ( + "obj.catch(function (outerError) { + return obj2.catch(function (innerError) { + }) + })", + None, + ), + ( + "obj.then(undefined, function (outerError) { + return obj2.then(undefined, function (innerError) { + }) + })", + None, + ), + ( + "obj.then(undefined, function (outerError) { + return obj2.catch(function (innerError) { + }) + })", + None, + ), + ( + "obj.catch(function (outerError) { + return obj2.then(undefined, function (innerError) { + }) + })", + None, + ), ("obj.catch()", None), - ("foo(function (error) { })", None), - ("foo().then(function (error) { })", None), - ("foo().catch(function (error) { })", None), - ("try { } catch ({message}) { }", None), - ("obj.catch(function ({message}) { })", None), - ("obj.catch(({message}) => { })", None), - ("obj.then(undefined, ({message}) => { })", None), - ("obj.catch(error => { }, anotherArgument)", None), - ("obj.then(undefined, error => { }, anotherArgument)", None), - ("obj.catch(_ => { })", None), - ("obj.catch((_) => { })", None), + ("foo(function (error) {})", None), + ("foo().then(function (error) {})", None), + ("foo().catch(function (error) {})", None), + ( + "try { + throw new Error('message'); + } catch { + console.log('failed'); + }", + None, + ), + ("try {} catch ({message}) {}", None), + ("obj.catch(function ({message}) {})", None), + ("obj.catch(({message}) => {})", None), + ("obj.then(undefined, ({message}) => {})", None), + ("obj.catch(error => {}, anotherArgument)", None), + ("obj.then(undefined, error => {}, anotherArgument)", None), + ("obj.catch(_ => {})", None), + ("obj.catch((_) => {})", None), ("obj.catch((_) => { console.log(foo); })", None), - ("try { } catch (_) { }", None), - ("try { } catch (_) { console.log(foo); }", None), + ("try {} catch (_) {}", None), + ("try {} catch (_) { console.log(foo); }", None), + ( + "try { + } catch (_) { + try { + } catch (_) {} + }", + None, + ), ( " - try { - } catch (_) { - console.log(_); - } - ", - Some(serde_json::json!([{"ignore": ["_"]}])), + try { + } catch (_) { + console.log(_); + } + ", + Some(serde_json::json!([ { "ignore": ["^_$"] } ])), + ), + ("try {} catch (error) {}", None), + ("try {} catch (error__) {}", None), + ("try {} catch (descriptiveError) {}", None), + ("try {} catch (descriptive_error) {}", None), + ("try {} catch (descriptiveError__) {}", None), + ("try {} catch (descriptive_error__) {}", None), + ("try {} catch (skipThisNameCheck) {}", Some(serde_json::json!([{"ignore": ["^skip"]}]))), + // This one needs to be modified from the upstream because there's no way to pass a regex with a flag (e.g. case insensitive flag). + ( + "try {} catch (skipThisNameCheck) {} + try {} catch (ignoreThisNameCheck) {} + try {} catch (pleaseIgnoreThisNameCheck) {}", + Some(serde_json::json!([{"ignore": ["^skip", "ignore", "Ignore"]}])), + ), + ( + "try {} catch (error1) {} + try {} catch (error1__) {} + try {} catch (error2) {}", + Some(serde_json::json!([{"ignore": ["error\\d*"]}])), ), - ("try { } catch (error) { }", None), - ("promise.catch(unicorn => { })", Some(serde_json::json!([{"ignore": ["unicorn"]}]))), - // https://github.com/oxc-project/oxc/issues/12430 + ("promise.catch(unicorn => {})", Some(serde_json::json!([{"ignore": ["unicorn"]}]))), + // https://github.com/oxc-project/oxc/issues/12430 ( "try { - // some codes -} catch (error: unknown) { - try { - // some codes - } catch (error2: unknown) { - // some codes - } -}", + // some codes + } catch (error: unknown) { + try { + // some codes + } catch (error2: unknown) { + // some codes + } + }", Some(serde_json::json!([{"ignore": [ "^error\\d*$"]}])), ), ("try { } catch (exception) { }", Some(serde_json::json!([{"name": "exception"}]))), ]; let fail = vec![ - ("try { } catch (descriptiveError) { }", Some(serde_json::json!([{"name": "exception"}]))), - ("try { } catch (e) { }", Some(serde_json::json!([{"name": "has_space_after "}]))), - ("try { } catch (e) { }", Some(serde_json::json!([{"name": "1_start_with_a_number"}]))), - ("try { } catch (e) { }", Some(serde_json::json!([{"name": "_){ } evilCode; if(false"}]))), - ("try { } catch (notMatching) { }", Some(serde_json::json!([{"ignore": []}]))), - ("try { } catch (notMatching) { }", Some(serde_json::json!([{"ignore": ["unicorn"]}]))), - ("try { } catch (notMatching) { }", Some(serde_json::json!([{"ignore": ["unicorn"]}]))), - ("try { } catch (_) { console.log(_) }", None), - ("try { } catch (err) { console.error(err) }", None), - ("promise.catch(notMatching => { })", Some(serde_json::json!([{"ignore": ["unicorn"]}]))), - ("promise.catch((foo) => { })", None), - ("promise.catch(function (foo) { })", None), - ("promise.catch((function (foo) { }))", None), - ("promise.then(function (foo) { }).catch((foo) => { })", None), - ("promise.then(undefined, function (foo) { })", None), - ("promise.then(undefined, (foo) => { })", None), + ( + "const handleError = error => { + try { + doSomething(); + } catch (foo) { + console.log(foo); + } + }", + None, + ), + ( + "const handleError = error => { + const error9 = new Error('foo bar'); + try { + doSomething(); + } catch (foo) { + console.log(foo); + } + }", + None, + ), + ( + "const handleError = error => { + const error_ = new Error('foo bar'); + obj.catch(foo => { }); + }", + None, + ), + ( + "obj.catch(err => {}); + obj.catch(err => {}); + obj.then(err => {}, err => {}); + obj.then(err => {}, err => {});", + None, + ), + ("try {} catch (descriptiveError) {}", Some(serde_json::json!([{"name": "exception"}]))), + ("try {} catch (e) {}", Some(serde_json::json!([{"name": "has_space_after "}]))), + ("try {} catch (e) {}", Some(serde_json::json!([{"name": "1_start_with_a_number"}]))), + ("try {} catch (e) {}", Some(serde_json::json!([{"name": "_){} evilCode; if(false"}]))), + ("try {} catch (notMatching) {}", Some(serde_json::json!([{"ignore": []}]))), + ("try {} catch (notMatching) {}", Some(serde_json::json!([{"ignore": ["unicorn"]}]))), + // ("try {} catch (notMatching) {}", Some(serde_json::json!([{"ignore": [/unicorn/]}]))), + ( + "try {} catch (error1) {} + try {} catch (error1__) {} + try {} catch (error2) {} + try {} catch (unicorn) {}", + Some(serde_json::json!([{"ignore": [r"error\d*"]}])), + ), + ( + "try {} catch (notMatching) {} + try {} catch (unicorn) {} + try {} catch (unicorn__) {}", + Some(serde_json::json!([{"ignore": ["unicorn"]}])), + ), + ("promise.catch(notMatching => {})", Some(serde_json::json!([{"ignore": ["unicorn"]}]))), + ( + "try { + } catch (_) { + console.log(_) + try { + } catch (_) { + console.log(_) + } + }", + None, + ), + ( + "foo.then(() => { + try {} catch (e) {} + }).catch(err => err);", + None, + ), + ( + "try { + doSomething(); + } catch (anyName) { // Nesting of catch clauses disables the rule + try { + doSomethingElse(); + } catch (anyOtherName) { + // ... + } + }", + None, + ), + ( + r#"@DragSource({ + async endDrag(props, monitor, component) { + try { + } catch (e) { + alert("There was a problem moving these items: " + e); + } + } + }) + export default class A {}"#, + None, + ), + ( + r#"@DragSource({ + async endDrag(props, monitor, component) { + try { + } catch (e) { + alert("1There was a problem moving these items: " + e); + } + } + }) + export default class A {}"#, + None, + ), ]; let fix = vec![ diff --git a/crates/oxc_linter/src/snapshots/unicorn_catch_error_name.snap b/crates/oxc_linter/src/snapshots/unicorn_catch_error_name.snap index 6245fe9bfe1a1..1df23358e1908 100644 --- a/crates/oxc_linter/src/snapshots/unicorn_catch_error_name.snap +++ b/crates/oxc_linter/src/snapshots/unicorn_catch_error_name.snap @@ -1,114 +1,199 @@ --- source: crates/oxc_linter/src/tester.rs --- + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" + โ•ญโ”€[catch_error_name.tsx:4:26] + 3 โ”‚ doSomething(); + 4 โ”‚ } catch (foo) { + ยท โ”€โ”€โ”€ + 5 โ”‚ console.log(foo); + โ•ฐโ”€โ”€โ”€โ”€ + help: Rename `foo` to `error` + + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" + โ•ญโ”€[catch_error_name.tsx:5:26] + 4 โ”‚ doSomething(); + 5 โ”‚ } catch (foo) { + ยท โ”€โ”€โ”€ + 6 โ”‚ console.log(foo); + โ•ฐโ”€โ”€โ”€โ”€ + help: Rename `foo` to `error` + + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" + โ•ญโ”€[catch_error_name.tsx:3:27] + 2 โ”‚ const error_ = new Error('foo bar'); + 3 โ”‚ obj.catch(foo => { }); + ยท โ”€โ”€โ”€ + 4 โ”‚ } + โ•ฐโ”€โ”€โ”€โ”€ + help: Replace `foo` with `error`. + + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "err" should be named "error" + โ•ญโ”€[catch_error_name.tsx:1:11] + 1 โ”‚ obj.catch(err => {}); + ยท โ”€โ”€โ”€ + 2 โ”‚ obj.catch(err => {}); + โ•ฐโ”€โ”€โ”€โ”€ + help: Replace `err` with `error`. + + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "err" should be named "error" + โ•ญโ”€[catch_error_name.tsx:2:23] + 1 โ”‚ obj.catch(err => {}); + 2 โ”‚ obj.catch(err => {}); + ยท โ”€โ”€โ”€ + 3 โ”‚ obj.then(err => {}, err => {}); + โ•ฐโ”€โ”€โ”€โ”€ + help: Replace `err` with `error`. + + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "err" should be named "error" + โ•ญโ”€[catch_error_name.tsx:3:33] + 2 โ”‚ obj.catch(err => {}); + 3 โ”‚ obj.then(err => {}, err => {}); + ยท โ”€โ”€โ”€ + 4 โ”‚ obj.then(err => {}, err => {}); + โ•ฐโ”€โ”€โ”€โ”€ + help: Replace `err` with `error`. + + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "err" should be named "error" + โ•ญโ”€[catch_error_name.tsx:4:33] + 3 โ”‚ obj.then(err => {}, err => {}); + 4 โ”‚ obj.then(err => {}, err => {}); + ยท โ”€โ”€โ”€ + โ•ฐโ”€โ”€โ”€โ”€ + help: Replace `err` with `error`. + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "descriptiveError" should be named "exception" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (descriptiveError) { } - ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + โ•ญโ”€[catch_error_name.tsx:1:15] + 1 โ”‚ try {} catch (descriptiveError) {} + ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ•ฐโ”€โ”€โ”€โ”€ help: Replace `descriptiveError` with `exception`. โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "e" should be named "has_space_after" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (e) { } - ยท โ”€ + โ•ญโ”€[catch_error_name.tsx:1:15] + 1 โ”‚ try {} catch (e) {} + ยท โ”€ โ•ฐโ”€โ”€โ”€โ”€ help: Replace `e` with `has_space_after`. โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "e" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (e) { } - ยท โ”€ + โ•ญโ”€[catch_error_name.tsx:1:15] + 1 โ”‚ try {} catch (e) {} + ยท โ”€ โ•ฐโ”€โ”€โ”€โ”€ help: Replace `e` with `error`. โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "e" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (e) { } - ยท โ”€ + โ•ญโ”€[catch_error_name.tsx:1:15] + 1 โ”‚ try {} catch (e) {} + ยท โ”€ โ•ฐโ”€โ”€โ”€โ”€ help: Replace `e` with `error`. โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "notMatching" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (notMatching) { } - ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ - โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `notMatching` with `error`. - - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "notMatching" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (notMatching) { } - ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + โ•ญโ”€[catch_error_name.tsx:1:15] + 1 โ”‚ try {} catch (notMatching) {} + ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ•ฐโ”€โ”€โ”€โ”€ help: Replace `notMatching` with `error`. โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "notMatching" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (notMatching) { } - ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + โ•ญโ”€[catch_error_name.tsx:1:15] + 1 โ”‚ try {} catch (notMatching) {} + ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ•ฐโ”€โ”€โ”€โ”€ help: Replace `notMatching` with `error`. - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "_" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (_) { console.log(_) } - ยท โ”€ + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "unicorn" should be named "error" + โ•ญโ”€[catch_error_name.tsx:4:27] + 3 โ”‚ try {} catch (error2) {} + 4 โ”‚ try {} catch (unicorn) {} + ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ•ฐโ”€โ”€โ”€โ”€ - help: Rename `_` to `error` + help: Replace `unicorn` with `error`. - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "err" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ try { } catch (err) { console.error(err) } - ยท โ”€โ”€โ”€ + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "notMatching" should be named "error" + โ•ญโ”€[catch_error_name.tsx:1:15] + 1 โ”‚ try {} catch (notMatching) {} + ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + 2 โ”‚ try {} catch (unicorn) {} โ•ฐโ”€โ”€โ”€โ”€ - help: Rename `err` to `error` + help: Replace `notMatching` with `error`. โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "notMatching" should be named "error" โ•ญโ”€[catch_error_name.tsx:1:15] - 1 โ”‚ promise.catch(notMatching => { }) + 1 โ”‚ promise.catch(notMatching => {}) ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ•ฐโ”€โ”€โ”€โ”€ help: Replace `notMatching` with `error`. - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:16] - 1 โ”‚ promise.catch((foo) => { }) - ยท โ”€โ”€โ”€ + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "_" should be named "error" + โ•ญโ”€[catch_error_name.tsx:2:22] + 1 โ”‚ try { + 2 โ”‚ } catch (_) { + ยท โ”€ + 3 โ”‚ console.log(_) โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `foo` with `error`. + help: Rename `_` to `error` - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:25] - 1 โ”‚ promise.catch(function (foo) { }) - ยท โ”€โ”€โ”€ + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "_" should be named "error" + โ•ญโ”€[catch_error_name.tsx:5:26] + 4 โ”‚ try { + 5 โ”‚ } catch (_) { + ยท โ”€ + 6 โ”‚ console.log(_) โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `foo` with `error`. + help: Rename `_` to `error` - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:26] - 1 โ”‚ promise.catch((function (foo) { })) - ยท โ”€โ”€โ”€ + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "err" should be named "error" + โ•ญโ”€[catch_error_name.tsx:3:22] + 2 โ”‚ try {} catch (e) {} + 3 โ”‚ }).catch(err => err); + ยท โ”€โ”€โ”€ โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `foo` with `error`. + help: Rename `err` to `error` - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:41] - 1 โ”‚ promise.then(function (foo) { }).catch((foo) => { }) - ยท โ”€โ”€โ”€ + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "e" should be named "error" + โ•ญโ”€[catch_error_name.tsx:2:31] + 1 โ”‚ foo.then(() => { + 2 โ”‚ try {} catch (e) {} + ยท โ”€ + 3 โ”‚ }).catch(err => err); โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `foo` with `error`. + help: Replace `e` with `error`. - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:35] - 1 โ”‚ promise.then(undefined, function (foo) { }) - ยท โ”€โ”€โ”€ + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "anyName" should be named "error" + โ•ญโ”€[catch_error_name.tsx:3:22] + 2 โ”‚ doSomething(); + 3 โ”‚ } catch (anyName) { // Nesting of catch clauses disables the rule + ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + 4 โ”‚ try { + โ•ฐโ”€โ”€โ”€โ”€ + help: Replace `anyName` with `error`. + + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "anyOtherName" should be named "error" + โ•ญโ”€[catch_error_name.tsx:6:26] + 5 โ”‚ doSomethingElse(); + 6 โ”‚ } catch (anyOtherName) { + ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + 7 โ”‚ // ... + โ•ฐโ”€โ”€โ”€โ”€ + help: Replace `anyOtherName` with `error`. + + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "e" should be named "error" + โ•ญโ”€[catch_error_name.tsx:4:30] + 3 โ”‚ try { + 4 โ”‚ } catch (e) { + ยท โ”€ + 5 โ”‚ alert("There was a problem moving these items: " + e); โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `foo` with `error`. + help: Rename `e` to `error` - โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "foo" should be named "error" - โ•ญโ”€[catch_error_name.tsx:1:26] - 1 โ”‚ promise.then(undefined, (foo) => { }) - ยท โ”€โ”€โ”€ + โš  eslint-plugin-unicorn(catch-error-name): The catch parameter "e" should be named "error" + โ•ญโ”€[catch_error_name.tsx:4:30] + 3 โ”‚ try { + 4 โ”‚ } catch (e) { + ยท โ”€ + 5 โ”‚ alert("1There was a problem moving these items: " + e); โ•ฐโ”€โ”€โ”€โ”€ - help: Replace `foo` with `error`. + help: Rename `e` to `error`