Skip to content

Commit

Permalink
Add support for Testing library
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Apr 25, 2023
1 parent 5e0578a commit f1bd19c
Show file tree
Hide file tree
Showing 31 changed files with 815 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"eslint-plugin-react": "~7.32.2",
"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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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
22 changes: 22 additions & 0 deletions src/rules/testing-library/await-async-query.d.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
41 changes: 41 additions & 0 deletions src/rules/testing-library/no-debugging-utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface NoDebuggingUtilsOption {
utilsToCheckFor?: {
prettyFormat?: boolean;
logDOM?: boolean;
logRoles?: boolean;
prettyDOM?: boolean;
logTestingPlaygroundURL?: boolean;
debug?: boolean;
};
}

/**
* Options.
*/
export type NoDebuggingUtilsOptions = [NoDebuggingUtilsOption?];

/**
* Disallow the use of debugging utilities like `debug`.
*
* @see [no-debugging-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-debugging-utils.md)
*/
export type NoDebuggingUtilsRuleConfig = RuleConfig<NoDebuggingUtilsOptions>;

/**
* Disallow the use of debugging utilities like `debug`.
*
* @see [no-debugging-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-debugging-utils.md)
*/
export interface NoDebuggingUtilsRule {
/**
* Disallow the use of debugging utilities like `debug`.
*
* @see [no-debugging-utils](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-debugging-utils.md)
*/
'testing-library/no-debugging-utils': NoDebuggingUtilsRuleConfig;
}
32 changes: 32 additions & 0 deletions src/rules/testing-library/no-dom-import.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export type NoDomImportOption = string;

/**
* Options.
*/
export type NoDomImportOptions = [NoDomImportOption?];

/**
* Disallow importing from DOM Testing Library.
*
* @see [no-dom-import](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-dom-import.md)
*/
export type NoDomImportRuleConfig = RuleConfig<NoDomImportOptions>;

/**
* Disallow importing from DOM Testing Library.
*
* @see [no-dom-import](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-dom-import.md)
*/
export interface NoDomImportRule {
/**
* Disallow importing from DOM Testing Library.
*
* @see [no-dom-import](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-dom-import.md)
*/
'testing-library/no-dom-import': NoDomImportRuleConfig;
}
22 changes: 22 additions & 0 deletions src/rules/testing-library/no-global-regexp-flag-in-query.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Disallow the use of the global RegExp flag (/g) in queries.
*
* @see [no-global-regexp-flag-in-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-global-regexp-flag-in-query.md)
*/
export type NoGlobalRegexpFlagInQueryRuleConfig = RuleConfig<[]>;

/**
* Disallow the use of the global RegExp flag (/g) in queries.
*
* @see [no-global-regexp-flag-in-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-global-regexp-flag-in-query.md)
*/
export interface NoGlobalRegexpFlagInQueryRule {
/**
* Disallow the use of the global RegExp flag (/g) in queries.
*
* @see [no-global-regexp-flag-in-query](https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules/no-global-regexp-flag-in-query.md)
*/
'testing-library/no-global-regexp-flag-in-query': NoGlobalRegexpFlagInQueryRuleConfig;
}
Loading

0 comments on commit f1bd19c

Please sign in to comment.