Skip to content

Commit bb679b5

Browse files
committed
fix(linter): promise/prefer-await-to-then strict option not reading from config (#14382)
fixes #14324
1 parent a86ca0b commit bb679b5

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

crates/oxc_linter/src/rules/promise/prefer_await_to_then.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ fn is_inside_yield_or_await(node: &AstNode) -> bool {
6565

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

7371
Self(PreferAwaitToThenConfig { strict })
7472
}
@@ -135,7 +133,7 @@ fn test() {
135133
),
136134
(
137135
"async function hi() { await thing().then() }",
138-
Some(serde_json::json!({ "strict": false })),
136+
Some(serde_json::json!([{ "strict": false }])),
139137
),
140138
("const { promise, resolve } = Promise.withResolvers()", None),
141139
("function x () { return Promise.all() } ", None),
@@ -153,9 +151,13 @@ fn test() {
153151
("something().then(async () => await somethingElse())", None),
154152
(
155153
"async function foo() { await thing().then() }",
156-
Some(serde_json::json!({ "strict": true })),
154+
Some(serde_json::json!([{ "strict": true }])),
155+
),
156+
("async function foo() { thing().then() }", Some(serde_json::json!([{ "strict": false }]))),
157+
(
158+
"async function hi() { await thing().then(x => {}) }",
159+
Some(serde_json::json!([{ "strict": true }])),
157160
),
158-
("async function foo() { thing().then() }", Some(serde_json::json!({ "strict": false }))),
159161
];
160162

161163
Tester::new(PreferAwaitToThen::NAME, PreferAwaitToThen::PLUGIN, pass, fail).test_and_snapshot();

crates/oxc_linter/src/snapshots/promise_prefer_await_to_then.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ source: crates/oxc_linter/src/tester.rs
7878
1async function foo() { thing().then() }
7979
· ────
8080
╰────
81+
82+
eslint-plugin-promise(prefer-await-to-then): Prefer await to then()/catch()/finally()
83+
╭─[prefer_await_to_then.tsx:1:37]
84+
1async function hi() { await thing().then(x => {}) }
85+
· ────
86+
╰────

0 commit comments

Comments
 (0)