-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
src/utils/matches.ts
Outdated
import micromatch from "micromatch" | ||
|
||
export default function matches(paths: string[], patterns: string[]): string[] { | ||
const isBasename = patterns.every((pattern) => path.basename(pattern) === pattern) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
src/utils/matches.ts
Outdated
for (const pattern of patterns) { | ||
const isBasename = path.basename(pattern) === pattern | ||
hasBasename ||= isBasename | ||
hasNested ||= !isBasename | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 find
s, 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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? 🙏
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. |
files.matches
no longer works when the pattern issome_directory/**/*
, when thebasename
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.