eslint-webpack-plugin icon indicating copy to clipboard operation
eslint-webpack-plugin copied to clipboard

Escaping glob patterns from context. Issue #132

Open NRosewood opened this issue 3 years ago • 15 comments
trafficstars

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.

NRosewood avatar Dec 02 '21 20:12 NRosewood

CLA Not Signed

Make sense to look at stable solutions from fast-glob https://github.com/mrmlnc/fast-glob/blob/master/src/utils/path.ts#L19

alexander-akait avatar Dec 02 '21 20:12 alexander-akait

Make sense to look at stable solutions from fast-glob https://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

NRosewood avatar Dec 02 '21 21:12 NRosewood

It means we should do normalize after escaping

alexander-akait avatar Dec 02 '21 21:12 alexander-akait

С:\\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/

NRosewood avatar Dec 02 '21 21:12 NRosewood

I see, windows characters are not allowed in glob, so we should convert them to glob style firstly

alexander-akait avatar Dec 02 '21 21:12 alexander-akait

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

NRosewood avatar Dec 02 '21 21:12 NRosewood

Just prevent it

alexander-akait avatar Dec 02 '21 21:12 alexander-akait

How to prevent make path methods use backslashes? In docs for node path i didn't found any solution

NRosewood avatar Dec 02 '21 21:12 NRosewood

You have regexps to fix it

alexander-akait avatar Dec 02 '21 21:12 alexander-akait

Can you show me pseudo-code example? Where exactly do you think i should use regexp to fix issue

NRosewood avatar Dec 02 '21 21:12 NRosewood

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

alexander-akait avatar Dec 02 '21 21:12 alexander-akait

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

NRosewood avatar Dec 02 '21 22:12 NRosewood

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

NRosewood avatar Dec 02 '21 22:12 NRosewood

We have this logic in copy-webpack-plugin, where you can use glob, you can look at code

alexander-akait avatar Dec 03 '21 10:12 alexander-akait