Skip to content

Commit 79ad4bc

Browse files
authored
fix!: treat * as a universal pattern (#50)
1 parent b5f74ed commit 79ad4bc

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

packages/config-array/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ A few things to keep in mind:
286286
- You must pass in the absolute filename to get a config for.
287287
- The returned config object never has `files`, `ignores`, or `name` properties; the only properties on the object will be the other configuration options specified.
288288
- The config array caches configs, so subsequent calls to `getConfig()` with the same filename will return in a fast lookup rather than another calculation.
289-
- 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.
289+
- 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.
290290

291291
## Determining Ignored Paths
292292

packages/config-array/src/config-array.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ export class ConfigArray extends Array {
836836

837837
const matchingConfigIndices = [];
838838
let matchFound = false;
839-
const universalPattern = /\/\*{1,2}$/u;
839+
const universalPattern = /^\*$|\/\*{1,2}$/u;
840840

841841
this.forEach((config, index) => {
842842
if (!config.files) {
@@ -861,8 +861,8 @@ export class ConfigArray extends Array {
861861
}
862862

863863
/*
864-
* If a config has a files pattern ending in /** or /*, and the
865-
* filePath only matches those patterns, then the config is only
864+
* If a config has a files pattern * or patterns ending in /** or /*,
865+
* and the filePath only matches those patterns, then the config is only
866866
* applied if there is another config where the filePath matches
867867
* a file with a specific extensions such as *.js.
868868
*/

packages/config-array/tests/config-array.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,26 @@ describe("ConfigArray", () => {
14341434
);
14351435
});
14361436

1437+
it('should return "unconfigured" when there is only * pattern', () => {
1438+
configs = new ConfigArray(
1439+
[
1440+
{
1441+
files: ["*"],
1442+
},
1443+
],
1444+
{
1445+
basePath,
1446+
},
1447+
);
1448+
1449+
configs.normalizeSync();
1450+
1451+
assert.strictEqual(
1452+
configs.getConfigStatus(path.join(basePath, "a.js")),
1453+
"unconfigured",
1454+
);
1455+
});
1456+
14371457
it('should return "matched" when files pattern matches and there is a pattern ending with /**', () => {
14381458
configs = new ConfigArray(
14391459
[

0 commit comments

Comments
 (0)