Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions crates/oxc_linter/src/rules/promise/prefer_await_to_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ fn is_inside_yield_or_await(node: &AstNode) -> bool {

impl Rule for PreferAwaitToThen {
fn from_configuration(value: serde_json::Value) -> Self {
let strict = match value {
Value::Object(obj) => obj.get("strict").and_then(Value::as_bool).unwrap_or(false),
_ => false,
};
let config = value.get(0);
let strict = config.and_then(|v| v.get("strict")).and_then(Value::as_bool).unwrap_or(false);

Self(PreferAwaitToThenConfig { strict })
}
Expand Down Expand Up @@ -135,7 +133,7 @@ fn test() {
),
(
"async function hi() { await thing().then() }",
Some(serde_json::json!({ "strict": false })),
Some(serde_json::json!([{ "strict": false }])),
),
("const { promise, resolve } = Promise.withResolvers()", None),
("function x () { return Promise.all() } ", None),
Expand All @@ -153,9 +151,13 @@ fn test() {
("something().then(async () => await somethingElse())", None),
(
"async function foo() { await thing().then() }",
Some(serde_json::json!({ "strict": true })),
Some(serde_json::json!([{ "strict": true }])),
),
("async function foo() { thing().then() }", Some(serde_json::json!([{ "strict": false }]))),
(
"async function hi() { await thing().then(x => {}) }",
Some(serde_json::json!([{ "strict": true }])),
),
("async function foo() { thing().then() }", Some(serde_json::json!({ "strict": false }))),
];

Tester::new(PreferAwaitToThen::NAME, PreferAwaitToThen::PLUGIN, pass, fail).test_and_snapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ source: crates/oxc_linter/src/tester.rs
1 │ async function foo() { thing().then() }
· ────
╰────

⚠ eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
╭─[prefer_await_to_then.tsx:1:37]
1 │ async function hi() { await thing().then(x => {}) }
· ────
╰────
Loading