FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(linter/node): implement no-top-level-await rule (#24634) · oxc-project/oxc@dd18383 · GitHub

Commit dd18383

Browse files
andauthored
feat(linter/node): implement no-top-level-await rule (#24634)
This implements [`no-top-level-await`](https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/no-top-level-await.md) from the Node ESLint plugin (#493). AI Disclosure: Generated with Claude Code. Reviewed and tested by me. I have an alternative implementation using a Program visitor but it made no difference performance-wise on vscode or in benchmarking outside extreme cases, so I don't think it's really worth the trouble vs the simpler implementation here. It's still in the commit history if that implementation is preferred. There is one notable difference between this and the original implementation, which is that the `convertPath` option is not implemented, and the checking of `package.json`/`.npmignore` is not implemented (it was used for checking if the given module was actually exposed in the library) as there's no way to check against those in oxlint. There's an argument to be made that this makes the rule not worth implementing, and I'm open to that argument if we'd prefer to mark this rule as unsupported instead. All tests were ported from the original rule (excluding those reliant on the mentioned config options/checks that were skipped). I've also had Claude add a few additional test cases (see commit 40418f7) on top to cover behavior that wasn't tested previously. I have confirmed that all of these tests are identical to the behavior of the upstream rule, but I can remove them if we don't want to have any divergence from the upstream test suite. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 79060a1 commit dd18383

8 files changed

Lines changed: 309 additions & 1 deletion

File tree

‎apps/oxlint/src-js/package/config.generated.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ export interface DummyRuleMap {
12341234
"node/no-path-concat"?: RuleNoConfig;
12351235
"node/no-process-env"?: RuleNoConfig | [AllowWarnDeny, NoProcessEnvConfig];
12361236
"node/no-sync"?: RuleNoConfig | [AllowWarnDeny, NoSyncConfig];
1237+
"node/no-top-level-await"?: RuleNoConfig | [AllowWarnDeny, NoTopLevelAwaitConfig];
12371238
"object-shorthand"?:
12381239
RuleNoConfig | [AllowWarnDeny, ShorthandType] | [AllowWarnDeny, ShorthandType, ObjectShorthandOptions];
12391240
"operator-assignment"?: RuleNoConfig | [AllowWarnDeny, AlwaysNever];
@@ -4046,6 +4047,14 @@ export interface NoSyncConfig {
40464047
*/
40474048
ignores?: string[];
40484049
}
4050+
export interface NoTopLevelAwaitConfig {
4051+
/**
4052+
* If `true`, top-level `await` is allowed in files that start with a
4053+
* hashbang (`#!`), which marks them as executable scripts rather than
4054+
* importable modules.
4055+
*/
4056+
ignoreBin?: boolean;
4057+
}
40494058
export interface ObjectShorthandOptions {
40504059
avoidExplicitReturnArrows?: boolean;
40514060
avoidQuotes?: boolean;

‎crates/oxc_linter/src/generated/rule_runner_impls.rs‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/oxc_linter/src/generated/rules_enum.rs‎

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/oxc_linter/src/rules.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ pub(crate) mod node {
853853
pub mod no_path_concat;
854854
pub mod no_process_env;
855855
pub mod no_sync;
856+
pub mod no_top_level_await;
856857
}
857858

858859
/// <https://github.com/vuejs/eslint-plugin-vue>

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL