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/c
exists, thena/./b/./c
also exists, as doesa/././b/././c
etc. 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/c
and 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 thejoin
orresolve
methods in Node’s built-inpath
module.I know this is an old issue, but I manage to fix my problem with
matchBase
option. In my case, I wanted that all.scss
files - regardless the folder level - were matched. Using**/.scss
didn’t solve the problem, but thematchBase: true
did.