Skip to content

Commit 85c082c

Browse files
authored
fix: explicit matching behavior with negated patterns and arrays (#19845)
1 parent 00e3e6a commit 85c082c

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"dependencies": {
107107
"@eslint-community/eslint-utils": "^4.2.0",
108108
"@eslint-community/regexpp": "^4.12.1",
109-
"@eslint/config-array": "^0.20.0",
109+
"@eslint/config-array": "^0.20.1",
110110
"@eslint/config-helpers": "^0.2.1",
111111
"@eslint/core": "^0.14.0",
112112
"@eslint/eslintrc": "^3.3.1",

tests/lib/eslint/eslint.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,6 +2925,107 @@ describe("ESLint", () => {
29252925
});
29262926
});
29272927

2928+
describe("Globbing based on configs with negated patterns and arrays in `files`", () => {
2929+
// https://github.com/eslint/eslint/issues/19813
2930+
it("should not include custom extensions when negated pattern is specified in `files`", async () => {
2931+
eslint = new ESLint({
2932+
flags,
2933+
cwd: getFixturePath("file-extensions"),
2934+
overrideConfigFile: true,
2935+
overrideConfig: [
2936+
{
2937+
files: ["!foo.js"],
2938+
},
2939+
{
2940+
files: ["!foo.jsx"],
2941+
},
2942+
{
2943+
files: ["!foo.ts"],
2944+
},
2945+
{
2946+
files: ["!g.tsx"],
2947+
},
2948+
],
2949+
});
2950+
const results = await eslint.lintFiles(["."]);
2951+
2952+
// should not include d.jsx, f.ts, and other extensions that are not linted by default
2953+
assert.strictEqual(results.length, 4);
2954+
assert.deepStrictEqual(
2955+
results.map(({ filePath }) => path.basename(filePath)),
2956+
["a.js", "b.mjs", "c.cjs", "eslint.config.js"],
2957+
);
2958+
});
2959+
2960+
it("should not include custom extensions when negated pattern is specified in an array in `files`", async () => {
2961+
eslint = new ESLint({
2962+
flags,
2963+
cwd: getFixturePath("file-extensions"),
2964+
overrideConfigFile: true,
2965+
overrideConfig: [
2966+
{
2967+
files: [["*", "!foo.js"]],
2968+
},
2969+
{
2970+
files: [["!foo.js", "*"]],
2971+
},
2972+
{
2973+
files: [["*", "!foo.ts"]],
2974+
},
2975+
{
2976+
files: [["!foo.ts", "*"]],
2977+
},
2978+
{
2979+
files: [["*", "!g.tsx"]],
2980+
},
2981+
{
2982+
files: [["!g.tsx", "*"]],
2983+
},
2984+
],
2985+
});
2986+
const results = await eslint.lintFiles(["."]);
2987+
2988+
// should not include d.jsx, f.ts, and other extensions that are not linted by default
2989+
assert.strictEqual(results.length, 4);
2990+
assert.deepStrictEqual(
2991+
results.map(({ filePath }) => path.basename(filePath)),
2992+
["a.js", "b.mjs", "c.cjs", "eslint.config.js"],
2993+
);
2994+
});
2995+
2996+
// https://github.com/eslint/eslint/issues/19814
2997+
it("should include custom extensions when matched by a non-universal pattern specified in an array in `files`", async () => {
2998+
eslint = new ESLint({
2999+
flags,
3000+
cwd: getFixturePath("file-extensions", ".."),
3001+
overrideConfigFile: true,
3002+
overrideConfig: [
3003+
{
3004+
files: [["**/*.jsx", "file-extensions/*"]],
3005+
},
3006+
{
3007+
files: [["file-extensions/*", "**/*.ts"]],
3008+
},
3009+
],
3010+
});
3011+
const results = await eslint.lintFiles(["file-extensions"]);
3012+
3013+
// should include d.jsx and f.ts, but not other extensions that are not linted by default
3014+
assert.strictEqual(results.length, 6);
3015+
assert.deepStrictEqual(
3016+
results.map(({ filePath }) => path.basename(filePath)),
3017+
[
3018+
"a.js",
3019+
"b.mjs",
3020+
"c.cjs",
3021+
"d.jsx",
3022+
"eslint.config.js",
3023+
"f.ts",
3024+
],
3025+
);
3026+
});
3027+
});
3028+
29283029
it("should report zero messages when given a '**' pattern with a .js and a .js2 file", async () => {
29293030
eslint = new ESLint({
29303031
flags,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy