Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for vitest #191

Merged
merged 3 commits into from Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -78,6 +78,7 @@
"eslint-plugin-sonarjs": "~0.19.0",
"eslint-plugin-spellcheck": "~0.0.20",
"eslint-plugin-unicorn": "~46.0.0",
"eslint-plugin-vitest": "~0.1.4",
"eslint-plugin-vue": "~9.11.0",
"eslint-plugin-vue-pug": "~0.6.0",
"expect-type": "~0.15.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.

@@ -0,0 +1,19 @@
diff --git a/src/rules/vitest/valid-title.d.ts b/src/rules/vitest/valid-title.d.ts
index 8bdfe9a..83c707b 100644
--- a/src/rules/vitest/valid-title.d.ts
+++ b/src/rules/vitest/valid-title.d.ts
@@ -8,13 +8,7 @@ export interface ValidTitleOption {
disallowedWords?: string[];
/**
*/
- [k: string]:
- | string
- | [string]
- | [string, string]
- | {
- [k: string]: string | [string] | [string, string];
- };
+ [k: string]: any;
}

/**
4 changes: 4 additions & 0 deletions scripts/generate-rule-files/src/plugins-map.ts
Expand Up @@ -68,6 +68,10 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
name: 'Unicorn',
module: 'eslint-plugin-unicorn',
},
vitest: {
name: 'Vitest',
module: 'eslint-plugin-vitest',
},
vue: {
name: 'Vue',
module: 'eslint-plugin-vue',
Expand Down
8 changes: 8 additions & 0 deletions src/config/extends/eslint-plugin-vitest.d.ts
@@ -0,0 +1,8 @@
/**
* Eslint Vitest extensions.
*
* @see [Eslint Vitest extensions](https://eslint.vuejs.org/user-guide/#usage)
*/
export type VitestExtensions =
| 'plugin:vitest/all'
| 'plugin:vitest/recommended';
2 changes: 2 additions & 0 deletions src/config/extends/index.d.ts
Expand Up @@ -12,6 +12,7 @@ import type { PrettierExtensions } from './eslint-plugin-prettier';
import type { PromiseExtensions } from './eslint-plugin-promise';
import type { SonarjsExtensions } from './eslint-plugin-sonarjs';
import type { UnicornExtensions } from './eslint-plugin-unicorn';
import type { VitestExtensions } from './eslint-plugin-vitest';
import type { VueExtensions } from './eslint-plugin-vue';
import type { VuePugExtensions } from './eslint-plugin-vue-pug';
import type { IntlifyVueI18nExtensions } from './intlify-vue-i18n';
Expand All @@ -36,6 +37,7 @@ export type KnownExtensions = LiteralUnion<
| SonarjsExtensions
| TypescriptEslintExtensions
| UnicornExtensions
| VitestExtensions
| VueExtensions
| VuePugExtensions
>;
Expand Down
1 change: 1 addition & 0 deletions src/config/plugin.d.ts
Expand Up @@ -14,5 +14,6 @@ export type Plugin = LiteralUnion<
| 'sonarjs'
| 'spellcheck'
| 'unicorn'
| 'vitest'
| 'vue'
>;
2 changes: 2 additions & 0 deletions src/rules/index.d.ts
Expand Up @@ -13,6 +13,7 @@ import type { SonarJSRules } from './sonarjs';
import type { SpellcheckRules } from './spellcheck';
import type { TypeScriptRules } from './typescript-eslint';
import type { UnicornRules } from './unicorn';
import type { VitestRules } from './vitest';
import type { VueRules } from './vue';
import type { VueI18nRules } from './vue-i18n';
import type { VuePugRules } from './vue-pug';
Expand All @@ -37,6 +38,7 @@ export type Rules = Partial<
SpellcheckRules &
TypeScriptRules &
UnicornRules &
VitestRules &
VueRules &
VueI18nRules &
VuePugRules &
Expand Down
36 changes: 36 additions & 0 deletions src/rules/vitest/consistent-test-filename.d.ts
@@ -0,0 +1,36 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface ConsistentTestFilenameOption {
pattern?: string;
allTestPattern?: string;
}

/**
* Options.
*/
export type ConsistentTestFilenameOptions = [ConsistentTestFilenameOption?];

/**
* Forbidden .spec test file pattern.
*
* @see [consistent-test-filename](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-filename.md)
*/
export type ConsistentTestFilenameRuleConfig =
RuleConfig<ConsistentTestFilenameOptions>;

