minimatch: "**/" pattern doesn't match "./" path part
This seems like a bug to me, intuitively, but I don’t see it addressed in the docs anywhere:
var minimatch = require("minimatch");
minimatch("foo/bar.js", "**/foo/**") // true
minimatch("./foo/bar.js", "./**/foo/**") // true
minimatch("./foo/bar.js", "**/foo/**") // false
Shouldn’t the last example return true because **/ should match ./?
Ref. cowboy/node-globule#11
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 16
- Comments: 18 (4 by maintainers)
@kimurakenshi the import plugin has another rule that requires a normalized path; i suggest using that as well.
**does not match.unless{dot:true}is set, and even if it is set, it does not ever match.or..as path portions.Paths starting with
./and../never match a pattern that doesn’t start explicitly with./or../, even if{dot:true}is set.This is by design, and matches the behavior of bash 4.3+.
@corbanbrook I had a similar issue - #51 - and solved it by passing
{dot: true}as the third argument tominimatch():This doesn’t fix @cowboy’s case though:
https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-useless-path-segments.md If you have further questions, please file them on eslint-plugin-import so we don’t create more noise here.
As stated back in February,
*and**(and other wildcard patterns) do not match path portions starting with.unless{dot:true}is set, and**will not never match.or..as path portions. (Otherwise you’d have an infinite regress; ifa/b/cexists, thena/./b/./calso exists, as doesa/././b/././cetc. Should**return an infinite list of entries?)If you are receiving paths that may contain
.or..in them (for example, you have a pattern likea/b/cand the user can pass ina/./b/c, and expects a match), I recommend resolving those prior to passing them tominimatch. You can do this using thejoinorresolvemethods in Node’s built-inpathmodule.I know this is an old issue, but I manage to fix my problem with
matchBaseoption. In my case, I wanted that all.scssfiles - regardless the folder level - were matched. Using**/.scssdidn’t solve the problem, but thematchBase: truedid.