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)',