eslint-webpack-plugin
eslint-webpack-plugin copied to clipboard
Escaping glob patterns from context. Issue #132
This PR contains a:
- [x] bugfix
- [ ] new feature
- [ ] code refactor
- [x] test update
- [ ] typo fix
- [ ] metadata update
Motivation / Use-Case
If you do not escape glob patterns from context, then the plugin will not match files for linting.
I described the problem in detail in Issue #132
Additional Info
Also, this is not the only problem that square brackets are causing. At least that's what the tests say. If, again, there are brackets in the name of one of the directories before the project, then most of the tests will fail.
- :x: - login: @NormanRosewood . The commit (d2c77a0f4b121063aca7655837b00c0cd8b5a485, e9555b4ee2f376ab139b6e46f3ff7fdba006f5ea, a3c35b290808196c1552308221e9a5ea0331cd8b) is not authorized under a signed CLA. Please click here to be authorized. For further assistance with EasyCLA, please submit a support request ticket.
Make sense to look at stable solutions from fast-glob https://github.com/mrmlnc/fast-glob/blob/master/src/utils/path.ts#L19
Make sense to look at stable solutions from
fast-globhttps://github.com/mrmlnc/fast-glob/blob/master/src/utils/path.ts#L19
In the issue, I described the reason why escaping with a double backslash will not work. Backslashes will be removed after normalizePath
It means we should do normalize after escaping
С:\\path\\[glob-pattern]\\project
after fast-glob escape will turn to
С:\\path\\[glob-pattern\\]\\project (already broken)
and then after normalizePath:
С:/path/[glob-pattern/]/project/
I see, windows characters are not allowed in glob, so we should convert them to glob style firstly
I do not see a way to do this. The problem lies here: utils.js#L57. We resolving context and file paths. Which returns windows path style again. i.e. it doesn't matter what we do with context. Even if we convert context before, it will be with windows backslashes again and glob escape will not work
Just prevent it
How to prevent make path methods use backslashes? In docs for node path i didn't found any solution
You have regexps to fix it
Can you show me pseudo-code example? Where exactly do you think i should use regexp to fix issue
Do it on compiler.options.context, so we will have valid context, when use / to concat with glob + we need escape special character, just avoid using path, also we need add tests with aboslute and relative paths to ensure we don't break them here
This idea is overcomplicated if I got you right In this case we will need to write own path resolving function, which also may work incorrectly in some non-obvious cases
I dunno, maybe it would be better to slice context for file and wanted/exclude before put it in isMatch?
https://github.com/webpack-contrib/eslint-webpack-plugin/blob/master/src/index.js#L112
And don't escape globs in context at all? Because globs cause problem only in case of matching
We have this logic in copy-webpack-plugin, where you can use glob, you can look at code