Skip to content

Commit 131e636

Browse files
authored
Merge branch 'main' into feat-add-autofix-for-await-async-utils
2 parents d841dc6 + 4dc7caa commit 131e636

File tree

6 files changed

+145
-5
lines changed

6 files changed

+145
-5
lines changed

.eslint-doc-generatorrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ const prettierConfig = require('./.prettierrc.js');
33

44
/** @type {import('eslint-doc-generator').GenerateOptions} */
55
const config = {
6+
ignoreConfig: [
7+
'flat/angular',
8+
'flat/dom',
9+
'flat/marko',
10+
'flat/react',
11+
'flat/vue',
12+
],
613
postprocess: (content) =>
714
prettier.format(content, { ...prettierConfig, parser: 'markdown' }),
815
};

README.md

+90
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ Another approach for customizing ESLint config by paths is through [ESLint Casca
108108

109109
## Shareable configurations
110110

111+
> [!NOTE]
112+
>
113+
> `eslint.config.js` compatible versions of configs are available prefixed with
114+
> `flat/`, though most of the plugin documentation still currently uses
115+
> `.eslintrc` syntax.
116+
>
117+
> Refer to the
118+
> [ESLint documentation on the new configuration file format](https://eslint.org/docs/latest/use/configure/configuration-files-new)
119+
> for more.
120+
111121
This plugin exports several recommended configurations that enforce good practices for specific Testing Library packages.
112122
You can find more info about enabled rules in the [Supported Rules section](#supported-rules), under the `Configurations` column.
113123

@@ -140,6 +150,22 @@ module.exports = {
140150
};
141151
```
142152

153+
To enable this configuration with `eslint.config.js`, use
154+
`testingLibrary.configs['flat/dom']`:
155+
156+
```js
157+
const testingLibrary = require('eslint-plugin-testing-library');
158+
159+
module.exports = [
160+
{
161+
files: [
162+
/* glob matching your test files */
163+
],
164+
...testingLibrary.configs['flat/dom'],
165+
},
166+
];
167+
```
168+
143169
### Angular
144170

145171
Enforces recommended rules for Angular Testing Library.
@@ -153,6 +179,22 @@ module.exports = {
153179
};
154180
```
155181

182+
To enable this configuration with `eslint.config.js`, use
183+
`testingLibrary.configs['flat/angular']`:
184+
185+
```js
186+
const testingLibrary = require('eslint-plugin-testing-library');
187+
188+
module.exports = [
189+
{
190+
files: [
191+
/* glob matching your test files */
192+
],
193+
...testingLibrary.configs['flat/angular'],
194+
},
195+
];
196+
```
197+
156198
### React
157199

158200
Enforces recommended rules for React Testing Library.
@@ -166,6 +208,22 @@ module.exports = {
166208
};
167209
```
168210

211+
To enable this configuration with `eslint.config.js`, use
212+
`testingLibrary.configs['flat/react']`:
213+
214+
```js
215+
const testingLibrary = require('eslint-plugin-testing-library');
216+
217+
module.exports = [
218+
{
219+
files: [
220+
/* glob matching your test files */
221+
],
222+
...testingLibrary.configs['flat/react'],
223+
},
224+
];
225+
```
226+
169227
### Vue
170228

171229
Enforces recommended rules for Vue Testing Library.
@@ -179,6 +237,22 @@ module.exports = {
179237
};
180238
```
181239

240+
To enable this configuration with `eslint.config.js`, use
241+
`testingLibrary.configs['flat/vue']`:
242+
243+
```js
244+
const testingLibrary = require('eslint-plugin-testing-library');
245+
246+
module.exports = [
247+
{
248+
files: [
249+
/* glob matching your test files */
250+
],
251+
...testingLibrary.configs['flat/vue'],
252+
},
253+
];
254+
```
255+
182256
### Marko
183257

184258
Enforces recommended rules for Marko Testing Library.
@@ -192,6 +266,22 @@ module.exports = {
192266
};
193267
```
194268

269+
To enable this configuration with `eslint.config.js`, use
270+
`testingLibrary.configs['flat/marko']`:
271+
272+
```js
273+
const testingLibrary = require('eslint-plugin-testing-library');
274+
275+
module.exports = [
276+
{
277+
files: [
278+
/* glob matching your test files */
279+
],
280+
...testingLibrary.configs['flat/marko'],
281+
},
282+
];
283+
```
284+
195285
## Supported Rules
196286

197287
> Remember that all rules from this plugin are prefixed by `"testing-library/"`

lib/configs/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SupportedTestingFramework,
99
} from '../utils';
1010

11-
export type LinterConfigRules = Record<string, TSESLint.Linter.RuleEntry>;
11+
export type LinterConfigRules = Pick<Required<TSESLint.Linter.Config>, 'rules'>;
1212

1313
const configsDir = __dirname;
1414

lib/index.ts

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1+
import type { TSESLint } from '@typescript-eslint/utils';
2+
13
import configs from './configs';
24
import rules from './rules';
5+
import { SupportedTestingFramework } from './utils';
6+
7+
// we can't natively import package.json as tsc will copy it into dist/
8+
const {
9+
name: packageName,
10+
version: packageVersion,
11+
// eslint-disable-next-line @typescript-eslint/no-var-requires
12+
} = require('../package.json') as { name: string; version: string };
313

4-
export = {
5-
configs,
14+
const plugin = {
15+
meta: {
16+
name: packageName,
17+
version: packageVersion,
18+
},
19+
// ugly cast for now to keep TypeScript happy since
20+
// we don't have types for flat config yet
21+
configs: {} as Record<
22+
SupportedTestingFramework | `flat/${SupportedTestingFramework}`,
23+
Pick<Required<TSESLint.Linter.Config>, 'rules'>
24+
>,
625
rules,
726
};
27+
28+
plugin.configs = {
29+
...configs,
30+
...(Object.fromEntries(
31+
Object.entries(configs).map(([framework, config]) => [
32+
`flat/${framework}`,
33+
{
34+
plugins: { 'testing-library': plugin },
35+
rules: config.rules,
36+
},
37+
])
38+
) as Record<
39+
`flat/${SupportedTestingFramework}`,
40+
Pick<Required<TSESLint.Linter.Config>, 'rules'> & { plugins: unknown }
41+
>),
42+
};
43+
44+
export = plugin;

tests/index.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ it('should export configs that refer to actual rules', () => {
5252
'react',
5353
'vue',
5454
'marko',
55+
'flat/dom',
56+
'flat/angular',
57+
'flat/react',
58+
'flat/vue',
59+
'flat/marko',
5560
]);
5661
const allConfigRules = Object.values(allConfigs)
5762
.map((config) => Object.keys(config.rules))

tools/generate-configs/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { type LinterConfigRules } from '../../lib/configs';
1+
import { type TSESLint } from '@typescript-eslint/utils';
2+
23
import rules from '../../lib/rules';
34
import {
45
SUPPORTED_TESTING_FRAMEWORKS,
@@ -11,7 +12,7 @@ const RULE_NAME_PREFIX = 'testing-library/';
1112

1213
const getRecommendedRulesForTestingFramework = (
1314
framework: SupportedTestingFramework
14-
): LinterConfigRules =>
15+
): Record<string, TSESLint.Linter.RuleEntry> =>
1516
Object.entries(rules)
1617
.filter(
1718
([

0 commit comments

Comments
 (0)