/**
* Forbidden .spec test file pattern.
*
* @see [consistent-test-filename](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-filename.md)
*/
export interface ConsistentTestFilenameRule {
/**
* Forbidden .spec test file pattern.
*
* @see [consistent-test-filename](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-filename.md)
*/
'vitest/consistent-test-filename': ConsistentTestFilenameRuleConfig;
}
35 changes: 35 additions & 0 deletions src/rules/vitest/consistent-test-it.d.ts
@@ -0,0 +1,35 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface ConsistentTestItOption {
fn?: 'test' | 'it';
withinDescribe?: 'test' | 'it';
}

/**
* Options.
*/
export type ConsistentTestItOptions = [ConsistentTestItOption?];

/**
* Prefer test or it but not both.
*
* @see [consistent-test-it](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-it.md)
*/
export type ConsistentTestItRuleConfig = RuleConfig<ConsistentTestItOptions>;

/**
* Prefer test or it but not both.
*
* @see [consistent-test-it](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-it.md)
*/
export interface ConsistentTestItRule {
/**
* Prefer test or it but not both.
*
* @see [consistent-test-it](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-it.md)
*/
'vitest/consistent-test-it': ConsistentTestItRuleConfig;
}
22 changes: 22 additions & 0 deletions src/rules/vitest/expect-expect.d.ts
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Enforce having expectation in test body.
*
* @see [expect-expect](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/expect-expect.md)
*/
export type ExpectExpectRuleConfig = RuleConfig<[]>;

/**
* Enforce having expectation in test body.
*
* @see [expect-expect](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/expect-expect.md)
*/
export interface ExpectExpectRule {
/**
* Enforce having expectation in test body.
*
* @see [expect-expect](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/expect-expect.md)
*/
'vitest/expect-expect': ExpectExpectRuleConfig;
}
102 changes: 102 additions & 0 deletions src/rules/vitest/index.d.ts
@@ -0,0 +1,102 @@
import type { ConsistentTestFilenameRule } from './consistent-test-filename';
import type { ConsistentTestItRule } from './consistent-test-it';
import type { ExpectExpectRule } from './expect-expect';
import type { MaxExpectsRule } from './max-expects';
import type { MaxNestedDescribeRule } from './max-nested-describe';
import type { NoAliasMethodsRule } from './no-alias-methods';
import type { NoCommentedOutTestsRule } from './no-commented-out-tests';
import type { NoConditionalExpectRule } from './no-conditional-expect';
import type { NoConditionalInTestRule } from './no-conditional-in-test';
import type { NoConditionalTestsRule } from './no-conditional-tests';
import type { NoDisabledTestsRule } from './no-disabled-tests';
import type { NoDoneCallbackRule } from './no-done-callback';
import type { NoDuplicateHooksRule } from './no-duplicate-hooks';
import type { NoFocusedTestsRule } from './no-focused-tests';
import type { NoHooksRule } from './no-hooks';
import type { NoIdenticalTitleRule } from './no-identical-title';
import type { NoInterpolationInSnapshotsRule } from './no-interpolation-in-snapshots';
import type { NoLargeSnapshotsRule } from './no-large-snapshots';
import type { NoMocksImportRule } from './no-mocks-import';
import type { NoRestrictedMatchersRule } from './no-restricted-matchers';
import type { NoRestrictedViMethodsRule } from './no-restricted-vi-methods';
import type { NoStandaloneExpectRule } from './no-standalone-expect';
import type { NoTestPrefixesRule } from './no-test-prefixes';
import type { NoTestReturnStatementRule } from './no-test-return-statement';
import type { PreferCalledWithRule } from './prefer-called-with';
import type { PreferComparisonMatcherRule } from './prefer-comparison-matcher';
import type { PreferEachRule } from './prefer-each';
import type { PreferEqualityMatcherRule } from './prefer-equality-matcher';
import type { PreferExpectResolvesRule } from './prefer-expect-resolves';
import type { PreferHooksInOrderRule } from './prefer-hooks-in-order';
import type { PreferHooksOnTopRule } from './prefer-hooks-on-top';
import type { PreferLowercaseTitleRule } from './prefer-lowercase-title';
import type { PreferSnapshotHintRule } from './prefer-snapshot-hint';
import type { PreferSpyOnRule } from './prefer-spy-on';
import type { PreferStrictEqualRule } from './prefer-strict-equal';
import type { PreferToBeRule } from './prefer-to-be';
import type { PreferToBeFalsyRule } from './prefer-to-be-falsy';
import type { PreferToBeObjectRule } from './prefer-to-be-object';
import type { PreferToBeTruthyRule } from './prefer-to-be-truthy';
import type { PreferToContainRule } from './prefer-to-contain';
import type { PreferToHaveLengthRule } from './prefer-to-have-length';
import type { PreferTodoRule } from './prefer-todo';
import type { PreferMockPromiseShorthandRule } from './preferMockPromiseShorthand';
import type { RequireHookRule } from './require-hook';
import type { RequireToThrowMessageRule } from './require-to-throw-message';
import type { RequireTopLevelDescribeRule } from './require-top-level-describe';
import type { ValidDescribeCallbackRule } from './valid-describe-callback';
import type { ValidExpectRule } from './valid-expect';
import type { ValidTitleRule } from './valid-title';

