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
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,43 @@ Specify the files and/or directories to exclude. Must be relative to `options.co
- Type:

```ts
type resourceQueryExclude = RegExp | Array<RegExp>;
type resourceQueryExclude = string | RegExp | Array<string | RegExp>;
```

- Default: `[]`

Specify the resource query to exclude.
Exclude modules from linting when their resource query matches one of the
provided patterns. The resource query is the part after `?` in an import, such
as `raw` in `import './file.js?raw'`.

String values are converted to `RegExp`. Use anchors when you need an exact
match.

```js
import ESLintPlugin from 'eslint-rspack-plugin';

export default {
plugins: [
new ESLintPlugin({
resourceQueryExclude: 'raw',
}),
],
};
```

You can also mix strings and `RegExp` values:

```js
import ESLintPlugin from 'eslint-rspack-plugin';

export default {
plugins: [
new ESLintPlugin({
resourceQueryExclude: [/media/, '^raw$'],
}),
],
};
```

### `files`

Expand Down
6 changes: 4 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type SeverityOptions = {
warning?: Severity;
};

export type ResourceQueryExclude = string | RegExp | Array<string | RegExp>;

export type PluginOptions = {
context?: string;
eslintPath?: string;
Expand All @@ -35,7 +37,7 @@ export type PluginOptions = {
lintAllFiles?: boolean;
severity?: SeverityOptions;
outputReport?: OutputReport;
resourceQueryExclude?: RegExp | RegExp[];
resourceQueryExclude?: ResourceQueryExclude;
configType?: string;
};

Expand All @@ -46,7 +48,7 @@ export type ResolvedOptions = Options & {
cacheLocation: string;
configType: string;
extensions: string | string[];
resourceQueryExclude: RegExp | RegExp[];
resourceQueryExclude: ResourceQueryExclude;
severity: Required<SeverityOptions>;
};

Expand Down
17 changes: 17 additions & 0 deletions test/resource-query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ describe('resource-query', () => {
expect(stats.hasWarnings()).toBe(false);
expect(stats.hasErrors()).toBe(false);
});

it('should exclude the match resource query from string pattern', async () => {
const compiler = pack(
'resource-query',
{
resourceQueryExclude: 'media',
extensions: ['.js', '.ts'],
},
{
module: { rules: [{ resourceQuery: /media/, type: 'asset/source' }] },
},
);

const stats = await compiler.runAsync();
expect(stats.hasWarnings()).toBe(false);
expect(stats.hasErrors()).toBe(false);
});
});
Loading