webpack-contrib / eslint-webpack-plugin

A ESLint plugin for webpack
MIT License
254 stars 47 forks source link

Glob patterns are not escaped in the context #132

Closed NRosewood closed 6 months ago

NRosewood commented 2 years ago

Bug report

Actual Behavior

The issue was originally noted in issue #93. But it was not sufficiently tested and the commit that closed the issue did not solve the problem.

If the path to the project and (or) the context from the configuration contains any glob pattern that is not supposed to be processed as a glob pattern, then isMatch in index.js#L112 will not compare correctly, because it will process glob patterns from the entire path of wanted or exclude variables, and not only those what are specified in the plugin configuration. And as a result, the files will not be included in the list for linting, and there will be no errors, because according to the plugin's logic, there is simply nothing to lint.

Expected Behavior

The context is expected to be escaped from glob patterns to avoid non-obvious errors. It is important to only escape globs in context so as not to break globs in the config ...and it should work 😄

How Do We Reproduce?

Just name one directory before the root of the project as [hello-glob] or name the root of the project that way. And initialize plugin with glob: new ESLintPlugin({ files: 'src/**/*', }), Config for eslint itself doesn't matter. You can use any variation of configuration. In ./src/**/ create one or more files with "wrong" JS for linting check.

Solution

If you try to escape globs with double backslash for context, you run into the problem of normalizing the path. In utils.js#L57 normalizePath is called. But it will remove backslashes and make the path invalid. If you don't normalize path, there will be a lot of double backslashes in Windows, and double backslashes for escaping will not work correctly, because it will be interpreted as a directory . At the same time, it makes no sense to separately normalize the context and "file", because after path.resolve the path will again become non-normalized.

The only solution I see at the moment is to escape globs in context this way: [glob-pattern] -> [[]glob-pattern[]] This is valid escaping, but I haven't tested it in your plugin.

npx webpack-cli info and sorry for bad english

System: OS: macOS 12.0.1 CPU: (12) x64 Intel(R) Core(TM) i5-10600 CPU @ 3.30GHz Memory: 24.56 MB / 8.00 GB

Binaries: Node: 14.17.6 - /usr/local/bin/node Yarn: 1.22.11 - /usr/local/bin/yarn npm: 6.14.15 - /usr/local/bin/npm

Browsers: Chrome: 96.0.4664.55 Safari: 15.1

Packages: eslint-webpack-plugin: ^3.1.1 => 3.1.1 webpack: ^5.64.4 => 5.64.4 webpack-cli: ^4.9.1 => 4.9.1

NRosewood commented 2 years ago

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.

ricardogobbosouza commented 6 months ago

Not currently reproducible, if necessary let me know to reopen