Skip to content
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

fix!: treat * as a universal pattern #50

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/config-array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ A few things to keep in mind:
- You must pass in the absolute filename to get a config for.
- The returned config object never has `files`, `ignores`, or `name` properties; the only properties on the object will be the other configuration options specified.
- The config array caches configs, so subsequent calls to `getConfig()` with the same filename will return in a fast lookup rather than another calculation.
- A config will only be generated if the filename matches an entry in a `files` key. A config will not be generated without matching a `files` key (configs without a `files` key are only applied when another config with a `files` key is applied; configs without `files` are never applied on their own). Any config with a `files` key entry ending with `/**` or `/*` will only be applied if another entry in the same `files` key matches or another config matches.
- A config will only be generated if the filename matches an entry in a `files` key. A config will not be generated without matching a `files` key (configs without a `files` key are only applied when another config with a `files` key is applied; configs without `files` are never applied on their own). Any config with a `files` key entry that is `*` or ends with `/**` or `/*` will only be applied if another entry in the same `files` key matches or another config matches.

## Determining Ignored Paths

Expand Down
6 changes: 3 additions & 3 deletions packages/config-array/src/config-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ export class ConfigArray extends Array {

const matchingConfigIndices = [];
let matchFound = false;
const universalPattern = /\/\*{1,2}$/u;
const universalPattern = /^\*$|\/\*{1,2}$/u;

this.forEach((config, index) => {
if (!config.files) {
Expand All @@ -909,8 +909,8 @@ export class ConfigArray extends Array {
}

/*
* If a config has a files pattern ending in /** or /*, and the
* filePath only matches those patterns, then the config is only
* If a config has a files pattern * or patterns ending in /** or /*,
* and the filePath only matches those patterns, then the config is only
* applied if there is another config where the filePath matches
* a file with a specific extensions such as *.js.
*/
Expand Down
20 changes: 20 additions & 0 deletions packages/config-array/tests/config-array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,26 @@ describe("ConfigArray", () => {
);
});

it('should return "unconfigured" when there is only * pattern', () => {
configs = new ConfigArray(
[
{
files: ["*"],
},
],
{
basePath,
},
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfigStatus(path.join(basePath, "a.js")),
"unconfigured",
);
});

it('should return "matched" when files pattern matches and there is a pattern ending with /**', () => {
configs = new ConfigArray(
[
Expand Down