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

Commit a00f1e3

Browse files
committed
Add testing-library rules
1 parent 3a37d58 commit a00f1e3

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export interface AwaitAsyncEventsOption {
7+
eventModule?: ('fireEvent' | 'userEvent') | ('fireEvent' | 'userEvent')[];
8+
}
9+
10+
/**
11+
* Options.
12+
*/
13+
export type AwaitAsyncEventsOptions = [AwaitAsyncEventsOption?];
14+
15+
/**
16+
* Enforce promises from async event methods are handled.
17+
*
18+
* @see [await-async-events](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-events.md)
19+
*/
20+
export type AwaitAsyncEventsRuleConfig = RuleConfig<AwaitAsyncEventsOptions>;
21+
22+
/**
23+
* Enforce promises from async event methods are handled.
24+
*
25+
* @see [await-async-events](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-events.md)
26+
*/
27+
export interface AwaitAsyncEventsRule {
28+
/**
29+
* Enforce promises from async event methods are handled.
30+
*
31+
* @see [await-async-events](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-events.md)
32+
*/
33+
'testing-library/await-async-events': AwaitAsyncEventsRuleConfig;
34+
}
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-queries](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-queries.md)
7+
*/
8+
export type AwaitAsyncQueriesRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Enforce promises from async queries to be handled.
12+
*
13+
* @see [await-async-queries](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-queries.md)
14+
*/
15+
export interface AwaitAsyncQueriesRule {
16+
/**
17+
* Enforce promises from async queries to be handled.
18+
*
19+
* @see [await-async-queries](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-queries.md)
20+
*/
21+
'testing-library/await-async-queries': AwaitAsyncQueriesRuleConfig;
22+
}

src/rules/testing-library/index.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import type { AwaitAsyncEventsRule } from './await-async-events';
2+
import type { AwaitAsyncQueriesRule } from './await-async-queries';
13
import type { AwaitAsyncQueryRule } from './await-async-query';
24
import type { AwaitAsyncUtilsRule } from './await-async-utils';
35
import type { AwaitFireEventRule } from './await-fire-event';
46
import type { ConsistentDataTestidRule } from './consistent-data-testid';
57
import type { NoAwaitSyncEventsRule } from './no-await-sync-events';
8+
import type { NoAwaitSyncQueriesRule } from './no-await-sync-queries';
69
import type { NoAwaitSyncQueryRule } from './no-await-sync-query';
710
import type { NoContainerRule } from './no-container';
811
import type { NoDebuggingUtilsRule } from './no-debugging-utils';
@@ -11,6 +14,7 @@ import type { NoGlobalRegexpFlagInQueryRule } from './no-global-regexp-flag-in-q
1114
import type { NoManualCleanupRule } from './no-manual-cleanup';
1215
import type { NoNodeAccessRule } from './no-node-access';
1316
import type { NoPromiseInFireEventRule } from './no-promise-in-fire-event';
17+
import type { NoRenderInLifecycleRule } from './no-render-in-lifecycle';
1418
import type { NoRenderInSetupRule } from './no-render-in-setup';
1519
import type { NoUnnecessaryActRule } from './no-unnecessary-act';
1620
import type { NoWaitForEmptyCallbackRule } from './no-wait-for-empty-callback';
@@ -30,11 +34,14 @@ import type { RenderResultNamingConventionRule } from './render-result-naming-co
3034
/**
3135
* All TestingLibrary rules.
3236
*/
33-
export type TestingLibraryRules = AwaitAsyncQueryRule &
37+
export type TestingLibraryRules = AwaitAsyncEventsRule &
38+
AwaitAsyncQueriesRule &
39+
AwaitAsyncQueryRule &
3440
AwaitAsyncUtilsRule &
3541
AwaitFireEventRule &
3642
ConsistentDataTestidRule &
3743
NoAwaitSyncEventsRule &
44+
NoAwaitSyncQueriesRule &
3845
NoAwaitSyncQueryRule &
3946
NoContainerRule &
4047
NoDebuggingUtilsRule &
@@ -43,6 +50,7 @@ export type TestingLibraryRules = AwaitAsyncQueryRule &
4350
NoManualCleanupRule &
4451
NoNodeAccessRule &
4552
NoPromiseInFireEventRule &
53+
NoRenderInLifecycleRule &
4654
NoRenderInSetupRule &
4755
NoUnnecessaryActRule &
4856
NoWaitForEmptyCallbackRule &
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+
* Disallow unnecessary `await` for sync queries.
5+
*
6+
* @see [no-await-sync-queries](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-queries.md)
7+
*/
8+
export type NoAwaitSyncQueriesRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Disallow unnecessary `await` for sync queries.
12+
*
13+
* @see [no-await-sync-queries](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-queries.md)
14+
*/
15+
export interface NoAwaitSyncQueriesRule {
16+
/**
17+
* Disallow unnecessary `await` for sync queries.
18+
*
19+
* @see [no-await-sync-queries](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-queries.md)
20+
*/
21+
'testing-library/no-await-sync-queries': NoAwaitSyncQueriesRuleConfig;
22+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export interface NoRenderInLifecycleOption {
7+
allowTestingFrameworkSetupHook?: 'beforeEach' | 'beforeAll';
8+
[k: string]: any;
9+
}
10+
11+
/**
12+
* Options.
13+
*/
14+
export type NoRenderInLifecycleOptions = [NoRenderInLifecycleOption?];
15+
16+
/**
17+
* Disallow the use of `render` in testing frameworks setup functions.
18+
*
19+
* @see [no-render-in-lifecycle](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-render-in-lifecycle.md)
20+
*/
21+
export type NoRenderInLifecycleRuleConfig =
22+
RuleConfig<NoRenderInLifecycleOptions>;
23+
24+
/**
25+
* Disallow the use of `render` in testing frameworks setup functions.
26+
*
27+
* @see [no-render-in-lifecycle](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-render-in-lifecycle.md)
28+
*/
29+
export interface NoRenderInLifecycleRule {
30+
/**
31+
* Disallow the use of `render` in testing frameworks setup functions.
32+
*
33+
* @see [no-render-in-lifecycle](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-render-in-lifecycle.md)
34+
*/
35+
'testing-library/no-render-in-lifecycle': NoRenderInLifecycleRuleConfig;
36+
}

0 commit comments

Comments
 (0)