Skip to content

refactor(linter/plugins): debug assert that values passed via NAPI are not undefined#20070

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_
Mar 6, 2026
Merged

refactor(linter/plugins): debug assert that values passed via NAPI are not undefined#20070
graphite-app[bot] merged 1 commit intomainfrom
om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 6, 2026

Follow-on after #19675.

The type for lint function that NAPI-RS produces is incorrect. Option::None on Rust side is translated to null, never undefined. Check this with a debug assertion, instead of handling undefined at runtime (which is pointless, because it never is undefined).

Copy link
Member Author

overlookmotel commented Mar 6, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Mar 6, 2026
@overlookmotel overlookmotel force-pushed the om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_ branch from 264f9fc to 7c27819 Compare March 6, 2026 14:37
@overlookmotel overlookmotel force-pushed the om/03-06-refactor_linter_plugins_clarify_types branch from c0fdcb3 to 28b7eec Compare March 6, 2026 14:37
@overlookmotel overlookmotel changed the base branch from om/03-06-refactor_linter_plugins_clarify_types to graphite-base/20070 March 6, 2026 15:37
@overlookmotel overlookmotel force-pushed the om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_ branch from 7c27819 to d80b305 Compare March 6, 2026 15:38
@overlookmotel overlookmotel changed the base branch from graphite-base/20070 to om/03-06-refactor_linter_plugins_clarify_types March 6, 2026 15:38
@overlookmotel overlookmotel marked this pull request as ready for review March 6, 2026 15:50
@overlookmotel overlookmotel requested a review from camc314 as a code owner March 6, 2026 15:50
Copilot AI review requested due to automatic review settings March 6, 2026 15:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new debugAssertIsNotUndefined assertion utility and uses it in cli.ts to verify that NAPI-RS never passes undefined for Option-typed Rust values. Since NAPI-RS maps Option::None to null (not undefined), the previous ?? null null-coalescing operators in the callback wrappers were redundant — they are now removed, with the debug assertions serving as a safety net to catch any regression.

Changes:

  • Added debugAssertIsNotUndefined<T> to apps/oxlint/src-js/utils/asserts.ts — a new debug-only assertion that throws if its argument is undefined
  • Added assertions in loadPluginWrapper and lintFileWrapper in cli.ts to assert that NAPI-RS never passes undefined for pluginName, buffer, and workspaceUri
  • Removed the now-redundant ?? null null-coalescing operators from the two call sites in each wrapper function

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/oxlint/src-js/utils/asserts.ts Adds new debugAssertIsNotUndefined<T> utility, patterned after existing debugAssertIsNonNull<T>
apps/oxlint/src-js/cli.ts Uses the new assertion in loadPluginWrapper and lintFileWrapper; drops redundant ?? null coalescers

@graphite-app graphite-app bot force-pushed the om/03-06-refactor_linter_plugins_clarify_types branch from 33b8af5 to 5f8e97f Compare March 6, 2026 16:09
@graphite-app graphite-app bot force-pushed the om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_ branch from d80b305 to f3aa4cd Compare March 6, 2026 16:10
@overlookmotel overlookmotel force-pushed the om/03-06-refactor_linter_plugins_clarify_types branch from 5f8e97f to 35432f7 Compare March 6, 2026 16:17
@overlookmotel overlookmotel force-pushed the om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_ branch from f3aa4cd to 2951baf Compare March 6, 2026 16:17
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Mar 6, 2026
Copy link
Contributor

camc314 commented Mar 6, 2026

Merge activity

@overlookmotel overlookmotel force-pushed the om/03-06-refactor_linter_plugins_clarify_types branch from 35432f7 to dbd1cb6 Compare March 6, 2026 17:37
@overlookmotel overlookmotel force-pushed the om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_ branch from 2951baf to 9a6c4b9 Compare March 6, 2026 17:37
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 6, 2026
…e not `undefined` (#20070)

Follow-on after #19675.

The type for `lint` function that NAPI-RS produces is incorrect. `Option::None` on Rust side is translated to `null`, never `undefined`. Check this with a debug assertion, instead of handling `undefined` at runtime (which is pointless, because it never is `undefined`).
@graphite-app graphite-app bot force-pushed the om/03-06-refactor_linter_plugins_clarify_types branch from dbd1cb6 to 391ab14 Compare March 6, 2026 17:39
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Mar 6, 2026
@graphite-app graphite-app bot force-pushed the om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_ branch from 9a6c4b9 to cfaa754 Compare March 6, 2026 17:39
Base automatically changed from om/03-06-refactor_linter_plugins_clarify_types to main March 6, 2026 17:46
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 6, 2026
@graphite-app graphite-app bot merged commit cfaa754 into main Mar 6, 2026
20 checks passed
@graphite-app graphite-app bot deleted the om/03-06-refactor_linter_plugins_debug_assert_that_values_passed_via_napi_are_not_undefined_ branch March 6, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants