Skip to content

fix(no-missing-import): Support data imports #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2025

Conversation

mureinik
Copy link

Imported prefixed with data: are not modules to be resolved, but the direct data that should be imported (e.g., JavaScript code, JSON or WASM).

This PR adds support for such imports in the no-missing-import rule.

Note:
With this change, the rule doesn't attempt to parse the data being imported, it merely does not try to resolve it to a path (which would fail), and thus allows those imports in the user's code.

Fixes #464

Copy link

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 👍

@aladdin-add aladdin-add requested a review from scagood July 27, 2025 14:58
Copy link

@scagood scagood left a comment

Choose a reason for hiding this comment

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

Love the contribution!

Can you also add a test to ensure this fails when using require in no-missing-require?

@mureinik
Copy link
Author

Can you also add a test to ensure this fails when using require in no-missing-require?

Good catch - require doesn't support data, but the two rules share the usage of import-target.js, and thus would have allowed something like require('data:text/javascript,const x = 123;'), which is of course wrong.

I've amended the PR to address that, and added a test for it.

Imported prefixed with 'data:' are not modules to be resolved, but the
direct data that should be imported (e.g., JavaScript code, JSON or
WASM).

This PR adds support for such imports in the no-missing-import rule.

Note:
With this change, the rule doesn't attempt to parse the data being
imported, it merely does not try to resolve it to a path (which would
fail), and thus allows those imports in the user's code.

Fixes eslint-community#464
Copy link

@scagood scagood left a comment

Choose a reason for hiding this comment

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

Thanks a million 🙇

@aladdin-add aladdin-add merged commit 69ea12b into eslint-community:master Jul 28, 2025
29 checks passed
@mureinik mureinik deleted the data-import branch July 28, 2025 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: no-missing-imports fails on data imports
3 participants