Skip to content

Commit

Permalink
Add support for Testing library (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: Shinigami92 <chrissi92@hotmail.de>
  • Loading branch information
azat-io and Shinigami92 committed Apr 26, 2023
1 parent fcb34cf commit ec647b2
Show file tree
Hide file tree
Showing 36 changed files with 855 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -80,6 +80,7 @@
"eslint-plugin-react-hooks": "~4.6.0",
"eslint-plugin-sonarjs": "~0.19.0",
"eslint-plugin-spellcheck": "~0.0.20",
"eslint-plugin-testing-library": "~5.10.3",
"eslint-plugin-unicorn": "~46.0.0",
"eslint-plugin-vitest": "~0.1.4",
"eslint-plugin-vue": "~9.11.0",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions scripts/generate-rule-files/src/plugins-map.ts
Expand Up @@ -76,6 +76,10 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
name: 'Spellcheck',
module: 'eslint-plugin-spellcheck',
},
'testing-library': {
name: 'TestingLibrary',
module: 'eslint-plugin-testing-library',
},
unicorn: {
name: 'Unicorn',
module: 'eslint-plugin-unicorn',
Expand Down
11 changes: 11 additions & 0 deletions src/config/extends/eslint-plugin-testing-library.d.ts
@@ -0,0 +1,11 @@
/**
* Eslint TestingLibrary extensions.
*
* @see [Eslint TestingLibrary extensions](https://github.com/testing-library/eslint-plugin-testing-library)
*/
export type TestingLibraryExtensions =
| 'plugin:testing-library/angular'
| 'plugin:testing-library/dom'
| 'plugin:testing-library/marko'
| 'plugin:testing-library/react'
| 'plugin:testing-library/vue';
2 changes: 2 additions & 0 deletions src/config/extends/index.d.ts
Expand Up @@ -13,6 +13,7 @@ import type { PromiseExtensions } from './eslint-plugin-promise';
import type { ReactExtensions } from './eslint-plugin-react';
import type { ReactHooksExtensions } from './eslint-plugin-react-hooks';
import type { SonarjsExtensions } from './eslint-plugin-sonarjs';
import type { TestingLibraryExtensions } from './eslint-plugin-testing-library';
import type { UnicornExtensions } from './eslint-plugin-unicorn';
import type { VitestExtensions } from './eslint-plugin-vitest';
import type { VueExtensions } from './eslint-plugin-vue';
Expand All @@ -39,6 +40,7 @@ export type KnownExtensions = LiteralUnion<
| ReactExtensions
| ReactHooksExtensions
| SonarjsExtensions
| TestingLibraryExtensions
| TypescriptEslintExtensions
| UnicornExtensions
| VitestExtensions
Expand Down
1 change: 1 addition & 0 deletions src/config/plugin.d.ts
Expand Up @@ -16,6 +16,7 @@ export type Plugin = LiteralUnion<
| 'react'
| 'sonarjs'
| 'spellcheck'
| 'testing-library'
| 'unicorn'
| 'vitest'
| 'vue'
Expand Down
24 changes: 24 additions & 0 deletions src/config/settings/testing-library.d.ts
@@ -0,0 +1,24 @@
import type { LiteralUnion } from '../../utility-types';

/**
* Testing Library settings.
*
* @see [Testing Library settings](https://github.com/testing-library/eslint-plugin-testing-library)
*/
export interface TestingLibrarySettings
extends Partial<Record<string, unknown>> {
/**
* @see [testing-library/custom-queries](https://github.com/testing-library/eslint-plugin-testing-library#testing-librarycustom-queries)
*/
'testing-library/custom-queries'?: 'off' | string[];

/**
* @see [testing-library/custom-renders](https://github.com/testing-library/eslint-plugin-testing-library#testing-librarycustom-renders)
*/
'testing-library/custom-renders'?: 'off' | string[];

/**
* @see [testing-library/utils-module](https://github.com/testing-library/eslint-plugin-testing-library#testing-libraryutils-module)
*/
'testing-library/utils-module'?: LiteralUnion<'off'>;
}
2 changes: 2 additions & 0 deletions src/rules/index.d.ts
Expand Up @@ -14,6 +14,7 @@ import type { ReactHooksRules } from './react-hooks';
import type { RuleConfig } from './rule-config';
import type { SonarJSRules } from './sonarjs';
import type { SpellcheckRules } from './spellcheck';
import type { TestingLibraryRules } from './testing-library';
import type { TypeScriptRules } from './typescript-eslint';
import type { UnicornRules } from './unicorn';
import type { VitestRules } from './vitest';
Expand Down Expand Up @@ -42,6 +43,7 @@ export type Rules = Partial<
ReactRules &
SonarJSRules &
SpellcheckRules &
TestingLibraryRules &
TypeScriptRules &
UnicornRules &
VitestRules &
Expand Down
22 changes: 22 additions & 0 deletions src/rules/testing-library/await-async-query.d.ts
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Enforce promises from async queries to be handled.
*
* @see [await-async-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-query.md)
*/
export type AwaitAsyncQueryRuleConfig = RuleConfig<[]>;

/**
* Enforce promises from async queries to be handled.
*
* @see [await-async-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-query.md)
*/
export interface AwaitAsyncQueryRule {
/**
* Enforce promises from async queries to be handled.
*
* @see [await-async-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-query.md)
*/
'testing-library/await-async-query': AwaitAsyncQueryRuleConfig;
}
22 changes: 22 additions & 0 deletions src/rules/testing-library/await-async-utils.d.ts
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Enforce promises from async utils to be awaited properly.
*
* @see [await-async-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-utils.md)
*/
export type AwaitAsyncUtilsRuleConfig = RuleConfig<[]>;

/**
* Enforce promises from async utils to be awaited properly.
*
* @see [await-async-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-utils.md)
*/
export interface AwaitAsyncUtilsRule {
/**
* Enforce promises from async utils to be awaited properly.
*
* @see [await-async-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-async-utils.md)
*/
'testing-library/await-async-utils': AwaitAsyncUtilsRuleConfig;
}
22 changes: 22 additions & 0 deletions src/rules/testing-library/await-fire-event.d.ts
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Enforce promises from `fireEvent` methods to be handled.
*
* @see [await-fire-event](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-fire-event.md)
*/
export type AwaitFireEventRuleConfig = RuleConfig<[]>;

/**
* Enforce promises from `fireEvent` methods to be handled.
*
* @see [await-fire-event](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-fire-event.md)
*/
export interface AwaitFireEventRule {
/**
* Enforce promises from `fireEvent` methods to be handled.
*
* @see [await-fire-event](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/await-fire-event.md)
*/
'testing-library/await-fire-event': AwaitFireEventRuleConfig;
}
37 changes: 37 additions & 0 deletions src/rules/testing-library/consistent-data-testid.d.ts
@@ -0,0 +1,37 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface ConsistentDataTestidOption {
testIdPattern: string;
testIdAttribute?: string | string[];
customMessage?: string;
}

/**
* Options.
*/
export type ConsistentDataTestidOptions = [ConsistentDataTestidOption?];

/**
* Ensures consistent usage of `data-testid`.
*
* @see [consistent-data-testid](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/consistent-data-testid.md)
*/
export type ConsistentDataTestidRuleConfig =
RuleConfig<ConsistentDataTestidOptions>;

/**
* Ensures consistent usage of `data-testid`.
*
* @see [consistent-data-testid](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/consistent-data-testid.md)
*/
export interface ConsistentDataTestidRule {
/**
* Ensures consistent usage of `data-testid`.
*
* @see [consistent-data-testid](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/consistent-data-testid.md)
*/
'testing-library/consistent-data-testid': ConsistentDataTestidRuleConfig;
}
58 changes: 58 additions & 0 deletions src/rules/testing-library/index.d.ts
@@ -0,0 +1,58 @@
import type { AwaitAsyncQueryRule } from './await-async-query';
import type { AwaitAsyncUtilsRule } from './await-async-utils';
import type { AwaitFireEventRule } from './await-fire-event';
import type { ConsistentDataTestidRule } from './consistent-data-testid';
import type { NoAwaitSyncEventsRule } from './no-await-sync-events';
import type { NoAwaitSyncQueryRule } from './no-await-sync-query';
import type { NoContainerRule } from './no-container';
import type { NoDebuggingUtilsRule } from './no-debugging-utils';
import type { NoDomImportRule } from './no-dom-import';
import type { NoGlobalRegexpFlagInQueryRule } from './no-global-regexp-flag-in-query';
import type { NoManualCleanupRule } from './no-manual-cleanup';
import type { NoNodeAccessRule } from './no-node-access';
import type { NoPromiseInFireEventRule } from './no-promise-in-fire-event';
import type { NoRenderInSetupRule } from './no-render-in-setup';
import type { NoUnnecessaryActRule } from './no-unnecessary-act';
import type { NoWaitForEmptyCallbackRule } from './no-wait-for-empty-callback';
import type { NoWaitForMultipleAssertionsRule } from './no-wait-for-multiple-assertions';
import type { NoWaitForSideEffectsRule } from './no-wait-for-side-effects';
import type { NoWaitForSnapshotRule } from './no-wait-for-snapshot';
import type { PreferExplicitAssertRule } from './prefer-explicit-assert';
import type { PreferFindByRule } from './prefer-find-by';
import type { PreferPresenceQueriesRule } from './prefer-presence-queries';
import type { PreferQueryByDisappearanceRule } from './prefer-query-by-disappearance';
import type { PreferScreenQueriesRule } from './prefer-screen-queries';
import type { PreferUserEventRule } from './prefer-user-event';
import type { PreferWaitForRule } from './prefer-wait-for';
import type { RenderResultNamingConventionRule } from './render-result-naming-convention';

/**
* All TestingLibrary rules.
*/
export type TestingLibraryRules = AwaitAsyncQueryRule &
AwaitAsyncUtilsRule &
AwaitFireEventRule &
ConsistentDataTestidRule &
NoAwaitSyncEventsRule &
NoAwaitSyncQueryRule &
NoContainerRule &
NoDebuggingUtilsRule &
NoDomImportRule &
NoGlobalRegexpFlagInQueryRule &
NoManualCleanupRule &
NoNodeAccessRule &
NoPromiseInFireEventRule &
NoRenderInSetupRule &
NoUnnecessaryActRule &
NoWaitForEmptyCallbackRule &
NoWaitForMultipleAssertionsRule &
NoWaitForSideEffectsRule &
NoWaitForSnapshotRule &
PreferExplicitAssertRule &
PreferFindByRule &
PreferPresenceQueriesRule &
PreferQueryByDisappearanceRule &
PreferScreenQueriesRule &
PreferUserEventRule &
PreferWaitForRule &
RenderResultNamingConventionRule;
40 changes: 40 additions & 0 deletions src/rules/testing-library/no-await-sync-events.d.ts
@@ -0,0 +1,40 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface NoAwaitSyncEventsOption {
/**
* @minItems 1
*/
eventModules?: [
'fire-event' | 'user-event',
...('fire-event' | 'user-event')[],
];
}

/**
* Options.
*/
export type NoAwaitSyncEventsOptions = [NoAwaitSyncEventsOption?];

/**
* Disallow unnecessary `await` for sync events.
*
* @see [no-await-sync-events](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-events.md)
*/
export type NoAwaitSyncEventsRuleConfig = RuleConfig<NoAwaitSyncEventsOptions>;

/**
* Disallow unnecessary `await` for sync events.
*
* @see [no-await-sync-events](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-events.md)
*/
export interface NoAwaitSyncEventsRule {
/**
* Disallow unnecessary `await` for sync events.
*
* @see [no-await-sync-events](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-events.md)
*/
'testing-library/no-await-sync-events': NoAwaitSyncEventsRuleConfig;
}
22 changes: 22 additions & 0 deletions src/rules/testing-library/no-await-sync-query.d.ts
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Disallow unnecessary `await` for sync queries.
*
* @see [no-await-sync-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-query.md)
*/
export type NoAwaitSyncQueryRuleConfig = RuleConfig<[]>;

/**
* Disallow unnecessary `await` for sync queries.
*
* @see [no-await-sync-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-query.md)
*/
export interface NoAwaitSyncQueryRule {
/**
* Disallow unnecessary `await` for sync queries.
*
* @see [no-await-sync-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-await-sync-query.md)
*/
'testing-library/no-await-sync-query': NoAwaitSyncQueryRuleConfig;
}
22 changes: 22 additions & 0 deletions src/rules/testing-library/no-container.d.ts
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Disallow the use of `container` methods.
*
* @see [no-container](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-container.md)
*/
export type NoContainerRuleConfig = RuleConfig<[]>;

/**
* Disallow the use of `container` methods.
*
* @see [no-container](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-container.md)
*/
export interface NoContainerRule {
/**
* Disallow the use of `container` methods.
*
* @see [no-container](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-container.md)
*/
'testing-library/no-container': NoContainerRuleConfig;
}

0 comments on commit ec647b2

Please sign in to comment.