Skip to content

Commit 2b8ebe5

Browse files
dword-designfisker
andauthored
no-unnecessary-await: Fix handling of experimental pipeline operator (#2658)
Co-authored-by: fisker <[email protected]>
1 parent 4c82dc1 commit 2b8ebe5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

rules/no-unnecessary-await.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ function notPromise(node) {
3838
/** @param {import('eslint').Rule.RuleContext} context */
3939
const create = context => ({
4040
AwaitExpression(node) {
41-
if (!notPromise(node.argument)) {
41+
if (
42+
// F#-style pipeline operator, `Promise.resolve() |> await`
43+
!node.argument
44+
|| !notPromise(node.argument)
45+
) {
4246
return;
4347
}
4448

test/no-unnecessary-await.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,33 @@ test.snapshot({
113113
'async function foo() {+await -1}',
114114
],
115115
});
116+
117+
test.babel({
118+
valid: [
119+
{
120+
code: 'Promise.resolve() |> await',
121+
languageOptions: {
122+
parserOptions: {
123+
babelOptions: {
124+
parserOpts: {
125+
plugins: [['pipelineOperator', {proposal: 'fsharp'}]],
126+
},
127+
},
128+
},
129+
},
130+
},
131+
{
132+
code: 'Promise.resolve() |> await %',
133+
languageOptions: {
134+
parserOptions: {
135+
babelOptions: {
136+
parserOpts: {
137+
plugins: [['pipelineOperator', {proposal: 'hack', topicToken: '%'}]],
138+
},
139+
},
140+
},
141+
},
142+
},
143+
],
144+
invalid: [],
145+
});

0 commit comments

Comments
 (0)