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 files.matches not working when it's a directory match #15

Merged
merged 5 commits into from
Jan 7, 2022

Conversation

athenayao
Copy link
Contributor

files.matches no longer works when the pattern is some_directory/**/*, when the basename option is true. Patterns with *.js still work fine.

This seems to be an issue with the underlying micromatch/picomatch implementation: micromatch/picomatch#89. My expectation is that when the pattern has a slash, basename should be ignored. No response to that issue though, so throwing a bandaid onto it to make our existing rules work again.

import micromatch from "micromatch"

export default function matches(paths: string[], patterns: string[]): string[] {
const isBasename = patterns.every((pattern) => path.basename(pattern) === pattern)
Copy link

Choose a reason for hiding this comment

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

nit: Could we add a short comment about this workaround so it has a bit of context?

Copy link

Choose a reason for hiding this comment

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

Also, IIUC this might have unexpected behavior if some patterns are fully qualified and some are not -- am I reading this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commented! and yeah hmmmm. I definitely chose the easy way out here. Most of the time everything only has one pattern. Maybe I should check and throw an error / warning if they're mixed?

Copy link

@ddfisher ddfisher Jan 3, 2022

Choose a reason for hiding this comment

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

Yeah, that sounds good! (Seems like a good balance between a quick fix and hitting potentially difficult to debug unexpected behavior later.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Looking a little clumsy, but I think much better that than having it silently / confusingly fail.

@athenayao athenayao requested a review from ddfisher January 4, 2022 21:35
Comment on lines 12 to 16
for (const pattern of patterns) {
const isBasename = path.basename(pattern) === pattern
hasBasename ||= isBasename
hasNested ||= !isBasename
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this loop just be a .find() so that it short-circuits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'd need to do two finds, to check for both nested and basename. And if we're generally expecting only a couple (in most cases one) pattern, this could be slightly better. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not a huge deal, doubt you're gonna have that many patterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, switched to find for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamiebuilds hi hi! Could you help me figure out how to get this bugfix published? 🙏

@athenayao
Copy link
Contributor Author

Want to check if there are any further comments here! Otherwise I'd like to aim to merge / bump version tomorrow to get endanger working again.

@athenayao athenayao merged commit 9d39f72 into discord:master Jan 7, 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.

4 participants