Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit ec647b2

Browse files
azat-ioShinigami92
andauthored
Add support for Testing library (#195)
Co-authored-by: Shinigami92 <[email protected]>
1 parent fcb34cf commit ec647b2

36 files changed

+855
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"eslint-plugin-react-hooks": "~4.6.0",
8181
"eslint-plugin-sonarjs": "~0.19.0",
8282
"eslint-plugin-spellcheck": "~0.0.20",
83+
"eslint-plugin-testing-library": "~5.10.3",
8384
"eslint-plugin-unicorn": "~46.0.0",
8485
"eslint-plugin-vitest": "~0.1.4",
8586
"eslint-plugin-vue": "~9.11.0",

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-rule-files/src/plugins-map.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
7676
name: 'Spellcheck',
7777
module: 'eslint-plugin-spellcheck',
7878
},
79+
'testing-library': {
80+
name: 'TestingLibrary',
81+
module: 'eslint-plugin-testing-library',
82+
},
7983
unicorn: {
8084
name: 'Unicorn',
8185
module: 'eslint-plugin-unicorn',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Eslint TestingLibrary extensions.
3+
*
4+
* @see [Eslint TestingLibrary extensions](https://github.com/testing-library/eslint-plugin-testing-library)
5+
*/
6+
export type TestingLibraryExtensions =
7+
| 'plugin:testing-library/angular'
8+
| 'plugin:testing-library/dom'
9+
| 'plugin:testing-library/marko'
10+
| 'plugin:testing-library/react'
11+
| 'plugin:testing-library/vue';

src/config/extends/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { PromiseExtensions } from './eslint-plugin-promise';
1313
import type { ReactExtensions } from './eslint-plugin-react';
1414
import type { ReactHooksExtensions } from './eslint-plugin-react-hooks';
1515
import type { SonarjsExtensions } from './eslint-plugin-sonarjs';
16+
import type { TestingLibraryExtensions } from './eslint-plugin-testing-library';
1617
import type { UnicornExtensions } from './eslint-plugin-unicorn';
1718
import type { VitestExtensions } from './eslint-plugin-vitest';
1819
import type { VueExtensions } from './eslint-plugin-vue';
@@ -39,6 +40,7 @@ export type KnownExtensions = LiteralUnion<
3940
| ReactExtensions
4041
| ReactHooksExtensions
4142
| SonarjsExtensions
43+
| TestingLibraryExtensions
4244
| TypescriptEslintExtensions
4345
| UnicornExtensions
4446
| VitestExtensions

src/config/plugin.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type Plugin = LiteralUnion<
1616
| 'react'
1717
| 'sonarjs'
1818
| 'spellcheck'
19+
| 'testing-library'
1920
| 'unicorn'
2021
| 'vitest'
2122
| 'vue'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { LiteralUnion } from '../../utility-types';
2+
3+
/**
4+
* Testing Library settings.
5+
*
6+
* @see [Testing Library settings](https://github.com/testing-library/eslint-plugin-testing-library)
7+
*/
8+
export interface TestingLibrarySettings
9+
extends Partial<Record<string, unknown>> {
10+
/**
11+
* @see [testing-library/custom-queries](https://github.com/testing-library/eslint-plugin-testing-library#testing-librarycustom-queries)
12+
*/
13+
'testing-library/custom-queries'?: 'off' | string[];
14+
15+
/**
16+
* @see [testing-library/custom-renders](https://github.com/testing-library/eslint-plugin-testing-library#testing-librarycustom-renders)
17+
*/
18+
'testing-library/custom-renders'?: 'off' | string[];
19+
20+
/**
21+
* @see [testing-library/utils-module](https://github.com/testing-library/eslint-plugin-testing-library#testing-libraryutils-module)
22+
*/
23+
'testing-library/utils-module'?: LiteralUnion<'off'>;
24+
}

src/rules/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { ReactHooksRules } from './react-hooks';
1414
import type { RuleConfig } from './rule-config';
1515
import type { SonarJSRules } from './sonarjs';
1616
import type { SpellcheckRules } from './spellcheck';
17+
import type { TestingLibraryRules } from './testing-library';
1718
import type { TypeScriptRules } from './typescript-eslint';
1819
import type { UnicornRules } from './unicorn';
1920
import type { VitestRules } from './vitest';
@@ -42,6 +43,7 @@ export type Rules = Partial<
4243
ReactRules &
4344
SonarJSRules &
4445
SpellcheckRules &
46+
TestingLibraryRules &
4547
TypeScriptRules &
4648
UnicornRules &
4749
VitestRules &
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Enforce promises from async queries to be handled.
5+
*
6+
* @see [await-async-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-query.md)
7+
*/
8+
export type AwaitAsyncQueryRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Enforce promises from async queries to be handled.
12+
*
13+
* @see [await-async-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-query.md)
14+
*/
15+
export interface AwaitAsyncQueryRule {
16+
/**
17+
* Enforce promises from async queries to be handled.
18+
*
19+
* @see [await-async-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-query.md)
20+
*/
21+
'testing-library/await-async-query': AwaitAsyncQueryRuleConfig;
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Enforce promises from async utils to be awaited properly.
5+
*
6+
* @see [await-async-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-utils.md)
7+
*/
8+
export type AwaitAsyncUtilsRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Enforce promises from async utils to be awaited properly.
12+
*
13+
* @see [await-async-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-utils.md)
14+
*/
15+
export interface AwaitAsyncUtilsRule {
16+
/**
17+
* Enforce promises from async utils to be awaited properly.
18+
*
19+
* @see [await-async-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-utils.md)
20+
*/
21+
'testing-library/await-async-utils': AwaitAsyncUtilsRuleConfig;
22+
}

0 commit comments

Comments
 (0)