/**
* All Vitest rules.
*/
export type VitestRules = PreferLowercaseTitleRule &
MaxNestedDescribeRule &
NoIdenticalTitleRule &
NoFocusedTestsRule &
NoConditionalTestsRule &
ExpectExpectRule &
ConsistentTestItRule &
PreferToBeRule &
NoHooksRule &
NoRestrictedViMethodsRule &
ConsistentTestFilenameRule &
MaxExpectsRule &
NoAliasMethodsRule &
NoCommentedOutTestsRule &
NoConditionalExpectRule &
NoConditionalInTestRule &
NoDisabledTestsRule &
NoDoneCallbackRule &
NoDuplicateHooksRule &
NoLargeSnapshotsRule &
NoInterpolationInSnapshotsRule &
NoMocksImportRule &
NoRestrictedMatchersRule &
NoStandaloneExpectRule &
NoTestPrefixesRule &
NoTestReturnStatementRule &
PreferCalledWithRule &
ValidTitleRule &
ValidExpectRule &
PreferToBeFalsyRule &
PreferToBeObjectRule &
PreferToBeTruthyRule &
PreferToHaveLengthRule &
PreferEqualityMatcherRule &
PreferStrictEqualRule &
PreferExpectResolvesRule &
PreferEachRule &
PreferHooksOnTopRule &
PreferHooksInOrderRule &
PreferMockPromiseShorthandRule &
PreferSnapshotHintRule &
ValidDescribeCallbackRule &
RequireTopLevelDescribeRule &
RequireToThrowMessageRule &
RequireHookRule &
PreferTodoRule &
PreferSpyOnRule &
PreferComparisonMatcherRule &
PreferToContainRule;
34 changes: 34 additions & 0 deletions src/rules/vitest/max-expects.d.ts
@@ -0,0 +1,34 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface MaxExpectsOption {
max?: number;
}

/**
* Options.
*/
export type MaxExpectsOptions = [MaxExpectsOption?];

/**
* Enforce a maximum number of expect per test.
*
* @see [max-expects](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/max-expects.md)
*/
export type MaxExpectsRuleConfig = RuleConfig<MaxExpectsOptions>;

/**
* Enforce a maximum number of expect per test.
*
* @see [max-expects](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/max-expects.md)
*/
export interface MaxExpectsRule {
/**
* Enforce a maximum number of expect per test.
*
* @see [max-expects](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/max-expects.md)
*/
'vitest/max-expects': MaxExpectsRuleConfig;
}
34 changes: 34 additions & 0 deletions src/rules/vitest/max-nested-describe.d.ts
@@ -0,0 +1,34 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface MaxNestedDescribeOption {
max?: number;
}

/**
* Options.
*/
export type MaxNestedDescribeOptions = [MaxNestedDescribeOption?];

/**
* Nested describe block should be less than set max value or default value.
*
* @see [max-nested-describe](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/max-nested-describe.md)
*/
export type MaxNestedDescribeRuleConfig = RuleConfig<MaxNestedDescribeOptions>;

/**
* Nested describe block should be less than set max value or default value.
*
* @see [max-nested-describe](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/max-nested-describe.md)
*/
export interface MaxNestedDescribeRule {
/**
* Nested describe block should be less than set max value or default value.
*
* @see [max-nested-describe](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/max-nested-describe.md)
*/
'vitest/max-nested-describe': MaxNestedDescribeRuleConfig;
}