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

Basename breaks matching complex pattern #230

Open
TrySound opened this issue Feb 5, 2022 · 2 comments
Open

Basename breaks matching complex pattern #230

TrySound opened this issue Feb 5, 2022 · 2 comments

Comments

@TrySound
Copy link
Contributor

TrySound commented Feb 5, 2022

(Thanks for reporting an issue to micromatch! If you haven't already read the contributor guidelines, Please do that now, then proceed to fill out the details below.)

Please describe the minimum necessary steps to reproduce this issue:

Hi, I tried to use micromatch for prettier I got a failed test with this case

mm.isMatch("__best-tests__/file.js",["**/__best-tests__/*.js"], {basename: true})
// with basenname: true the result is false
// with basename: false the result is true

I wasn't able to make it work with absolute path as well

mm.isMatch("/user/__best-tests__/file.js",["**/__best-tests__/*.js"], {basename: true})

What is happening that shouldn't be?

Correct pattern doesn't work with basename: true

What should be happening instead?

It should match. But I'm not sure. Works with minimatch.

@TrySound
Copy link
Contributor Author

TrySound commented Feb 5, 2022

From docs looks like basename matcher should not be used if pattern contains slashes.

If set, then patterns without slashes will be matched against the basename of the path if it contains slashes.

And this actually matches minimatch bahavior. With filtered patterns I was able to pass prettier tests.

  const withSlashes = [];
  const withoutSlashes = [];
  for (const pattern of patternList) {
    if (pattern.includes("/")) {
      withSlashes.push(pattern);
    } else {
      withoutSlashes.push(pattern);
    }
  }
  const result = micromatch.isMatch(filePath, withoutSlashes, {
      ignore: excludedPatternList,
      matchBase: true,
      dot: true,
    }) ||
    micromatch.isMatch(filePath, withSlashes, {
      ignore: excludedPatternList,
      matchBase: false,
      dot: true,
    })

@HackAttack
Copy link

Root issue seems to be micromatch/picomatch#89.

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

No branches or pull requests

2 participants