From 0c3ccb11846c6f1ef8d9ee8ccf34f86c40d843d0 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sun, 23 Apr 2023 16:04:16 +0800 Subject: [PATCH] `prefer-top-level-await`: Ignore `.cjs` files (#2072) Co-authored-by: Sindre Sorhus --- rules/prefer-top-level-await.js | 4 ++++ test/prefer-top-level-await.mjs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/rules/prefer-top-level-await.js b/rules/prefer-top-level-await.js index add6c1edb8..9710d1d2fb 100644 --- a/rules/prefer-top-level-await.js +++ b/rules/prefer-top-level-await.js @@ -59,6 +59,10 @@ const isAwaitArgument = node => { /** @param {import('eslint').Rule.RuleContext} context */ function create(context) { + if (context.getFilename().toLowerCase().endsWith('.cjs')) { + return; + } + const sourceCode = context.getSourceCode(); return { diff --git a/test/prefer-top-level-await.mjs b/test/prefer-top-level-await.mjs index b4bdd083d7..41b7e6ae71 100644 --- a/test/prefer-top-level-await.mjs +++ b/test/prefer-top-level-await.mjs @@ -71,6 +71,10 @@ test.snapshot({ } } `, + { + code: 'foo.then(bar)', + filename: 'foo.cjS', + }, ], invalid: [ 'foo.then(bar)',