Skip to content

Commit 0ddf5ea

Browse files
kachkaevfisker
andauthored
throw-new-error: Fix false positive for Effect library (#2740)
Co-authored-by: fisker Cheung <[email protected]>
1 parent 99acd27 commit 0ddf5ea

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

rules/throw-new-error.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {isMemberExpression} from './ast/index.js';
12
import {switchCallExpressionToNewExpression} from './fix/index.js';
23

34
const messageId = 'throw-new-error';
@@ -23,6 +24,17 @@ const create = context => ({
2324
return;
2425
}
2526

27+
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2654 (Effect library)
28+
if (
29+
isMemberExpression(callee, {
30+
object: 'Data',
31+
property: 'TaggedError',
32+
computed: false,
33+
})
34+
) {
35+
return;
36+
}
37+
2638
return {
2739
node,
2840
messageId,

test/throw-new-error.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ test.snapshot({
2929
'throw lib["Error"]()',
3030
// Not `FooError` like
3131
'throw lib.getError()',
32+
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2654 (Effect library)
33+
'class QueryError extends Data.TaggedError(\'QueryError\') {}',
3234
],
3335
invalid: [
3436
'throw Error()',

0 commit comments

Comments
 (0)