Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/resource-query-exclude-types.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
15 changes: 14 additions & 1 deletion src/shared-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,20 @@
"instanceof": "RegExp"
},
{
"type": "array"
"type": "string"
},
{
"type": "array",
"items": {
"anyOf": [
{
"instanceof": "RegExp"
},
{
"type": "string"
}
]
}
}
]
},
Expand Down
12 changes: 12 additions & 0 deletions test/resource-query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});
});