Closed ericbn closed 3 weeks ago
of modules
It needs to be in a module (ESM), not CommonJS.
Maybe it's possible to check sourceType
via context.languageOptions
Thanks for the heads up. Maybe this should have been part of the unicorn/prefer-module
rule? Or maybe the prefer-top-level-await.md documentation should mention that the rule should be used with module (ESM), not CommonJS?
Description
Adding a top level await in a node script fails with:
The
unicorn/prefer-top-level-await
rule should not apply to scripts.Fail
Pass
Additional Info
The code in the "Fail" example currently passes the linting rule, but the script fails to be executed:
On the other hand, the code in the "Pass" example currently fails the linting rule: