-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(no-throw-statements)!: replace option
allowInAsyncFunctions
wi…
…th `allowToRejectPromises`
- Loading branch information
1 parent
d399066
commit 031ef8e
Showing
10 changed files
with
227 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { name, rule } from "#/rules/no-throw-statements"; | ||
import { testRule } from "#/tests/helpers/testers"; | ||
|
||
import es2016Invalid from "../es2016/invalid"; | ||
import es2016Valid from "../es2016/valid"; | ||
import es3Invalid from "../es3/invalid"; | ||
import es3Valid from "../es3/valid"; | ||
|
||
import invalid from "./invalid"; | ||
import valid from "./valid"; | ||
|
||
const tests = { | ||
valid: [...es3Valid, ...es2016Valid, ...valid], | ||
invalid: [...es3Invalid, ...es2016Invalid, ...invalid], | ||
}; | ||
|
||
const tester = testRule(name, rule); | ||
|
||
tester.typescript(tests); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { AST_NODE_TYPES } from "@typescript-eslint/utils"; | ||
import dedent from "dedent"; | ||
|
||
import { type rule } from "#/rules/no-throw-statements"; | ||
import { | ||
type InvalidTestCaseSet, | ||
type MessagesOf, | ||
type OptionsOf, | ||
} from "#/tests/helpers/util"; | ||
|
||
const tests: Array< | ||
InvalidTestCaseSet<MessagesOf<typeof rule>, OptionsOf<typeof rule>> | ||
> = [ | ||
{ | ||
code: dedent` | ||
const foo = Promise.reject(); | ||
foo.then(() => { | ||
throw new Error(); | ||
}); | ||
`, | ||
optionsSet: [ | ||
[ | ||
{ | ||
allowToRejectPromises: true, | ||
}, | ||
], | ||
], | ||
errors: [ | ||
{ | ||
messageId: "generic", | ||
type: AST_NODE_TYPES.ThrowStatement, | ||
line: 3, | ||
column: 3, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: dedent` | ||
const foo = Promise.reject(); | ||
foo.then( | ||
() => { | ||
throw new Error(); | ||
}, | ||
() => {} | ||
); | ||
`, | ||
optionsSet: [ | ||
[ | ||
{ | ||
allowToRejectPromises: true, | ||
}, | ||
], | ||
], | ||
errors: [ | ||
{ | ||
messageId: "generic", | ||
type: AST_NODE_TYPES.ThrowStatement, | ||
line: 4, | ||
column: 7, | ||
}, | ||
], | ||
}, | ||
{ | ||
code: dedent` | ||
const foo = { | ||
catch(cb) { | ||
cb(); | ||
}, | ||
}; | ||
foo.catch(() => { | ||
throw new Error(); | ||
}); | ||
`, | ||
optionsSet: [ | ||
[ | ||
{ | ||
allowToRejectPromises: true, | ||
}, | ||
], | ||
], | ||
errors: [ | ||
{ | ||
messageId: "generic", | ||
type: AST_NODE_TYPES.ThrowStatement, | ||
line: 7, | ||
column: 3, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export default tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import dedent from "dedent"; | ||
|
||
import { type rule } from "#/rules/no-throw-statements"; | ||
import { type OptionsOf, type ValidTestCaseSet } from "#/tests/helpers/util"; | ||
|
||
const tests: Array<ValidTestCaseSet<OptionsOf<typeof rule>>> = [ | ||
{ | ||
code: dedent` | ||
const foo = Promise.reject(); | ||
foo.catch(() => { | ||
throw new Error(); | ||
}); | ||
`, | ||
optionsSet: [ | ||
[ | ||
{ | ||
allowToRejectPromises: true, | ||
}, | ||
], | ||
], | ||
}, | ||
{ | ||
code: dedent` | ||
const foo = Promise.reject(); | ||
foo.then( | ||
() => {}, | ||
() => { | ||
throw new Error(); | ||
} | ||
); | ||
`, | ||
optionsSet: [ | ||
[ | ||
{ | ||
allowToRejectPromises: true, | ||
}, | ||
], | ||
], | ||
}, | ||
]; | ||
|
||
export default tests; |