diff --git a/.changeset/resource-query-exclude-types.md b/.changeset/resource-query-exclude-types.md new file mode 100644 index 0000000..a0cecce --- /dev/null +++ b/.changeset/resource-query-exclude-types.md @@ -0,0 +1,5 @@ +--- +"diagnostics-webpack-plugin": patch +--- + +`resourceQueryExclude` takes a string as well as a regexp, which the schema refused on its own and accepted unchecked inside a list. diff --git a/README.md b/README.md index deee9db..77127c3 100644 --- a/README.md +++ b/README.md @@ -362,12 +362,12 @@ to a worker. - Type: ```ts -type resourceQueryExclude = RegExp | RegExp[]; +type resourceQueryExclude = RegExp | RegExp[] | string | string[]; ``` - Default: `[]` -Specify the resource query to exclude. Only affects checks that read the module graph, such as ESLint. +Specify the resource query to exclude. A string is read as the source of a regular expression, so `"raw"` and `/raw/` mean the same thing. Only affects checks that read the module graph, such as ESLint. #### `fix` diff --git a/src/shared-options.json b/src/shared-options.json index 3b10d6a..5c90db0 100644 --- a/src/shared-options.json +++ b/src/shared-options.json @@ -189,7 +189,20 @@ "instanceof": "RegExp" }, { - "type": "array" + "type": "string" + }, + { + "type": "array", + "items": { + "anyOf": [ + { + "instanceof": "RegExp" + }, + { + "type": "string" + } + ] + } } ] }, diff --git a/test/resource-query.test.js b/test/resource-query.test.js index 9dd8cf9..895f92b 100644 --- a/test/resource-query.test.js +++ b/test/resource-query.test.js @@ -35,6 +35,18 @@ describe("resource-query", () => { }); it("should exclude the match resource query written as a string", async () => { + // A string is the source of the regexp, whether it is given on its own or + // among others. + assert.strictEqual(await reported("media"), 0); assert.strictEqual(await reported(["media"]), 0); + assert.strictEqual(await reported([/media/u, "nothing"]), 0); + }); + + it("should reject what is neither a regexp nor a string", async () => { + await assert.rejects( + () => reported([42]), + /resourceQueryExclude\[0\] should be one of these/u, + "a number is not read as the regexp it would become", + ); }); });