New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of minimatch's matchBase
prevents overrides from targeting project root files.
#9740
Comments
Does using |
Using an absolute path (or
|
I've updated the description with a better summary of the problem, along with a reproduction repo that makes it easier to test and step through the issue. |
I'm not sure why we're using That said, I haven't delved into the code at all so there might be (i.e., probably is) something I'm missing. |
I'm taking a stab at fixing using the following semantics:
This is a non-breaking change (I confirmed that @platinumazure - To do this, I am adding unit tests for |
If you think the current test coverage is insufficient, I think we would
welcome a separate PR to shore up coverage. As you can see, this area of
the code is pretty touchy. I'm sorry to ask, but would you mind separating
those out? Thanks so much, we really appreciate you helping us look into
this.
…On Dec 20, 2017 8:50 AM, "Robert Jackson" ***@***.***> wrote:
I'm taking a stab at fixing using the following semantics:
- If the pattern to be matched *starts* with ./: remove ./ and do not
use matchBase
- All other patterns use existing semantics of matchBase
This is a non-breaking change (I confirmed that ./anything.js cannot
match anything today), but adds the ability to match root project files.
@platinumazure <https://github.com/platinumazure> - To do this, I am
adding unit tests for ConfigOps.pathMatchesGlobs (makes it much easier to
confirm expected behavior with a given set of filePath, pattern, and
excludes combinations). Would you prefer that I PR tests for the existing
semantics separately from adding support for ./? That way it might make
it clearer exactly what is changing when I actually make the changes to
lib/config/config-ops.js...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9740 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AARWeqreCnOPGbjS92Fr-pj88hvCMwsNks5tCR7RgaJpZM4RH3Gi>
.
|
Labeling as core bug for now, but if anyone on the team thinks this should definitely be regarded as an enhancement request, feel free to relabel. |
@platinumazure - Not a problem at all! I totally agree that having some additional coverage will make review of the actual fix for this issue much easier. Submitted a battery of unit tests for |
) Prior to this change it was impossible to target files in the project root in `overrides` configuration without _also_ matching files of the same name in nested directories. This was due to the specific options passed to `minimatch` when testing the provided patterns. After this change, it is now possible to prefix a glob with `./` to "anchor" it to the project root. This has the perceived behavior of making it possible to target `./index.js` independently of `src/index.js` (for example). Due to the fact that `./` previously _never matched_ anything (as evidendenced by the unit tests) we can be certain that this does not break any preexisting globs.
Now that the baseline tests are landed, I have submitted #9748 with the potential fix I mentioned above in #9740 (comment). I believe that this is convenient backwards compatible change... |
Due to eslint/eslint#9740, we cannot _actually_ target `<project-root>/index.js` directly from within `overrides` configuration. This commit adds workarounds for both apps and addons. For apps, we avoid adding `index.js` (or `tests/dummy/config/**/*.js`) to the list of overrides. This side-steps the entire issue. For addons, we add `excludedFiles` to ensure that `app/` and `addon/` are _never_ matched by the node file overrides.
Due to eslint/eslint#9740, we cannot _actually_ target `<project-root>/index.js` directly from within `overrides` configuration. This commit adds workarounds for both apps and addons. For apps, we avoid adding `index.js` (or `tests/dummy/config/**/*.js`) to the list of overrides. This side-steps the entire issue. For addons, we add `excludedFiles` to ensure that `app/` and `addon/` are _never_ matched by the node file overrides.
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
Default.
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
Files present:
Command Ran:
I've created a repo to make testing this easier:
What did you expect to happen?
Expected output:
What actually happened? Please include the actual, raw output from ESLint.
No errors were reported.
Detailed Explanation
The new
overrides
feature added in ESLint 4.1.0 (#8081) is awesome (massively better than "sprinkling" config around in a repo or in specific files via comments). Unfortunately, there is a hole in theoverrides
support due to a small implementation decision.When the overrides are processed to determine if each individual override matches or does not match a given file, the
matchBase
option is passed in to minimatch and the includes/excludes are processed.The code that does this can be found here, but is also included below for explanation purposes:
The usage of
matchBase: true
tominimatch
means that patterns without a/
in them will be matched against thefilePath
s base name (i.e.path.basename(filePath)
). This allows matching "all JS files" as simple as*.js
instead of using**/*.js
. Unfortunately, this means that it is nowimpossible to match files in the project root without also matching nested files with the same base name.
The text was updated successfully, but these errors were encountered: