Skip to content
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

fix: do not crash rule no-unpublished-require #49

Merged
merged 1 commit into from Aug 22, 2022
Merged

fix: do not crash rule no-unpublished-require #49

merged 1 commit into from Aug 22, 2022

Conversation

fasttime
Copy link

Fixes #48

This PR ensures that the rule no-unpublished-require does not crash when the package root directory is required.

This is done by making sure that npmignore.match is never called if the argument is an empty string, which is the relative path of the root directory. That's because calling npmignore.match("") results in an underlying call to ignore().createFilter()(""), where ignore fails with a TypeError.

This works under the assumption that a package can never npmignore its root directory. This does not add logic to check that the "main" file defined in package.json (or fallback file index.js) exists or is published.

I've wrapped the changed code into function calls to make it better readable, and also to avoid running isDevPackage() unnecessarily when isPrivateFile() returns truthy.

@fasttime fasttime marked this pull request as ready for review August 20, 2022 17:38
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 merged commit 38b0298 into eslint-community:master Aug 22, 2022
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.

no-unpublished-require throws a TypeError when "." or "./" is required
2 participants