From 085e3202f6a4f4bbd05b3d6adf610ce89111ef64 Mon Sep 17 00:00:00 2001 From: Yukihiro Hasegawa <49516827+y-hsgw@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:20:08 +0900 Subject: [PATCH] fix: Apply ESLint to .ts files (#602) * fix: add missing `files` property * fix: lint --- eslint-remote-tester.config.ts | 20 +- eslint.config.js | 10 +- scripts/chain-permutations.ts | 2 +- src/index.ts | 22 +- src/rules/consistent-test-filename.ts | 4 +- src/rules/no-hooks.ts | 2 +- src/rules/no-standalone-expect.ts | 8 +- src/rules/padding-around-after-all-blocks.ts | 2 +- src/rules/padding-around-after-each-blocks.ts | 2 +- src/rules/padding-around-all.ts | 23 +- src/rules/padding-around-before-all-blocks.ts | 2 +- .../padding-around-before-each-blocks.ts | 14 +- src/rules/padding-around-describe-blocks.ts | 18 +- src/rules/padding-around-expect-groups.ts | 22 +- src/rules/padding-around-test-blocks.ts | 18 +- src/rules/prefer-comparison-matcher.ts | 2 +- src/rules/prefer-equality-matcher.ts | 2 +- src/rules/prefer-expect-assertions.ts | 10 +- src/rules/prefer-lowercase-title.ts | 2 +- src/rules/prefer-spy-on.ts | 4 +- src/rules/prefer-vi-mocked.ts | 60 ++-- ...l-test-context-for-concurrent-snapshots.ts | 6 +- src/rules/valid-describe-callback.ts | 2 +- src/rules/valid-expect-in-promise.ts | 314 +++++++++--------- src/rules/valid-expect.ts | 94 +++--- src/rules/valid-title.ts | 20 +- src/utils/ast-utils.ts | 49 ++- src/utils/index.ts | 2 +- src/utils/msc.ts | 4 +- src/utils/padding.ts | 98 +++--- src/utils/parse-vitest-fn-call.ts | 18 +- src/utils/types.ts | 10 +- tests/consistent-test-it.test.ts | 2 +- tests/expect-expect.test.ts | 12 +- tests/max-expects.test.ts | 6 +- tests/max-nested-describe.test.ts | 18 +- tests/no-conditional-in-test.test.ts | 8 +- tests/no-conditional-tests.test.ts | 4 +- tests/no-done-callback.test.ts | 2 +- tests/no-focused-tests.test.ts | 12 +- tests/no-identical-title.test.ts | 10 +- tests/no-large-snapshots.test.ts | 4 +- tests/padding-around-after-all-blocks.test.ts | 22 +- .../padding-around-after-each-blocks.test.ts | 29 +- tests/padding-around-all.test.ts | 50 +-- .../padding-around-before-all-blocks.test.ts | 29 +- .../padding-around-before-each-blocks.test.ts | 29 +- tests/padding-around-describe-blocks.test.ts | 34 +- tests/padding-around-expect-groups.test.ts | 45 ++- tests/padding-around-test-blocks.test.ts | 41 ++- tests/prefer-expect-assertions.test.ts | 12 +- tests/prefer-vi-mocked.test.ts | 146 ++++---- tests/require-hook.test.ts | 6 +- tests/valid-describe-callback.test.ts | 10 +- tests/valid-expect-in-promise.test.ts | 250 +++++++------- tests/valid-expect.test.ts | 28 +- tests/valid-title.test.ts | 1 - unbuild.config.ts | 6 +- 58 files changed, 832 insertions(+), 850 deletions(-) diff --git a/eslint-remote-tester.config.ts b/eslint-remote-tester.config.ts index b2f71852..6bc6320e 100644 --- a/eslint-remote-tester.config.ts +++ b/eslint-remote-tester.config.ts @@ -1,10 +1,10 @@ -import parser from '@typescript-eslint/parser'; -import type { Config } from 'eslint-remote-tester'; +import parser from '@typescript-eslint/parser' +import type { Config } from 'eslint-remote-tester' import { getPathIgnorePattern, - getRepositories, -} from 'eslint-remote-tester-repositories'; -import vitest from './dist/index.mjs'; + getRepositories +} from 'eslint-remote-tester-repositories' +import vitest from './dist/index.mjs' export default { repositories: getRepositories(), @@ -17,8 +17,8 @@ export default { vitest.configs.all, { languageOptions: { - parser, - }, - }, - ] as Config['eslintConfig'], -} satisfies Config; + parser + } + } + ] as Config['eslintConfig'] +} satisfies Config diff --git a/eslint.config.js b/eslint.config.js index d9c40046..34466a15 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -11,10 +11,17 @@ const styleConfigs = stylistic.configs.customize({ commaDangle: 'never' }) +/** @type {import("eslint").Linter.Config[]} */ export default [ eslintPlugin.configs['flat/recommended'], vitest.configs.recommended, vitest.configs.env, + { + files: ['**/*.ts'], + languageOptions: { + parser + } + }, { ignores: ['dist/**/*', '**/*.md'], plugins: { @@ -29,9 +36,6 @@ export default [ vitest: { typecheck: true } - }, - languageOptions: { - parser } } ] diff --git a/scripts/chain-permutations.ts b/scripts/chain-permutations.ts index b761e541..f162bdb2 100644 --- a/scripts/chain-permutations.ts +++ b/scripts/chain-permutations.ts @@ -46,7 +46,7 @@ const DEPTH = 3 const allPermutations: string[] = [] -const depths = (maxDepth:number) => Array.from({ length: maxDepth }, (_, i) => i) +const depths = (maxDepth: number) => Array.from({ length: maxDepth }, (_, i) => i) data.forEach((q) => { q.names.forEach((name) => { diff --git a/src/index.ts b/src/index.ts index 1e0a1ba2..6a202c8d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,7 +41,7 @@ import preferEach, { RULE_NAME as preferEachName } from './rules/prefer-each' import preferHooksOnTop, { RULE_NAME as preferHooksOnTopName } from './rules/prefer-hooks-on-top' import preferHooksInOrder, { RULE_NAME as preferHooksInOrderName } from './rules/prefer-hooks-in-order' import preferMockPromiseShorthand, { RULE_NAME as preferMockPromiseShortHandName } from './rules/prefer-mock-promise-shorthand' -import preferViMocked, { RULE_NAME as preferViMockedName } from "./rules/prefer-vi-mocked"; +import preferViMocked, { RULE_NAME as preferViMockedName } from './rules/prefer-vi-mocked' import preferSnapshotHint, { RULE_NAME as preferSnapshotHintName } from './rules/prefer-snapshot-hint' import validDescribeCallback, { RULE_NAME as validDescribeCallbackName } from './rules/valid-describe-callback' import requireTopLevelDescribe, { RULE_NAME as requireTopLevelDescribeName } from './rules/require-top-level-describe' @@ -53,14 +53,14 @@ import preferSpyOn, { RULE_NAME as preferSpyOnName } from './rules/prefer-spy-on import preferComparisonMatcher, { RULE_NAME as preferComparisonMatcherName } from './rules/prefer-comparison-matcher' import preferToContain, { RULE_NAME as preferToContainName } from './rules/prefer-to-contain' import preferExpectAssertions, { RULE_NAME as preferExpectAssertionsName } from './rules/prefer-expect-assertions' -import paddingAroundAfterAllBlocks, { RULE_NAME as paddingAroundAfterAllBlocksName } from "./rules/padding-around-after-all-blocks" -import paddingAroundAfterEachBlocks, { RULE_NAME as paddingAroundAfterEachBlocksName } from "./rules/padding-around-after-each-blocks" -import paddingAroundAll, { RULE_NAME as paddingAroundAllName } from "./rules/padding-around-all" -import paddingAroundBeforeAllBlocks, { RULE_NAME as paddingAroundBeforeAllBlocksName } from "./rules/padding-around-before-all-blocks" -import paddingAroundBeforeEachBlocks, { RULE_NAME as paddingAroundBeforeEachBlocksName } from "./rules/padding-around-before-each-blocks" -import paddingAroundDescribeBlocks, { RULE_NAME as paddingAroundDescribeBlocksName } from "./rules/padding-around-describe-blocks" -import paddingAroundExpectGroups, { RULE_NAME as paddingAroundExpectGroupsName } from "./rules/padding-around-expect-groups" -import paddingAroundTestBlocks, { RULE_NAME as paddingAroundTestBlocksName } from "./rules/padding-around-test-blocks" +import paddingAroundAfterAllBlocks, { RULE_NAME as paddingAroundAfterAllBlocksName } from './rules/padding-around-after-all-blocks' +import paddingAroundAfterEachBlocks, { RULE_NAME as paddingAroundAfterEachBlocksName } from './rules/padding-around-after-each-blocks' +import paddingAroundAll, { RULE_NAME as paddingAroundAllName } from './rules/padding-around-all' +import paddingAroundBeforeAllBlocks, { RULE_NAME as paddingAroundBeforeAllBlocksName } from './rules/padding-around-before-all-blocks' +import paddingAroundBeforeEachBlocks, { RULE_NAME as paddingAroundBeforeEachBlocksName } from './rules/padding-around-before-each-blocks' +import paddingAroundDescribeBlocks, { RULE_NAME as paddingAroundDescribeBlocksName } from './rules/padding-around-describe-blocks' +import paddingAroundExpectGroups, { RULE_NAME as paddingAroundExpectGroupsName } from './rules/padding-around-expect-groups' +import paddingAroundTestBlocks, { RULE_NAME as paddingAroundTestBlocksName } from './rules/padding-around-test-blocks' import validExpectInPromise, { RULE_NAME as validExpectInPromiseName } from './rules/valid-expect-in-promise' const createConfig = (rules: R) => ( @@ -70,8 +70,8 @@ const createConfig = (rules: R) => ( [`vitest/${ruleName}`]: rules[ruleName] } }, {})) as { - [K in keyof R as `vitest/${Extract}`]: R[K] - } + [K in keyof R as `vitest/${Extract}`]: R[K] +} const createConfigLegacy = (rules: Record) => ({ plugins: ['@vitest'], diff --git a/src/rules/consistent-test-filename.ts b/src/rules/consistent-test-filename.ts index af0aff71..07e30e1a 100644 --- a/src/rules/consistent-test-filename.ts +++ b/src/rules/consistent-test-filename.ts @@ -32,12 +32,12 @@ export default createEslintRule< additionalProperties: false, properties: { pattern: { - //@ts-ignore + // @ts-ignore format: 'regex', default: defaultPattern.source }, allTestPattern: { - //@ts-ignore + // @ts-ignore format: 'regex', default: defaultTestsPattern.source } diff --git a/src/rules/no-hooks.ts b/src/rules/no-hooks.ts index 6dda4b1b..f6f159b1 100644 --- a/src/rules/no-hooks.ts +++ b/src/rules/no-hooks.ts @@ -22,7 +22,7 @@ export default createEslintRule< properties: { allow: { type: 'array', - //@ts-ignore + // @ts-ignore contains: ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'] } }, diff --git a/src/rules/no-standalone-expect.ts b/src/rules/no-standalone-expect.ts index 4d996438..f512c527 100644 --- a/src/rules/no-standalone-expect.ts +++ b/src/rules/no-standalone-expect.ts @@ -50,9 +50,9 @@ export default createEslintRule({ { properties: { additionaltestblockfunctions: { - //@ts-ignore + // @ts-ignore type: 'array', - //@ts-ignore + // @ts-ignore items: { type: `string` } } }, @@ -74,8 +74,8 @@ export default createEslintRule({ if (vitestFnCall?.type === 'expect') { if (vitestFnCall.head.node.parent?.type === AST_NODE_TYPES.MemberExpression && vitestFnCall.members.length === 1 && !['assertions', 'hasAssertions'].includes( - getAccessorValue(vitestFnCall.members[0]) - )) + getAccessorValue(vitestFnCall.members[0]) + )) return const parent = callStack[callStack.length - 1] diff --git a/src/rules/padding-around-after-all-blocks.ts b/src/rules/padding-around-after-all-blocks.ts index 8c303010..1bdf1f52 100644 --- a/src/rules/padding-around-after-all-blocks.ts +++ b/src/rules/padding-around-after-all-blocks.ts @@ -1,4 +1,4 @@ -import { Config, PaddingType, StatementType, createPaddingRule } from "../utils/padding" +import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding' export const RULE_NAME = 'padding-around-after-all-blocks' diff --git a/src/rules/padding-around-after-each-blocks.ts b/src/rules/padding-around-after-each-blocks.ts index f5c239c7..0cb6dc18 100644 --- a/src/rules/padding-around-after-each-blocks.ts +++ b/src/rules/padding-around-after-each-blocks.ts @@ -1,4 +1,4 @@ -import { Config, PaddingType, StatementType, createPaddingRule } from "../utils/padding"; +import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding' export const RULE_NAME = 'padding-around-after-each-blocks' diff --git a/src/rules/padding-around-all.ts b/src/rules/padding-around-all.ts index bbeab532..f8c5ce78 100644 --- a/src/rules/padding-around-all.ts +++ b/src/rules/padding-around-all.ts @@ -1,12 +1,11 @@ - -import { config as paddingAroundAfterAllBlocksConfig } from './padding-around-after-all-blocks'; -import { config as paddingAroundAfterEachBlocksConfig } from './padding-around-after-each-blocks'; -import { config as paddingAroundBeforeAllBlocksConfig } from './padding-around-before-all-blocks'; -import { config as paddingAroundBeforeEachBlocksConfig } from './padding-around-before-each-blocks'; -import { config as paddingAroundDescribeBlocksConfig } from './padding-around-describe-blocks'; -import { config as paddingAroundExpectGroupsConfig } from './padding-around-expect-groups'; -import { config as paddingAroundTestBlocksConfig } from './padding-around-test-blocks'; -import { createPaddingRule } from '../utils/padding'; +import { config as paddingAroundAfterAllBlocksConfig } from './padding-around-after-all-blocks' +import { config as paddingAroundAfterEachBlocksConfig } from './padding-around-after-each-blocks' +import { config as paddingAroundBeforeAllBlocksConfig } from './padding-around-before-all-blocks' +import { config as paddingAroundBeforeEachBlocksConfig } from './padding-around-before-each-blocks' +import { config as paddingAroundDescribeBlocksConfig } from './padding-around-describe-blocks' +import { config as paddingAroundExpectGroupsConfig } from './padding-around-expect-groups' +import { config as paddingAroundTestBlocksConfig } from './padding-around-test-blocks' +import { createPaddingRule } from '../utils/padding' export const RULE_NAME = 'padding-around-all' @@ -20,6 +19,6 @@ export default createPaddingRule( ...paddingAroundBeforeEachBlocksConfig, ...paddingAroundDescribeBlocksConfig, ...paddingAroundExpectGroupsConfig, - ...paddingAroundTestBlocksConfig, - ], -); + ...paddingAroundTestBlocksConfig + ] +) diff --git a/src/rules/padding-around-before-all-blocks.ts b/src/rules/padding-around-before-all-blocks.ts index a6f101bc..e0c710e6 100644 --- a/src/rules/padding-around-before-all-blocks.ts +++ b/src/rules/padding-around-before-all-blocks.ts @@ -1,4 +1,4 @@ -import { Config, PaddingType, StatementType, createPaddingRule } from "../utils/padding"; +import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding' export const RULE_NAME = 'padding-around-before-all-blocks' diff --git a/src/rules/padding-around-before-each-blocks.ts b/src/rules/padding-around-before-each-blocks.ts index fcfaa7fa..1849baf0 100644 --- a/src/rules/padding-around-before-each-blocks.ts +++ b/src/rules/padding-around-before-each-blocks.ts @@ -1,4 +1,4 @@ -import { PaddingType, StatementType, createPaddingRule } from '../utils/padding'; +import { PaddingType, StatementType, createPaddingRule } from '../utils/padding' export const RULE_NAME = 'padding-around-before-each-blocks' @@ -6,17 +6,17 @@ export const config = [ { paddingType: PaddingType.Always, prevStatementType: StatementType.Any, - nextStatementType: StatementType.BeforeEachToken, + nextStatementType: StatementType.BeforeEachToken }, { paddingType: PaddingType.Always, prevStatementType: StatementType.BeforeEachToken, - nextStatementType: StatementType.Any, - }, -]; + nextStatementType: StatementType.Any + } +] export default createPaddingRule( RULE_NAME, 'Enforce padding around `beforeEach` blocks', - config, -); + config +) diff --git a/src/rules/padding-around-describe-blocks.ts b/src/rules/padding-around-describe-blocks.ts index 0cb24b69..e60400e5 100644 --- a/src/rules/padding-around-describe-blocks.ts +++ b/src/rules/padding-around-describe-blocks.ts @@ -1,4 +1,4 @@ -import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding'; +import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding' export const RULE_NAME = 'padding-around-describe-blocks' @@ -9,22 +9,22 @@ export const config: Config[] = [ nextStatementType: [ StatementType.DescribeToken, StatementType.FdescribeToken, - StatementType.XdescribeToken, - ], + StatementType.XdescribeToken + ] }, { paddingType: PaddingType.Always, prevStatementType: [ StatementType.DescribeToken, StatementType.FdescribeToken, - StatementType.XdescribeToken, + StatementType.XdescribeToken ], - nextStatementType: StatementType.Any, - }, -]; + nextStatementType: StatementType.Any + } +] export default createPaddingRule( RULE_NAME, 'Enforce padding around `describe` blocks', - config, -); + config +) diff --git a/src/rules/padding-around-expect-groups.ts b/src/rules/padding-around-expect-groups.ts index 4190bcfa..f04fdedd 100644 --- a/src/rules/padding-around-expect-groups.ts +++ b/src/rules/padding-around-expect-groups.ts @@ -1,4 +1,4 @@ -import { Config, PaddingType, StatementType, createPaddingRule } from "../utils/padding"; +import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding' export const RULE_NAME = 'padding-around-expect-groups' @@ -6,37 +6,37 @@ export const config: Config[] = [ { paddingType: PaddingType.Always, prevStatementType: StatementType.Any, - nextStatementType: StatementType.ExpectToken, + nextStatementType: StatementType.ExpectToken }, { paddingType: PaddingType.Always, prevStatementType: StatementType.ExpectToken, - nextStatementType: StatementType.Any, + nextStatementType: StatementType.Any }, { paddingType: PaddingType.Any, prevStatementType: StatementType.ExpectToken, - nextStatementType: StatementType.ExpectToken, + nextStatementType: StatementType.ExpectToken }, { paddingType: PaddingType.Always, prevStatementType: StatementType.Any, - nextStatementType: StatementType.ExpectTypeOfToken, + nextStatementType: StatementType.ExpectTypeOfToken }, { paddingType: PaddingType.Always, prevStatementType: StatementType.ExpectTypeOfToken, - nextStatementType: StatementType.Any, + nextStatementType: StatementType.Any }, { paddingType: PaddingType.Any, prevStatementType: StatementType.ExpectTypeOfToken, - nextStatementType: StatementType.ExpectTypeOfToken, - }, -]; + nextStatementType: StatementType.ExpectTypeOfToken + } +] export default createPaddingRule( RULE_NAME, 'Enforce padding around `expect` groups', - config, -); + config +) diff --git a/src/rules/padding-around-test-blocks.ts b/src/rules/padding-around-test-blocks.ts index cac453b5..be83750b 100644 --- a/src/rules/padding-around-test-blocks.ts +++ b/src/rules/padding-around-test-blocks.ts @@ -1,4 +1,4 @@ -import { PaddingType, StatementType, createPaddingRule } from '../utils/padding'; +import { PaddingType, StatementType, createPaddingRule } from '../utils/padding' export const RULE_NAME = 'padding-around-test-blocks' @@ -11,8 +11,8 @@ export const config = [ StatementType.ItToken, StatementType.FitToken, StatementType.XitToken, - StatementType.XtestToken, - ], + StatementType.XtestToken + ] }, { paddingType: PaddingType.Always, @@ -21,14 +21,14 @@ export const config = [ StatementType.ItToken, StatementType.FitToken, StatementType.XitToken, - StatementType.XtestToken, + StatementType.XtestToken ], - nextStatementType: StatementType.Any, - }, -]; + nextStatementType: StatementType.Any + } +] export default createPaddingRule( RULE_NAME, 'Enforce padding around afterAll blocks', - config, -); + config +) diff --git a/src/rules/prefer-comparison-matcher.ts b/src/rules/prefer-comparison-matcher.ts index 45cb6f5f..6a2717eb 100644 --- a/src/rules/prefer-comparison-matcher.ts +++ b/src/rules/prefer-comparison-matcher.ts @@ -112,7 +112,7 @@ export default createEslintRule({ ), fixer.replaceTextRange( [expectCallEnd, matcher.parent.range[1]], - `${modifierText}.${preferredMatcher}` + `${modifierText}.${preferredMatcher}` ), fixer.replaceText( matcherArg, diff --git a/src/rules/prefer-equality-matcher.ts b/src/rules/prefer-equality-matcher.ts index 39cc57ba..08ec5feb 100644 --- a/src/rules/prefer-equality-matcher.ts +++ b/src/rules/prefer-equality-matcher.ts @@ -77,7 +77,7 @@ export default createEslintRule({ ), fixer.replaceTextRange( [expectCallEnd, matcher.parent.range[1]], - `${modifierText}.${equalityMatcher}` + `${modifierText}.${equalityMatcher}` ), fixer.replaceText( matcherArg, diff --git a/src/rules/prefer-expect-assertions.ts b/src/rules/prefer-expect-assertions.ts index 1b7de9a7..048d89d4 100644 --- a/src/rules/prefer-expect-assertions.ts +++ b/src/rules/prefer-expect-assertions.ts @@ -38,9 +38,9 @@ const isFirstStatement = (node: TSESTree.CallExpression): boolean => { const suggestRemovingExtraArguments = (context: TSESLint.RuleContext, func: TSESTree.CallExpression, from: number): TSESLint.ReportSuggestionArray[0] => ({ - messageId: 'suggestRemovingExtraArguments', - fix: fixer => removeExtraArgumentsFixer(fixer, context, func, from) - }) + messageId: 'suggestRemovingExtraArguments', + fix: fixer => removeExtraArgumentsFixer(fixer, context, func, from) +}) export default createEslintRule({ name: 'prefer-expect-assertions', @@ -177,7 +177,7 @@ export default createEslintRule({ return } - if (vitestFnCall?.head.type === "testContext" && vitestFnCall.members[0].type === AST_NODE_TYPES.Identifier && vitestFnCall.members[0].name === "expect") { + if (vitestFnCall?.head.type === 'testContext' && vitestFnCall.members[0].type === AST_NODE_TYPES.Identifier && vitestFnCall.members[0].name === 'expect') { testContextName = `${vitestFnCall.head.local}` } @@ -222,7 +222,7 @@ export default createEslintRule({ const suggestions: Array<[MessageIds, string]> = [] if (secondArg.body.type === AST_NODE_TYPES.BlockStatement) { - const prefix = testContextName ? `${testContextName}.` : ""; + const prefix = testContextName ? `${testContextName}.` : '' suggestions.push(['suggestAddingHasAssertions', `${prefix}expect.hasAssertions();`], ['suggestAddingAssertions', `${prefix}expect.assertions();`]) } diff --git a/src/rules/prefer-lowercase-title.ts b/src/rules/prefer-lowercase-title.ts index 5aea1ca4..454790f4 100644 --- a/src/rules/prefer-lowercase-title.ts +++ b/src/rules/prefer-lowercase-title.ts @@ -64,7 +64,7 @@ export default createEslintRule<[ ignore: { type: 'array', items: { - type: "string", + type: 'string', enum: [ DescribeAlias.describe, TestCaseName.test, diff --git a/src/rules/prefer-spy-on.ts b/src/rules/prefer-spy-on.ts index 237bc63e..76ac1490 100644 --- a/src/rules/prefer-spy-on.ts +++ b/src/rules/prefer-spy-on.ts @@ -99,11 +99,11 @@ export default createEslintRule({ fixer.insertTextBefore(left, 'vi.spyOn('), fixer.replaceTextRange( [left.object.range[1], left.property.range[0]], - `, ${lefPropQuote}` + `, ${lefPropQuote}` ), fixer.replaceTextRange( [left.property.range[1], vitestFnCall.range[1]], - `${lefPropQuote})${mockImplementation}` + `${lefPropQuote})${mockImplementation}` ) ] } diff --git a/src/rules/prefer-vi-mocked.ts b/src/rules/prefer-vi-mocked.ts index 506a4761..66c3affc 100644 --- a/src/rules/prefer-vi-mocked.ts +++ b/src/rules/prefer-vi-mocked.ts @@ -1,64 +1,64 @@ -import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/utils"; -import { createEslintRule } from "../utils"; -import { followTypeAssertionChain } from "../utils/ast-utils"; +import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils' +import { createEslintRule } from '../utils' +import { followTypeAssertionChain } from '../utils/ast-utils' -export const RULE_NAME = "prefer-vi-mocked"; -type MESSAGE_IDS = "useViMocked"; +export const RULE_NAME = 'prefer-vi-mocked' +type MESSAGE_IDS = 'useViMocked' -const mockTypes = ["Mock", "MockedFunction", "MockedClass", "MockedObject"]; +const mockTypes = ['Mock', 'MockedFunction', 'MockedClass', 'MockedObject'] -type Options = []; +type Options = [] export default createEslintRule({ name: RULE_NAME, meta: { - type: "suggestion", + type: 'suggestion', docs: { - description: "Prefer `vi.mocked()` over `fn as Mock`", + description: 'require `vi.mocked()` over `fn as Mock`', requiresTypeChecking: true, - recommended: false, + recommended: false }, - fixable: "code", + fixable: 'code', messages: { - useViMocked: "Prefer `vi.mocked()`", + useViMocked: 'Prefer `vi.mocked()`' }, - schema: [], + schema: [] }, defaultOptions: [], create(context) { function check(node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion) { - const { typeAnnotation } = node; + const { typeAnnotation } = node - if (typeAnnotation.type !== AST_NODE_TYPES.TSTypeReference) return; + if (typeAnnotation.type !== AST_NODE_TYPES.TSTypeReference) return - const { typeName } = typeAnnotation; + const { typeName } = typeAnnotation - if (typeName.type !== AST_NODE_TYPES.Identifier) return; + if (typeName.type !== AST_NODE_TYPES.Identifier) return - if (!mockTypes.includes(typeName.name)) return; + if (!mockTypes.includes(typeName.name)) return const fnName = context.sourceCode.text.slice( ...followTypeAssertionChain(node.expression).range - ); + ) context.report({ node, - messageId: "useViMocked", + messageId: 'useViMocked', fix(fixer) { - return fixer.replaceText(node, `vi.mocked(${fnName})`); - }, - }); + return fixer.replaceText(node, `vi.mocked(${fnName})`) + } + }) } return { TSAsExpression(node) { - if (node.parent.type === AST_NODE_TYPES.TSAsExpression) return; + if (node.parent.type === AST_NODE_TYPES.TSAsExpression) return - check(node); + check(node) }, TSTypeAssertion(node) { - check(node); - }, - }; - }, -}); + check(node) + } + } + } +}) diff --git a/src/rules/require-local-test-context-for-concurrent-snapshots.ts b/src/rules/require-local-test-context-for-concurrent-snapshots.ts index e2da574c..527216cb 100644 --- a/src/rules/require-local-test-context-for-concurrent-snapshots.ts +++ b/src/rules/require-local-test-context-for-concurrent-snapshots.ts @@ -24,9 +24,9 @@ export default createEslintRule({ const vitestFnCall = parseVitestFnCall(node, context) if (vitestFnCall === null) return - if (vitestFnCall.type !== "expect") + if (vitestFnCall.type !== 'expect') return - if (vitestFnCall.type === "expect" && vitestFnCall.head.type === "testContext") + if (vitestFnCall.type === 'expect' && vitestFnCall.head.type === 'testContext') return const isNotASnapshotAssertion = ![ @@ -35,7 +35,7 @@ export default createEslintRule({ 'toMatchFileSnapshot', 'toThrowErrorMatchingSnapshot', 'toThrowErrorMatchingInlineSnapshot' - //@ts-ignore + // @ts-ignore ].includes(node.callee?.property.name) if (isNotASnapshotAssertion) return diff --git a/src/rules/valid-describe-callback.ts b/src/rules/valid-describe-callback.ts index 5aea4e0f..bc5e780e 100644 --- a/src/rules/valid-describe-callback.ts +++ b/src/rules/valid-describe-callback.ts @@ -82,7 +82,7 @@ export default createEslintRule({ } if (!isFunction(arg2)) { - if(arg3 && isFunction(arg3)) { + if (arg3 && isFunction(arg3)) { if (hasNonEachMembersAndParams(vitestFnCall, arg3)) { context.report({ messageId: 'unexpectedDescribeArgument', diff --git a/src/rules/valid-expect-in-promise.ts b/src/rules/valid-expect-in-promise.ts index 9aa0d388..f5d9c6ce 100644 --- a/src/rules/valid-expect-in-promise.ts +++ b/src/rules/valid-expect-in-promise.ts @@ -1,120 +1,118 @@ import { AST_NODE_TYPES, TSESTree, TSESLint } from '@typescript-eslint/utils' -import { createEslintRule, getAccessorValue, isSupportedAccessor,type KnownCallExpression, - getNodeName, - isFunction, - isIdentifier } from '../utils' +import { createEslintRule, getAccessorValue, isSupportedAccessor, type KnownCallExpression, + getNodeName, + isFunction, + isIdentifier } from '../utils' import { ModifierName } from '../utils/types' import { - findTopMostCallExpression, - isTypeOfVitestFnCall, - parseVitestFnCall, - } from "../utils/parse-vitest-fn-call"; + findTopMostCallExpression, + isTypeOfVitestFnCall, + parseVitestFnCall +} from '../utils/parse-vitest-fn-call' export const RULE_NAME = 'valid-expect-in-promise' export type MESSAGE_IDS = | 'expectInFloatingPromise' const defaultAsyncMatchers = ['toRejectWith', 'toResolveWith'] - - type PromiseChainCallExpression = KnownCallExpression< - "then" | "catch" | "finally" ->; + 'then' | 'catch' | 'finally' +> const isPromiseChainCall = ( node: TSESTree.Node ): node is PromiseChainCallExpression => { if ( - node.type === AST_NODE_TYPES.CallExpression && - node.callee.type === AST_NODE_TYPES.MemberExpression && - isSupportedAccessor(node.callee.property) + node.type === AST_NODE_TYPES.CallExpression + && node.callee.type === AST_NODE_TYPES.MemberExpression + && isSupportedAccessor(node.callee.property) ) { // promise methods should have at least 1 argument if (node.arguments.length === 0) { - return false; + return false } switch (getAccessorValue(node.callee.property)) { - case "then": - return node.arguments.length < 3; - case "catch": - case "finally": - return node.arguments.length < 2; + case 'then': + return node.arguments.length < 3 + case 'catch': + case 'finally': + return node.arguments.length < 2 } } - return false; -}; + return false +} const isTestCaseCallWithCallbackArg = ( node: TSESTree.CallExpression, context: TSESLint.RuleContext ): boolean => { - const vitestCallFn = parseVitestFnCall(node, context); + const vitestCallFn = parseVitestFnCall(node, context) - if (vitestCallFn?.type !== "test") { - return false; + if (vitestCallFn?.type !== 'test') { + return false } const isVitestEach = vitestCallFn.members.some( - (s) => getAccessorValue(s) === "each" - ); + s => getAccessorValue(s) === 'each' + ) if ( - isVitestEach && - node.callee.type !== AST_NODE_TYPES.TaggedTemplateExpression + isVitestEach + && node.callee.type !== AST_NODE_TYPES.TaggedTemplateExpression ) { - return true; + return true } - const [, callback] = node.arguments; + const [, callback] = node.arguments - const callbackArgIndex = Number(isVitestEach); + const callbackArgIndex = Number(isVitestEach) return ( - callback && - isFunction(callback) && - callback.params.length === 1 + callbackArgIndex - ); -}; + callback + && isFunction(callback) + && callback.params.length === 1 + callbackArgIndex + ) +} const isPromiseMethodThatUsesValue = ( node: TSESTree.AwaitExpression | TSESTree.ReturnStatement, identifier: TSESTree.Identifier ): boolean => { - const { name } = identifier; + const { name } = identifier if (node.argument === null) { - return false; + return false } if ( - node.argument.type === AST_NODE_TYPES.CallExpression && - node.argument.arguments.length > 0 + node.argument.type === AST_NODE_TYPES.CallExpression + && node.argument.arguments.length > 0 ) { - const nodeName = getNodeName(node.argument); + const nodeName = getNodeName(node.argument) - if (["Promise.all", "Promise.allSettled"].includes(nodeName as string)) { - const [firstArg] = node.argument.arguments; + if (['Promise.all', 'Promise.allSettled'].includes(nodeName as string)) { + const [firstArg] = node.argument.arguments if ( - firstArg.type === AST_NODE_TYPES.ArrayExpression && - firstArg.elements.some((nod) => nod && isIdentifier(nod, name)) + firstArg.type === AST_NODE_TYPES.ArrayExpression + && firstArg.elements.some(nod => nod && isIdentifier(nod, name)) ) { - return true; + return true } } if ( - ["Promise.resolve", "Promise.reject"].includes(nodeName as string) && - node.argument.arguments.length === 1 + ['Promise.resolve', 'Promise.reject'].includes(nodeName as string) + && node.argument.arguments.length === 1 ) { - return isIdentifier(node.argument.arguments[0], name); + return isIdentifier(node.argument.arguments[0], name) } } - return isIdentifier(node.argument, name); -}; + return isIdentifier(node.argument, name) +} /** * Attempts to determine if the runtime value represented by the given `identifier` @@ -123,27 +121,27 @@ const isPromiseMethodThatUsesValue = ( const isValueAwaitedInElements = ( name: string, elements: - | TSESTree.ArrayExpression["elements"] - | TSESTree.CallExpression["arguments"] + | TSESTree.ArrayExpression['elements'] + | TSESTree.CallExpression['arguments'] ): boolean => { for (const element of elements) { if ( - element?.type === AST_NODE_TYPES.AwaitExpression && - isIdentifier(element.argument, name) + element?.type === AST_NODE_TYPES.AwaitExpression + && isIdentifier(element.argument, name) ) { - return true; + return true } if ( - element?.type === AST_NODE_TYPES.ArrayExpression && - isValueAwaitedInElements(name, element.elements) + element?.type === AST_NODE_TYPES.ArrayExpression + && isValueAwaitedInElements(name, element.elements) ) { - return true; + return true } } - return false; -}; + return false +} /** * Attempts to determine if the runtime value represented by the given `identifier` @@ -153,48 +151,48 @@ const isValueAwaitedInArguments = ( name: string, call: TSESTree.CallExpression ): boolean => { - let node: TSESTree.Node = call; + let node: TSESTree.Node = call while (node) { if (node.type === AST_NODE_TYPES.CallExpression) { if (isValueAwaitedInElements(name, node.arguments)) { - return true; + return true } - node = node.callee; + node = node.callee } if (node.type !== AST_NODE_TYPES.MemberExpression) { - break; + break } - node = node.object; + node = node.object } - return false; -}; + return false +} const getLeftMostCallExpression = ( call: TSESTree.CallExpression ): TSESTree.CallExpression => { - let leftMostCallExpression: TSESTree.CallExpression = call; - let node: TSESTree.Node = call; + let leftMostCallExpression: TSESTree.CallExpression = call + let node: TSESTree.Node = call while (node) { if (node.type === AST_NODE_TYPES.CallExpression) { - leftMostCallExpression = node; - node = node.callee; + leftMostCallExpression = node + node = node.callee } if (node.type !== AST_NODE_TYPES.MemberExpression) { - break; + break } - node = node.object; + node = node.object } - return leftMostCallExpression; -}; + return leftMostCallExpression +} /** * Attempts to determine if the runtime value represented by the given `identifier` @@ -205,51 +203,51 @@ const isValueAwaitedOrReturned = ( body: TSESTree.Statement[], context: TSESLint.RuleContext ): boolean => { - const { name } = identifier; + const { name } = identifier for (const node of body) { // skip all nodes that are before this identifier, because they'd probably // be affecting a different runtime value (e.g. due to reassignment) if (node.range[0] <= identifier.range[0]) { - continue; + continue } if (node.type === AST_NODE_TYPES.ReturnStatement) { - return isPromiseMethodThatUsesValue(node, identifier); + return isPromiseMethodThatUsesValue(node, identifier) } if (node.type === AST_NODE_TYPES.ExpressionStatement) { // it's possible that we're awaiting the value as an argument if (node.expression.type === AST_NODE_TYPES.CallExpression) { if (isValueAwaitedInArguments(name, node.expression)) { - return true; + return true } - const leftMostCall = getLeftMostCallExpression(node.expression); - const vitestFnCall = parseVitestFnCall(node.expression, context); + const leftMostCall = getLeftMostCallExpression(node.expression) + const vitestFnCall = parseVitestFnCall(node.expression, context) if ( - vitestFnCall?.type === "expect" && - leftMostCall.arguments.length > 0 && - isIdentifier(leftMostCall.arguments[0], name) + vitestFnCall?.type === 'expect' + && leftMostCall.arguments.length > 0 + && isIdentifier(leftMostCall.arguments[0], name) ) { if ( vitestFnCall.members.some((m) => { - const v = getAccessorValue(m); + const v = getAccessorValue(m) - return v === ModifierName.resolves || v === ModifierName.rejects; + return v === ModifierName.resolves || v === ModifierName.rejects }) ) { - return true; + return true } } } if ( - node.expression.type === AST_NODE_TYPES.AwaitExpression && - isPromiseMethodThatUsesValue(node.expression, identifier) + node.expression.type === AST_NODE_TYPES.AwaitExpression + && isPromiseMethodThatUsesValue(node.expression, identifier) ) { - return true; + return true } // (re)assignment changes the runtime value, so if we've not found an @@ -258,83 +256,83 @@ const isValueAwaitedOrReturned = ( // unless we're assigning to the same identifier, in which case // we might be chaining off the existing promise value if ( - isIdentifier(node.expression.left, name) && - getNodeName(node.expression.right)?.startsWith(`${name}.`) && - isPromiseChainCall(node.expression.right) + isIdentifier(node.expression.left, name) + && getNodeName(node.expression.right)?.startsWith(`${name}.`) + && isPromiseChainCall(node.expression.right) ) { - continue; + continue } - break; + break } } if ( - node.type === AST_NODE_TYPES.BlockStatement && - isValueAwaitedOrReturned(identifier, node.body, context) + node.type === AST_NODE_TYPES.BlockStatement + && isValueAwaitedOrReturned(identifier, node.body, context) ) { - return true; + return true } } - return false; -}; + return false +} const findFirstBlockBodyUp = ( node: TSESTree.Node -): TSESTree.BlockStatement["body"] => { - let parent: TSESTree.Node["parent"] = node; +): TSESTree.BlockStatement['body'] => { + let parent: TSESTree.Node['parent'] = node while (parent) { if (parent.type === AST_NODE_TYPES.BlockStatement) { - return parent.body; + return parent.body } - parent = parent.parent; + parent = parent.parent } /* istanbul ignore next */ throw new Error( `Could not find BlockStatement - please file a github issue at https://github.com/vitest-dev/eslint-plugin-vitest` - ); -}; + ) +} const isDirectlyWithinTestCaseCall = ( node: TSESTree.Node, context: TSESLint.RuleContext ): boolean => { - let parent: TSESTree.Node["parent"] = node; + let parent: TSESTree.Node['parent'] = node while (parent) { if (isFunction(parent)) { - parent = parent.parent; + parent = parent.parent return ( - parent?.type === AST_NODE_TYPES.CallExpression && - isTypeOfVitestFnCall(parent, context, ["test"]) - ); + parent?.type === AST_NODE_TYPES.CallExpression + && isTypeOfVitestFnCall(parent, context, ['test']) + ) } - parent = parent.parent; + parent = parent.parent } - return false; -}; + return false +} const isVariableAwaitedOrReturned = ( variable: TSESTree.VariableDeclarator, context: TSESLint.RuleContext ): boolean => { - const body = findFirstBlockBodyUp(variable); + const body = findFirstBlockBodyUp(variable) // it's pretty much impossible for us to track destructuring assignments, // so we return true to bailout gracefully if (!isIdentifier(variable.id)) { - return true; + return true } - return isValueAwaitedOrReturned(variable.id, body, context); -}; + return isValueAwaitedOrReturned(variable.id, body, context) +} export default createEslintRule<[ Partial<{ @@ -348,14 +346,14 @@ export default createEslintRule<[ meta: { docs: { description: - "Require promises that have expectations in their chain to be valid", + 'require promises that have expectations in their chain to be valid' }, messages: { expectInFloatingPromise: - "This promise should either be returned or awaited to ensure the expects in its chain are called", + 'This promise should either be returned or awaited to ensure the expects in its chain are called' }, - type: "suggestion", - schema: [], + type: 'suggestion', + schema: [] }, defaultOptions: [{ alwaysAwait: false, @@ -364,7 +362,7 @@ export default createEslintRule<[ maxArgs: 1 }], create(context) { - let inTestCaseWithDoneCallback = false; + let inTestCaseWithDoneCallback = false // an array of booleans representing each promise chain we enter, with the // boolean value representing if we think a given chain contains an expect // in it's body. @@ -372,109 +370,109 @@ export default createEslintRule<[ // since we only care about the inner-most chain, we represent the state in // reverse with the inner-most being the first item, as that makes it // slightly less code to assign to by not needing to know the length - const chains: boolean[] = []; + const chains: boolean[] = [] return { CallExpression(node: TSESTree.CallExpression) { // there are too many ways that the done argument could be used with // promises that contain expect that would make the promise safe for us if (isTestCaseCallWithCallbackArg(node, context)) { - inTestCaseWithDoneCallback = true; + inTestCaseWithDoneCallback = true - return; + return } // if this call expression is a promise chain, add it to the stack with // value of "false", as we assume there are no expect calls initially if (isPromiseChainCall(node)) { - chains.unshift(false); + chains.unshift(false) - return; + return } // if we're within a promise chain, and this call expression looks like // an expect call, mark the deepest chain as having an expect call if ( - chains.length > 0 && - isTypeOfVitestFnCall(node, context, ["expect"]) + chains.length > 0 + && isTypeOfVitestFnCall(node, context, ['expect']) ) { - chains[0] = true; + chains[0] = true } }, - "CallExpression:exit"(node: TSESTree.CallExpression) { + 'CallExpression:exit'(node: TSESTree.CallExpression) { // there are too many ways that the "done" argument could be used to // make promises containing expects safe in a test for us to be able to // accurately check, so we just bail out completely if it's present if (inTestCaseWithDoneCallback) { - if (isTypeOfVitestFnCall(node, context, ["test"])) { - inTestCaseWithDoneCallback = false; + if (isTypeOfVitestFnCall(node, context, ['test'])) { + inTestCaseWithDoneCallback = false } - return; + return } if (!isPromiseChainCall(node)) { - return; + return } // since we're exiting this call expression (which is a promise chain) // we remove it from the stack of chains, since we're unwinding - const hasExpectCall = chains.shift(); + const hasExpectCall = chains.shift() // if the promise chain we're exiting doesn't contain an expect, // then we don't need to check it for anything if (!hasExpectCall) { - return; + return } - const { parent } = findTopMostCallExpression(node); + const { parent } = findTopMostCallExpression(node) // if we don't have a parent (which is technically impossible at runtime) // or our parent is not directly within the test case, we stop checking // because we're most likely in the body of a function being defined // within the test, which we can't track if (!parent || !isDirectlyWithinTestCaseCall(parent, context)) { - return; + return } switch (parent.type) { case AST_NODE_TYPES.VariableDeclarator: { if (isVariableAwaitedOrReturned(parent, context)) { - return; + return } - break; + break } case AST_NODE_TYPES.AssignmentExpression: { if ( - parent.left.type === AST_NODE_TYPES.Identifier && - isValueAwaitedOrReturned( + parent.left.type === AST_NODE_TYPES.Identifier + && isValueAwaitedOrReturned( parent.left, findFirstBlockBodyUp(parent), context ) ) { - return; + return } - break; + break } case AST_NODE_TYPES.ExpressionStatement: - break; + break case AST_NODE_TYPES.ReturnStatement: case AST_NODE_TYPES.AwaitExpression: default: - return; + return } context.report({ - messageId: "expectInFloatingPromise", - node: parent, - }); - }, - }; - }, -}); + messageId: 'expectInFloatingPromise', + node: parent + }) + } + } + } +}) diff --git a/src/rules/valid-expect.ts b/src/rules/valid-expect.ts index 9fa1e393..873261de 100644 --- a/src/rules/valid-expect.ts +++ b/src/rules/valid-expect.ts @@ -46,19 +46,19 @@ const promiseArrayExceptionKey = ({ start, end }: TSESTree.SourceLocation) => `${start.line}:${start.column}-${end.line}:${end.column}` const getNormalizeFunctionExpression = ( - functionExpression: FunctionExpression, + functionExpression: FunctionExpression ): | TSESTree.PropertyComputedName | TSESTree.PropertyNonComputedName | FunctionExpression => { if ( - functionExpression.parent.type === AST_NODE_TYPES.Property && - functionExpression.type === AST_NODE_TYPES.FunctionExpression + functionExpression.parent.type === AST_NODE_TYPES.Property + && functionExpression.type === AST_NODE_TYPES.FunctionExpression ) - return functionExpression.parent; + return functionExpression.parent - return functionExpression; -}; + return functionExpression +} function getParentIfThenified(node: TSESTree.Node): TSESTree.Node { const grandParentNode = node.parent?.parent @@ -75,29 +75,29 @@ function getParentIfThenified(node: TSESTree.Node): TSESTree.Node { const findPromiseCallExpressionNode = (node: TSESTree.Node) => node.parent?.parent - && [AST_NODE_TYPES.CallExpression, AST_NODE_TYPES.ArrayExpression].includes( - node.parent.type - ) + && [AST_NODE_TYPES.CallExpression, AST_NODE_TYPES.ArrayExpression].includes( + node.parent.type + ) ? getPromiseCallExpressionNode(node.parent) : null const findFirstFunctionExpression = ({ - parent, + parent }: TSESTree.Node): FunctionExpression | null => { if (!parent) - return null; + return null - return isFunction(parent) ? parent : findFirstFunctionExpression(parent); -}; + return isFunction(parent) ? parent : findFirstFunctionExpression(parent) +} const isAcceptableReturnNode = ( node: TSESTree.Node, allowReturn: boolean ): node is - | TSESTree.ConditionalExpression - | TSESTree.ArrowFunctionExpression - | TSESTree.AwaitExpression - | TSESTree.ReturnStatement => { +| TSESTree.ConditionalExpression +| TSESTree.ArrowFunctionExpression +| TSESTree.AwaitExpression +| TSESTree.ReturnStatement => { if (allowReturn && node.type === AST_NODE_TYPES.ReturnStatement) return true @@ -135,7 +135,7 @@ export default createEslintRule<[ 'Promises which return async assertions must be awaited{{orReturned}}' }, type: 'suggestion', - fixable: "code", + fixable: 'code', schema: [ { type: 'object', @@ -170,12 +170,12 @@ export default createEslintRule<[ create: (context, [{ alwaysAwait, asyncMatchers = defaultAsyncMatchers, minArgs = 1, maxArgs = 1 }]) => { const arrayExceptions = new Set() const descriptors: Array<{ - node: TSESTree.Node; + node: TSESTree.Node messageId: Extract< MESSAGE_IDS, 'asyncMustBeAwaited' | 'promisesWithAsyncAssertionsMustBeAwaited' - >; - }> = []; + > + }> = [] const pushPromiseArrayException = (loc: TSESTree.SourceLocation) => arrayExceptions.add(promiseArrayExceptionKey(loc)) @@ -243,7 +243,7 @@ export default createEslintRule<[ } return } - else if (vitestFnCall?.type ==="expectTypeOf" && settings.typecheck){ + else if (vitestFnCall?.type === 'expectTypeOf' && settings.typecheck) { return } else if (vitestFnCall?.type !== 'expect') { @@ -282,12 +282,12 @@ export default createEslintRule<[ // Note: 2nd argument should be string, not a variable in current implementation if (expect.arguments.length === 2) { // expect(value, "string literal") - const isSecondArgString = expect.arguments[1].type === AST_NODE_TYPES.Literal && - typeof expect.arguments[1].value === 'string'; + const isSecondArgString = expect.arguments[1].type === AST_NODE_TYPES.Literal + && typeof expect.arguments[1].value === 'string' // expect(value, `template literal`) - const isSecondArgTemplateLiteral = expect.arguments[1].type === AST_NODE_TYPES.TemplateLiteral; + const isSecondArgTemplateLiteral = expect.arguments[1].type === AST_NODE_TYPES.TemplateLiteral if (isSecondArgString || isSecondArgTemplateLiteral) { - return; + return } } @@ -341,10 +341,10 @@ export default createEslintRule<[ } }, 'Program:exit'() { - const fixes: TSESLint.RuleFix[] = []; + const fixes: TSESLint.RuleFix[] = [] descriptors.forEach(({ node, messageId }, index) => { - const orReturned = alwaysAwait ? '' : ' or returned'; + const orReturned = alwaysAwait ? '' : ' or returned' context.report({ loc: node.loc, @@ -352,41 +352,41 @@ export default createEslintRule<[ messageId, node, fix(fixer) { - const functionExpression = findFirstFunctionExpression(node); + const functionExpression = findFirstFunctionExpression(node) if (!functionExpression) - return null; + return null - const foundAsyncFixer = fixes.some(fix => fix.text === 'async '); + const foundAsyncFixer = fixes.some(fix => fix.text === 'async ') if (!functionExpression.async && !foundAsyncFixer) { - const targetFunction = - getNormalizeFunctionExpression(functionExpression); + const targetFunction + = getNormalizeFunctionExpression(functionExpression) - fixes.push(fixer.insertTextBefore(targetFunction, 'async ')); + fixes.push(fixer.insertTextBefore(targetFunction, 'async ')) } - const returnStatement = - node.parent?.type === AST_NODE_TYPES.ReturnStatement + const returnStatement + = node.parent?.type === AST_NODE_TYPES.ReturnStatement ? node.parent - : null; + : null if (alwaysAwait && returnStatement) { - const sourceCodeText = - context.sourceCode.getText(returnStatement); - const replacedText = sourceCodeText.replace('return', 'await'); + const sourceCodeText + = context.sourceCode.getText(returnStatement) + const replacedText = sourceCodeText.replace('return', 'await') - fixes.push(fixer.replaceText(returnStatement, replacedText)); + fixes.push(fixer.replaceText(returnStatement, replacedText)) } else { - fixes.push(fixer.insertTextBefore(node, 'await ')); + fixes.push(fixer.insertTextBefore(node, 'await ')) } - return index === descriptors.length - 1 ? fixes : null; - }, - }); - }); - }, + return index === descriptors.length - 1 ? fixes : null + } + }) + }) + } } } }) diff --git a/src/rules/valid-title.ts b/src/rules/valid-title.ts index a50df70a..079fdd49 100644 --- a/src/rules/valid-title.ts +++ b/src/rules/valid-title.ts @@ -44,13 +44,13 @@ type Options = { allowArguments?: boolean disallowedWords?: string[] mustNotMatch?: - | Partial> - | MatcherAndMessage - | string + | Partial> + | MatcherAndMessage + | string mustMatch?: - | Partial> - | MatcherAndMessage - | string + | Partial> + | MatcherAndMessage + | string }[] type CompiledMatcherAndMessage = [matcher: RegExp, message?: string] @@ -91,7 +91,7 @@ const compileMatcherPatterns = (matchers: | Partial> | MatcherAndMessage | string): Record & - Record => { + Record => { if (typeof matchers === 'string' || Array.isArray(matchers)) { const compiledMatcher = compileMatcherPattern(matchers) @@ -162,8 +162,8 @@ export default createEslintRule({ MatcherAndMessageSchema, { type: 'object', - //@ts-ignore - propertyNames: { type: "string", enum: ['describe', 'test', 'it'] }, + // @ts-ignore + propertyNames: { type: 'string', enum: ['describe', 'test', 'it'] }, additionalProperties: { oneOf: [{ type: 'string' }, MatcherAndMessageSchema] } @@ -200,13 +200,11 @@ export default createEslintRule({ const [argument] = node.arguments if (settings.typecheck) { - const services = ESLintUtils.getParserServices(context) const type = services.getTypeAtLocation(argument) if (isFunctionType(type) || isClassType(type)) return - } if (!argument || (allowArguments && argument.type === AST_NODE_TYPES.Identifier)) return diff --git a/src/utils/ast-utils.ts b/src/utils/ast-utils.ts index 8a3f1444..83ca10d5 100644 --- a/src/utils/ast-utils.ts +++ b/src/utils/ast-utils.ts @@ -1,20 +1,19 @@ -import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESLint, TSESTree } from "@typescript-eslint/utils"; -import { createRequire } from "node:module" +import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils' +import { createRequire } from 'node:module' import { MaybeTypeCast, TSTypeCastExpression } from './types' const require = createRequire(import.meta.url) -const eslintRequire = createRequire(require.resolve("eslint")) - -export const espreeParser = eslintRequire.resolve('espree'); +const eslintRequire = createRequire(require.resolve('eslint')) +export const espreeParser = eslintRequire.resolve('espree') // We'll only verify nodes with these parent types const STATEMENT_LIST_PARENTS = new Set([ AST_NODE_TYPES.Program, AST_NODE_TYPES.BlockStatement, AST_NODE_TYPES.SwitchCase, - AST_NODE_TYPES.SwitchStatement, -]); + AST_NODE_TYPES.SwitchStatement +]) export const isValidParent = (parentType: AST_NODE_TYPES): boolean => { return STATEMENT_LIST_PARENTS.has(parentType) @@ -23,7 +22,6 @@ export const isValidParent = (parentType: AST_NODE_TYPES): boolean => { export const isTokenASemicolon = (token: TSESTree.Token): boolean => token.value === ';' && token.type === AST_TOKEN_TYPES.Punctuator - /** * Gets the actual last token. * @@ -34,22 +32,20 @@ export const isTokenASemicolon = (token: TSESTree.Token): boolean => * ;[1, 2, 3].forEach(bar) */ export const getActualLastToken = (sourceCode: TSESLint.SourceCode, node: TSESTree.Node): TSESTree.Token => { - - const semiToken = sourceCode.getLastToken(node)!; - const prevToken = sourceCode.getTokenBefore(semiToken)!; + const semiToken = sourceCode.getLastToken(node)! + const prevToken = sourceCode.getTokenBefore(semiToken)! const nextToken = sourceCode.getTokenAfter(semiToken) const isSemicolonLessStyle = Boolean( - prevToken && - nextToken && - prevToken.range[0] >= node.range[0] && - isTokenASemicolon(semiToken) && - semiToken.loc.start.line !== prevToken.loc.end.line && - semiToken.loc.end.line === nextToken.loc.start.line, - ); - - return isSemicolonLessStyle ? prevToken : semiToken; - + prevToken + && nextToken + && prevToken.range[0] >= node.range[0] + && isTokenASemicolon(semiToken) + && semiToken.loc.start.line !== prevToken.loc.end.line + && semiToken.loc.end.line === nextToken.loc.start.line + ) + + return isSemicolonLessStyle ? prevToken : semiToken } export const getPaddingLineSequences = (prevNode: TSESTree.Node, nextNode: TSESTree.Node, sourceCode: TSESLint.SourceCode) => { @@ -73,17 +69,16 @@ export const getPaddingLineSequences = (prevNode: TSESTree.Node, nextNode: TSEST return pairs } - export const areTokensOnSameLine = ( left: TSESTree.Node | TSESTree.Token, - right: TSESTree.Node | TSESTree.Token, -): boolean => left.loc.end.line === right.loc.start.line; + right: TSESTree.Node | TSESTree.Token +): boolean => left.loc.end.line === right.loc.start.line const isTypeCastExpression = ( node: MaybeTypeCast ): node is TSTypeCastExpression => - node.type === AST_NODE_TYPES.TSAsExpression || - node.type === AST_NODE_TYPES.TSTypeAssertion; + node.type === AST_NODE_TYPES.TSAsExpression + || node.type === AST_NODE_TYPES.TSTypeAssertion export const followTypeAssertionChain = < Expression extends TSESTree.Expression @@ -92,4 +87,4 @@ export const followTypeAssertionChain = < ): Expression => isTypeCastExpression(expression) ? followTypeAssertionChain(expression.expression) - : expression; + : expression diff --git a/src/utils/index.ts b/src/utils/index.ts index 0fe16473..7762b075 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -13,7 +13,7 @@ import { import { Rule } from 'eslint' interface PluginDocs { - recommended?: boolean, + recommended?: boolean requiresTypeChecking?: boolean } diff --git a/src/utils/msc.ts b/src/utils/msc.ts index edf702b8..c7ef39f5 100644 --- a/src/utils/msc.ts +++ b/src/utils/msc.ts @@ -2,8 +2,8 @@ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils' import { getFirstMatcherArg, ParsedExpectVitestFnCall } from './parse-vitest-fn-call' import { EqualityMatcher } from './types' import { getAccessorValue, isSupportedAccessor } from '.' -import { basename, parse } from "node:path"; -import { fileURLToPath } from 'node:url'; +import { basename, parse } from 'node:path' +import { fileURLToPath } from 'node:url' export const isBooleanLiteral = (node: TSESTree.Node): node is TSESTree.BooleanLiteral => node.type === AST_NODE_TYPES.Literal && typeof node.value === 'boolean' diff --git a/src/utils/padding.ts b/src/utils/padding.ts index 2724f234..58b32288 100644 --- a/src/utils/padding.ts +++ b/src/utils/padding.ts @@ -1,9 +1,9 @@ -//Imported from https://github.com/dangreenisrael/eslint-plugin-jest-formatting/blob/master/src/rules/padding.ts -//Original license: https://github.com/dangreenisrael/eslint-plugin-jest-formatting/blob/master/LICENSE +// Imported from https://github.com/dangreenisrael/eslint-plugin-jest-formatting/blob/master/src/rules/padding.ts +// Original license: https://github.com/dangreenisrael/eslint-plugin-jest-formatting/blob/master/LICENSE -import { createEslintRule } from "." -import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESLint, TSESTree } from "@typescript-eslint/utils"; -import * as astUtils from "./ast-utils" +import { createEslintRule } from '.' +import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils' +import * as astUtils from './ast-utils' export const enum PaddingType { Any, @@ -25,40 +25,40 @@ export const enum StatementType { TestToken, XdescribeToken, XitToken, - XtestToken, + XtestToken } export interface Config { - paddingType: PaddingType, - prevStatementType: StatementType | StatementType[], + paddingType: PaddingType + prevStatementType: StatementType | StatementType[] nextStatementType: StatementType | StatementType[] } interface ScopeInfo { - prevNode: TSESTree.Node | null; - enter: () => void; - exit: () => void; + prevNode: TSESTree.Node | null + enter: () => void + exit: () => void } // Tracks position in scope and prevNode. Used to compare current and prev node // and then to walk back up to the parent scope or down into the next one. // And so on... interface Scope { - upper: Scope | null; - prevNode: TSESTree.Node | null; + upper: Scope | null + prevNode: TSESTree.Node | null } type PaddingTester = ( prevNode: TSESTree.Node, nextNode: TSESTree.Node, paddingContext: PaddingContext, -) => void; +) => void interface PaddingContext { - ruleContext: TSESLint.RuleContext<'missingPadding', unknown[]>; - sourceCode: TSESLint.SourceCode; - scopeInfo: ScopeInfo; - configs: Config[]; + ruleContext: TSESLint.RuleContext<'missingPadding', unknown[]> + sourceCode: TSESLint.SourceCode + scopeInfo: ScopeInfo + configs: Config[] } const paddingAlwaysTester = (prevNode: TSESTree.Node, nextNode: TSESTree.Node, paddingContext: PaddingContext): void => { @@ -68,10 +68,9 @@ const paddingAlwaysTester = (prevNode: TSESTree.Node, nextNode: TSESTree.Node, p if (paddingLines.length > 0) return - ruleContext.report({ node: nextNode, - messageId: "missingPadding", + messageId: 'missingPadding', fix(fixer: TSESLint.RuleFixer) { let prevToken = astUtils.getActualLastToken(sourceCode, prevNode) const nextToken = (sourceCode.getFirstTokenBetween(prevToken, nextNode, { @@ -114,9 +113,8 @@ const paddingAlwaysTester = (prevNode: TSESTree.Node, nextNode: TSESTree.Node, p // A mapping of PaddingType to PaddingTester const paddingTesters: { [T in PaddingType]: PaddingTester } = { [PaddingType.Any]: () => true, - [PaddingType.Always]: paddingAlwaysTester, -}; - + [PaddingType.Always]: paddingAlwaysTester +} const createScopeInfo = (): ScopeInfo => { let scope: Scope | null = null @@ -126,7 +124,7 @@ const createScopeInfo = (): ScopeInfo => { return scope!.prevNode }, set prevNode(node) { - scope!.prevNode = node; + scope!.prevNode = node }, enter() { scope = { upper: scope, prevNode: null } @@ -137,35 +135,33 @@ const createScopeInfo = (): ScopeInfo => { } } - const createTokenTester = (tokenName: string): StatementTester => { return (node: TSESTree.Node, sourceCode: TSESLint.SourceCode): boolean => { - let activeNode = node; + let activeNode = node if (activeNode.type === AST_NODE_TYPES.ExpressionStatement) { // In the case of `await`, we actually care about its argument if (activeNode.expression.type === AST_NODE_TYPES.AwaitExpression) { - activeNode = activeNode.expression.argument; + activeNode = activeNode.expression.argument } - const token = sourceCode.getFirstToken(activeNode); + const token = sourceCode.getFirstToken(activeNode) return ( token?.type === AST_TOKEN_TYPES.Identifier && token.value === tokenName - ); + ) } - return false; - }; -}; - + return false + } +} type StatementTester = ( node: TSESTree.Node, sourceCode: TSESLint.SourceCode, -) => boolean; +) => boolean -type StatementTypes = StatementType | StatementType[]; +type StatementTypes = StatementType | StatementType[] // A mapping of StatementType to StatementTester for... testing statements const statementTesters: { [T in StatementType]: StatementTester } = { @@ -183,8 +179,8 @@ const statementTesters: { [T in StatementType]: StatementTester } = { [StatementType.TestToken]: createTokenTester('test'), [StatementType.XdescribeToken]: createTokenTester('xdescribe'), [StatementType.XitToken]: createTokenTester('xit'), - [StatementType.XtestToken]: createTokenTester('xtest'), -}; + [StatementType.XtestToken]: createTokenTester('xtest') +} /** * Check whether the given node matches the statement type @@ -192,35 +188,34 @@ const statementTesters: { [T in StatementType]: StatementTester } = { const nodeMatchesType = ( node: TSESTree.Node, statementType: StatementTypes, - paddingContext: PaddingContext, + paddingContext: PaddingContext ): boolean => { - let innerStatementNode = node; - const { sourceCode } = paddingContext; + let innerStatementNode = node + const { sourceCode } = paddingContext // Dig into LabeledStatement body until it's not that anymore while (innerStatementNode.type === AST_NODE_TYPES.LabeledStatement) { - innerStatementNode = innerStatementNode.body; + innerStatementNode = innerStatementNode.body } // If it's an array recursively check if any of the statement types match // the node if (Array.isArray(statementType)) { return statementType.some(type => - nodeMatchesType(innerStatementNode, type, paddingContext), - ); + nodeMatchesType(innerStatementNode, type, paddingContext) + ) } - return statementTesters[statementType](innerStatementNode, sourceCode); -}; + return statementTesters[statementType](innerStatementNode, sourceCode) +} const testPadding = (prevNode: TSESTree.Node, nextNode: TSESTree.Node, paddingContext: PaddingContext): void => { const { configs } = paddingContext const testType = (type: PaddingType) => paddingTesters[type](prevNode, nextNode, paddingContext) - for (let i = configs.length - 1; i >= 0; --i) { - const { prevStatementType: prevType, nextStatementType: nextType, paddingType } = configs[i]; + const { prevStatementType: prevType, nextStatementType: nextType, paddingType } = configs[i] if (nodeMatchesType(prevNode, prevType, paddingContext) && nodeMatchesType(nextNode, nextType, paddingContext)) { return testType(paddingType) @@ -247,7 +242,6 @@ const verifyNode = (node: TSESTree.Node, paddingContext: PaddingContext): void = scopeInfo.prevNode = node } - /** * Creates an ESLint rule for a given set of padding Config objects. * @@ -297,14 +291,14 @@ export const createPaddingRule = (name: string, description: string, configs: Co configs } - const { scopeInfo } = paddingContext; + const { scopeInfo } = paddingContext return { - Program: scopeInfo.enter, + 'Program': scopeInfo.enter, 'Program:exit': scopeInfo.exit, - BlockStatement: scopeInfo.enter, + 'BlockStatement': scopeInfo.enter, 'BlockStatement:exit': scopeInfo.exit, - SwitchStatement: scopeInfo.enter, + 'SwitchStatement': scopeInfo.enter, 'SwitchStatement:exit': scopeInfo.exit, ':statement': (node: TSESTree.Node) => verifyNode(node, paddingContext), SwitchCase(node: TSESTree.Node) { diff --git a/src/utils/parse-vitest-fn-call.ts b/src/utils/parse-vitest-fn-call.ts index 5b15aa89..0d43b79f 100644 --- a/src/utils/parse-vitest-fn-call.ts +++ b/src/utils/parse-vitest-fn-call.ts @@ -252,7 +252,7 @@ const parseVitestFnCallWithReasonInner = ( const links = [name, ...rest.map(getAccessorValue)] - if (resolved.type !== "testContext" && name !== 'vi' && name !== 'expect' && name !== 'expectTypeOf' && !ValidVitestFnCallChains.has(links.join('.'))) + if (resolved.type !== 'testContext' && name !== 'vi' && name !== 'expect' && name !== 'expectTypeOf' && !ValidVitestFnCallChains.has(links.join('.'))) return null const parsedVitestFnCall: Omit = { @@ -322,11 +322,11 @@ const resolveVitestFn = ( if (maybeImport === 'local') return null - if (maybeImport === "testContext") + if (maybeImport === 'testContext') return { local: identifier, original: null, - type: "testContext" + type: 'testContext' } if (maybeImport) { @@ -374,17 +374,17 @@ export const resolveScope = ( if (ref && ref.defs.length > 0) { const def = ref.defs[ref.defs.length - 1] - const objectParam = isFunction(def.node) ? def.node.params.find(params => params.type === AST_NODE_TYPES.ObjectPattern ) : undefined + const objectParam = isFunction(def.node) ? def.node.params.find(params => params.type === AST_NODE_TYPES.ObjectPattern) : undefined if (objectParam) { const property = objectParam.properties.find(property => property.type === AST_NODE_TYPES.Property) const key = property?.key.type === AST_NODE_TYPES.Identifier ? property.key : undefined if (key?.name === identifier) - return "testContext" + return 'testContext' } - const namedParam = isFunction(def.node) ? def.node.params.find(params => params.type === AST_NODE_TYPES.Identifier ) : undefined + const namedParam = isFunction(def.node) ? def.node.params.find(params => params.type === AST_NODE_TYPES.Identifier) : undefined if (namedParam) - return "testContext" + return 'testContext' const importDetails = describePossibleImportDef(def) @@ -537,5 +537,5 @@ const isTypeCastExpression = ( export const followTypeAssertionChain = ( expression: MaybeTypeCast ): Expression => isTypeCastExpression(expression) - ? followTypeAssertionChain(expression.expression) - : expression + ? followTypeAssertionChain(expression.expression) + : expression diff --git a/src/utils/types.ts b/src/utils/types.ts index 69941684..22cdde37 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -41,7 +41,7 @@ export enum ModifierName { * Represents a `CallExpression` with a single argument. */ export interface CallExpressionWithSingleArgument< - Argument extends TSESTree.CallExpression['arguments'][number] = TSESTree.CallExpression['arguments'][number] + Argument extends TSESTree.CallExpression['arguments'][number] = TSESTree.CallExpression['arguments'][number] > extends TSESTree.CallExpression { arguments: [Argument] } @@ -54,20 +54,20 @@ export enum EqualityMatcher { export type MaybeTypeCast = | TSTypeCastExpression - | Expression; + | Expression export type TSTypeCastExpression< Expression extends TSESTree.Expression = TSESTree.Expression -> = AsExpressionChain | TypeAssertionChain; +> = AsExpressionChain | TypeAssertionChain interface AsExpressionChain< Expression extends TSESTree.Expression = TSESTree.Expression > extends TSESTree.TSAsExpression { - expression: AsExpressionChain | Expression; + expression: AsExpressionChain | Expression } interface TypeAssertionChain< Expression extends TSESTree.Expression = TSESTree.Expression > extends TSESTree.TSTypeAssertion { - expression: TypeAssertionChain | Expression; + expression: TypeAssertionChain | Expression } diff --git a/tests/consistent-test-it.test.ts b/tests/consistent-test-it.test.ts index e4e52aeb..2eec85c9 100644 --- a/tests/consistent-test-it.test.ts +++ b/tests/consistent-test-it.test.ts @@ -28,7 +28,7 @@ ruleTester.run(RULE_NAME, rule, { fibonacci(10); })`, options: [{ fn: TestCaseName.it }] - }, + } ], invalid: [ { diff --git a/tests/expect-expect.test.ts b/tests/expect-expect.test.ts index fe830e7e..f3f7fef4 100644 --- a/tests/expect-expect.test.ts +++ b/tests/expect-expect.test.ts @@ -16,13 +16,13 @@ ruleTester.run(RULE_NAME, rule, { assert('foo' !== 'bar', 'foo should not be equal to bar') })`, `test('cleanPrCommitTitle', () => { - const clean = 'Something done'; - assert.equal(cleanPrCommitTitle('Something done (#123)', 123), clean); - assert.equal(cleanPrCommitTitle(' Something done (#123) ', 123), clean); - assert.equal(cleanPrCommitTitle(' Something done ', 123), clean); + const clean = 'Something done'; + assert.equal(cleanPrCommitTitle('Something done (#123)', 123), clean); + assert.equal(cleanPrCommitTitle(' Something done (#123) ', 123), clean); + assert.equal(cleanPrCommitTitle(' Something done ', 123), clean); - assert.notEqual(cleanPrCommitTitle('Something done (fixes #123)', 123), clean); - assert.notEqual(cleanPrCommitTitle('Something done (#23454)', 123), clean); + assert.notEqual(cleanPrCommitTitle('Something done (fixes #123)', 123), clean); + assert.notEqual(cleanPrCommitTitle('Something done (#23454)', 123), clean); });`, `import { it as base } from 'vitest' diff --git a/tests/max-expects.test.ts b/tests/max-expects.test.ts index 04bba5c2..e3763669 100644 --- a/tests/max-expects.test.ts +++ b/tests/max-expects.test.ts @@ -6,21 +6,21 @@ ruleTester.run(RULE_NAME, rule, { 'test(\'should pass\')', 'test(\'should pass\', () => {})', 'test.skip(\'should pass\', () => {})', - `test('should pass', () => { + `test('should pass', () => { expect(true).toBeDefined(); expect(true).toBeDefined(); expect(true).toBeDefined(); expect(true).toBeDefined(); expect(true).toBeDefined(); });`, - `test('should pass', () => { + `test('should pass', () => { expect(true).toBeDefined(); expect(true).toBeDefined(); expect(true).toBeDefined(); expect(true).toBeDefined(); expect(true).toBeDefined(); });`, - ` test('should pass', async () => { + ` test('should pass', async () => { expect.hasAssertions(); expect(true).toBeDefined(); diff --git a/tests/max-nested-describe.test.ts b/tests/max-nested-describe.test.ts index b8618c43..0c27d6ac 100644 --- a/tests/max-nested-describe.test.ts +++ b/tests/max-nested-describe.test.ts @@ -2,7 +2,7 @@ import rule, { RULE_NAME } from '../src/rules/max-nested-describe' import { ruleTester } from './ruleTester' const valid = [ - `describe('another suite', () => { + `describe('another suite', () => { describe('another suite', () => { it('skipped test', () => { // Test skipped, as tests are running in Only mode @@ -15,7 +15,7 @@ const valid = [ }) }) })`, - `describe('another suite', () => { + `describe('another suite', () => { describe('another suite', () => { describe('another suite', () => { describe('another suite', () => { @@ -27,7 +27,7 @@ const valid = [ ] const invalid = [ - `describe('another suite', () => { + `describe('another suite', () => { describe('another suite', () => { describe('another suite', () => { describe('another suite', () => { @@ -40,7 +40,7 @@ const invalid = [ }) }) })`, - `describe('another suite', () => { + `describe('another suite', () => { describe('another suite', () => { describe('another suite', () => { describe('another suite', () => { @@ -64,9 +64,9 @@ const invalid = [ ] ruleTester.run(RULE_NAME, rule, { - valid, - invalid: invalid.map(i => ({ - code: i, - errors: [{ messageId: 'maxNestedDescribe' }] - })) + valid, + invalid: invalid.map(i => ({ + code: i, + errors: [{ messageId: 'maxNestedDescribe' }] + })) }) diff --git a/tests/no-conditional-in-test.test.ts b/tests/no-conditional-in-test.test.ts index 76946096..8e168629 100644 --- a/tests/no-conditional-in-test.test.ts +++ b/tests/no-conditional-in-test.test.ts @@ -4,13 +4,13 @@ import { ruleTester } from './ruleTester' ruleTester.run(`${RULE_NAME}-conditional expressions`, rule, { valid: [ 'const x = y ? 1 : 0', - `const foo = function (bar) { + `const foo = function (bar) { return foo ? bar : null; }; it('foo', () => { foo(); });`, - `it.concurrent('foo', () => { + `it.concurrent('foo', () => { switch('bar') {} })` ], @@ -34,12 +34,12 @@ ruleTester.run(`${RULE_NAME}-if statements`, rule, { 'it(\'foo\', () => {})', 'it("foo", function () {})', 'it(\'foo\', () => {}); function myTest() { if (\'bar\') {} }', - `describe.each\`\`('foo', () => { + `describe.each\`\`('foo', () => { afterEach(() => { if ('bar') {} }); })`, - `const values = something.map((thing) => { + `const values = something.map((thing) => { if (thing.isFoo) { return thing.foo } else { diff --git a/tests/no-conditional-tests.test.ts b/tests/no-conditional-tests.test.ts index 3ab169eb..95d912e1 100644 --- a/tests/no-conditional-tests.test.ts +++ b/tests/no-conditional-tests.test.ts @@ -6,7 +6,7 @@ ruleTester.run(RULE_NAME, rule, { 'test("shows error", () => {});', 'it("foo", function () {})', 'it(\'foo\', () => {}); function myTest() { if (\'bar\') {} }', - `function myFunc(str: string) { + `function myFunc(str: string) { return str; } describe("myTest", () => { @@ -16,7 +16,7 @@ ruleTester.run(RULE_NAME, rule, { ).toEqual("5"); }); });`, - `describe("shows error", () => { + `describe("shows error", () => { if (1 === 2) { myFunc(); } diff --git a/tests/no-done-callback.test.ts b/tests/no-done-callback.test.ts index f3ee44c7..e3f591ba 100644 --- a/tests/no-done-callback.test.ts +++ b/tests/no-done-callback.test.ts @@ -103,7 +103,7 @@ ruleTester.run(RULE_NAME, rule, { 'test.each``("something", () => {return new Promise(done => { done(); })})' } ] - }, + } ] }, { diff --git a/tests/no-focused-tests.test.ts b/tests/no-focused-tests.test.ts index bfd04de5..47c39a9e 100644 --- a/tests/no-focused-tests.test.ts +++ b/tests/no-focused-tests.test.ts @@ -14,7 +14,7 @@ ruleTester.run(RULE_NAME, rule, { line: 1, messageId: 'noFocusedTests' } - ], + ] }, { options: [{ @@ -29,7 +29,7 @@ ruleTester.run(RULE_NAME, rule, { line: 1, messageId: 'noFocusedTests' } - ], + ] }, { options: [{ @@ -44,7 +44,7 @@ ruleTester.run(RULE_NAME, rule, { line: 1, messageId: 'noFocusedTests' } - ], + ] }, { options: [{ @@ -59,7 +59,7 @@ ruleTester.run(RULE_NAME, rule, { line: 1, messageId: 'noFocusedTests' } - ], + ] }, { options: [{ @@ -74,7 +74,7 @@ ruleTester.run(RULE_NAME, rule, { line: 1, messageId: 'noFocusedTests' } - ], + ] }, { options: [{ @@ -89,7 +89,7 @@ ruleTester.run(RULE_NAME, rule, { line: 1, messageId: 'noFocusedTests' } - ], + ] } ] }) diff --git a/tests/no-identical-title.test.ts b/tests/no-identical-title.test.ts index fb753524..9eee94bb 100644 --- a/tests/no-identical-title.test.ts +++ b/tests/no-identical-title.test.ts @@ -3,7 +3,7 @@ import { ruleTester } from './ruleTester' ruleTester.run(RULE_NAME, rule, { valid: [ - `suite('parent', () => { + `suite('parent', () => { suite('child 1', () => { test('grand child 1', () => {}) }) @@ -11,9 +11,9 @@ ruleTester.run(RULE_NAME, rule, { test('grand child 1', () => {}) }) })`, - 'it(); it();', - 'test("two", () => {});', - `fdescribe('a describe', () => { + 'it(); it();', + 'test("two", () => {});', + `fdescribe('a describe', () => { test('a test', () => { expect(true).toBe(true); }); @@ -23,7 +23,7 @@ ruleTester.run(RULE_NAME, rule, { expect(true).toBe(true); }); });`, - ` + ` suite('parent', () => { suite('child 1', () => { test('grand child 1', () => {}) diff --git a/tests/no-large-snapshots.test.ts b/tests/no-large-snapshots.test.ts index 2728357a..d37985aa 100644 --- a/tests/no-large-snapshots.test.ts +++ b/tests/no-large-snapshots.test.ts @@ -41,7 +41,7 @@ ruleTester.run(RULE_NAME, rule, { maxSize: 61 } ] - }, + } ], invalid: [ { @@ -80,6 +80,6 @@ ruleTester.run(RULE_NAME, rule, { data: { lineLimit: 50, lineCount: 51 } } ] - }, + } ] }) diff --git a/tests/padding-around-after-all-blocks.test.ts b/tests/padding-around-after-all-blocks.test.ts index 3117ab35..83e4175b 100644 --- a/tests/padding-around-after-all-blocks.test.ts +++ b/tests/padding-around-after-all-blocks.test.ts @@ -1,6 +1,6 @@ -import { ruleTester } from "./ruleTester" -import rule, { RULE_NAME } from "../src/rules/padding-around-after-all-blocks" -import { InvalidTestCase } from "@typescript-eslint/rule-tester" +import { ruleTester } from './ruleTester' +import rule, { RULE_NAME } from '../src/rules/padding-around-after-all-blocks' +import { InvalidTestCase } from '@typescript-eslint/rule-tester' const testCase = { code: ` @@ -56,30 +56,30 @@ describe('someText', () => { { messageId: 'missingPadding', line: 3, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 5, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 8, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 11, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 18, - column: 3, - }, - ], -} satisfies InvalidTestCase<'missingPadding', never>; + column: 3 + } + ] +} satisfies InvalidTestCase<'missingPadding', never> ruleTester.run(RULE_NAME, rule, { valid: [testCase.output], diff --git a/tests/padding-around-after-each-blocks.test.ts b/tests/padding-around-after-each-blocks.test.ts index 10a7e727..b29b81a1 100644 --- a/tests/padding-around-after-each-blocks.test.ts +++ b/tests/padding-around-after-each-blocks.test.ts @@ -1,7 +1,6 @@ - -import type { TSESLint } from '@typescript-eslint/utils'; -import rule, { RULE_NAME } from '../src/rules/padding-around-after-each-blocks'; -import { ruleTester } from './ruleTester'; +import type { TSESLint } from '@typescript-eslint/utils' +import rule, { RULE_NAME } from '../src/rules/padding-around-after-each-blocks' +import { ruleTester } from './ruleTester' const testCase = { code: ` @@ -55,34 +54,34 @@ describe('someText', () => { { messageId: 'missingPadding', line: 3, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 5, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 8, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 11, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 17, - column: 3, - }, - ], -} satisfies TSESLint.InvalidTestCase<'missingPadding', never>; + column: 3 + } + ] +} satisfies TSESLint.InvalidTestCase<'missingPadding', never> ruleTester.run(RULE_NAME, rule, { valid: [testCase.output], invalid: ['src/component.test.jsx', 'src/component.test.js'].map( - filename => ({ ...testCase, filename }), - ), -}); + filename => ({ ...testCase, filename }) + ) +}) diff --git a/tests/padding-around-all.test.ts b/tests/padding-around-all.test.ts index e97198df..ed14f1c7 100644 --- a/tests/padding-around-all.test.ts +++ b/tests/padding-around-all.test.ts @@ -1,6 +1,6 @@ -import rule, { RULE_NAME } from '../src/rules/padding-around-all'; -import { ruleTester } from './ruleTester'; -import { InvalidTestCase } from "@typescript-eslint/rule-tester" +import rule, { RULE_NAME } from '../src/rules/padding-around-all' +import { ruleTester } from './ruleTester' +import { InvalidTestCase } from '@typescript-eslint/rule-tester' const testCase = { code: ` @@ -56,30 +56,30 @@ describe('someText', () => { { messageId: 'missingPadding', line: 3, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 5, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 8, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 11, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 18, - column: 3, - }, - ], -} satisfies InvalidTestCase<'missingPadding', never>; + column: 3 + } + ] +} satisfies InvalidTestCase<'missingPadding', never> ruleTester.run(RULE_NAME, rule, { valid: [ @@ -87,7 +87,7 @@ ruleTester.run(RULE_NAME, rule, { ` xyz: afterEach(() => {}); - `, + ` ], invalid: [ { @@ -106,9 +106,9 @@ ruleTester.run(RULE_NAME, rule, { { messageId: 'missingPadding', line: 3, - column: 9, - }, - ], + column: 9 + } + ] }, { code: ` @@ -162,37 +162,37 @@ ruleTester.run(RULE_NAME, rule, { line: 3, column: 9, endLine: 3, - endColumn: 30, + endColumn: 30 }, { messageId: 'missingPadding', line: 4, column: 9, endLine: 19, - endColumn: 12, + endColumn: 12 }, { messageId: 'missingPadding', line: 8, column: 15, endLine: 8, - endColumn: 21, + endColumn: 21 }, { messageId: 'missingPadding', line: 12, column: 15, endLine: 12, - endColumn: 33, + endColumn: 33 }, { messageId: 'missingPadding', line: 13, column: 15, endLine: 13, - endColumn: 69, - }, - ], - }, - ], -}); + endColumn: 69 + } + ] + } + ] +}) diff --git a/tests/padding-around-before-all-blocks.test.ts b/tests/padding-around-before-all-blocks.test.ts index 4a669550..4720ccb0 100644 --- a/tests/padding-around-before-all-blocks.test.ts +++ b/tests/padding-around-before-all-blocks.test.ts @@ -1,7 +1,6 @@ - -import type { TSESLint } from '@typescript-eslint/utils'; -import rule, { RULE_NAME } from '../src/rules/padding-around-before-all-blocks'; -import { ruleTester } from './ruleTester'; +import type { TSESLint } from '@typescript-eslint/utils' +import rule, { RULE_NAME } from '../src/rules/padding-around-before-all-blocks' +import { ruleTester } from './ruleTester' const testCase = { code: ` @@ -57,34 +56,34 @@ describe('someText', () => { { messageId: 'missingPadding', line: 3, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 5, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 8, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 11, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 18, - column: 3, - }, - ], -} satisfies TSESLint.InvalidTestCase<'missingPadding', never>; + column: 3 + } + ] +} satisfies TSESLint.InvalidTestCase<'missingPadding', never> ruleTester.run(RULE_NAME, rule, { valid: [testCase.output], invalid: ['src/component.test.jsx', 'src/component.test.js'].map( - filename => ({ ...testCase, filename }), - ), -}); + filename => ({ ...testCase, filename }) + ) +}) diff --git a/tests/padding-around-before-each-blocks.test.ts b/tests/padding-around-before-each-blocks.test.ts index 497a12fb..edf70b4c 100644 --- a/tests/padding-around-before-each-blocks.test.ts +++ b/tests/padding-around-before-each-blocks.test.ts @@ -1,7 +1,6 @@ - -import type { TSESLint } from '@typescript-eslint/utils'; -import rule, { RULE_NAME } from '../src/rules/padding-around-before-each-blocks'; -import { ruleTester } from './ruleTester'; +import type { TSESLint } from '@typescript-eslint/utils' +import rule, { RULE_NAME } from '../src/rules/padding-around-before-each-blocks' +import { ruleTester } from './ruleTester' const testCase = { code: ` @@ -57,34 +56,34 @@ describe('someText', () => { { messageId: 'missingPadding', line: 3, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 5, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 8, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 11, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 18, - column: 3, - }, - ], -} satisfies TSESLint.InvalidTestCase<'missingPadding', never>; + column: 3 + } + ] +} satisfies TSESLint.InvalidTestCase<'missingPadding', never> ruleTester.run(RULE_NAME, rule, { valid: [testCase.output], invalid: ['src/component.test.jsx', 'src/component.test.js'].map( - filename => ({ ...testCase, filename }), - ), -}); + filename => ({ ...testCase, filename }) + ) +}) diff --git a/tests/padding-around-describe-blocks.test.ts b/tests/padding-around-describe-blocks.test.ts index 4116e763..25ef9b44 100644 --- a/tests/padding-around-describe-blocks.test.ts +++ b/tests/padding-around-describe-blocks.test.ts @@ -1,6 +1,6 @@ -import type { TSESLint } from '@typescript-eslint/utils'; -import rule, { RULE_NAME } from '../src/rules/padding-around-describe-blocks'; -import { ruleTester } from './ruleTester'; +import type { TSESLint } from '@typescript-eslint/utils' +import rule, { RULE_NAME } from '../src/rules/padding-around-describe-blocks' +import { ruleTester } from './ruleTester' const testCase = { code: ` @@ -78,49 +78,49 @@ describe { messageId: 'missingPadding', line: 11, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 14, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 17, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 21, - column: 5, + column: 5 }, { messageId: 'missingPadding', line: 24, - column: 4, + column: 4 }, { messageId: 'missingPadding', line: 25, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 26, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 27, - column: 1, - }, - ], -} satisfies TSESLint.InvalidTestCase<'missingPadding', never>; + column: 1 + } + ] +} satisfies TSESLint.InvalidTestCase<'missingPadding', never> ruleTester.run(RULE_NAME, rule, { valid: [testCase.output], invalid: ['src/component.test.jsx', 'src/component.test.js'].map( - filename => ({ ...testCase, filename }), - ), -}); + filename => ({ ...testCase, filename }) + ) +}) diff --git a/tests/padding-around-expect-groups.test.ts b/tests/padding-around-expect-groups.test.ts index f7753797..e8f1c693 100644 --- a/tests/padding-around-expect-groups.test.ts +++ b/tests/padding-around-expect-groups.test.ts @@ -1,7 +1,6 @@ - -import rule, { RULE_NAME } from '../src/rules/padding-around-expect-groups'; -import { ruleTester } from './ruleTester'; -import { InvalidTestCase } from "@typescript-eslint/rule-tester" +import rule, { RULE_NAME } from '../src/rules/padding-around-expect-groups' +import { ruleTester } from './ruleTester' +import { InvalidTestCase } from '@typescript-eslint/rule-tester' const testCase = { code: ` @@ -157,74 +156,74 @@ test('expectTypeOf test', () => { { messageId: 'missingPadding', line: 13, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 15, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 16, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 21, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 24, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 32, - column: 7, + column: 7 }, { messageId: 'missingPadding', line: 43, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 47, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 51, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 56, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 61, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 63, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 65, - column: 3, - }, - ], -} satisfies InvalidTestCase<'missingPadding', never>; + column: 3 + } + ] +} satisfies InvalidTestCase<'missingPadding', never> ruleTester.run(RULE_NAME, rule, { valid: [testCase.output], invalid: ['src/component.test.jsx', 'src/component.test.js'].map( - filename => ({ ...testCase, filename }), - ), -}); + filename => ({ ...testCase, filename }) + ) +}) diff --git a/tests/padding-around-test-blocks.test.ts b/tests/padding-around-test-blocks.test.ts index 8a2c424d..3eef726c 100644 --- a/tests/padding-around-test-blocks.test.ts +++ b/tests/padding-around-test-blocks.test.ts @@ -1,6 +1,6 @@ -import type { TSESLint } from '@typescript-eslint/utils'; -import rule from '../src/rules/padding-around-test-blocks'; -import { ruleTester } from './ruleTester'; +import type { TSESLint } from '@typescript-eslint/utils' +import rule from '../src/rules/padding-around-test-blocks' +import { ruleTester } from './ruleTester' const testCase = { code: ` @@ -73,65 +73,64 @@ xit('bar foo', () => {}); { messageId: 'missingPadding', line: 4, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 7, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 10, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 11, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 16, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 19, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 21, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 22, - column: 3, + column: 3 }, { messageId: 'missingPadding', line: 23, - column: 4, + column: 4 }, { messageId: 'missingPadding', line: 24, - column: 1, + column: 1 }, { messageId: 'missingPadding', line: 26, - column: 1, - }, - ], -} satisfies TSESLint.InvalidTestCase<'missingPadding', never>; + column: 1 + } + ] +} satisfies TSESLint.InvalidTestCase<'missingPadding', never> ruleTester.run('padding-around-test-blocks', rule, { valid: [testCase.output], invalid: ['src/component.test.jsx', 'src/component.test.js'].map( - filename => ({ ...testCase, filename }), - ), -}); - + filename => ({ ...testCase, filename }) + ) +}) diff --git a/tests/prefer-expect-assertions.test.ts b/tests/prefer-expect-assertions.test.ts index eaf7266e..498a713a 100644 --- a/tests/prefer-expect-assertions.test.ts +++ b/tests/prefer-expect-assertions.test.ts @@ -102,7 +102,7 @@ it('my test description', ({ expect }) => {expect.assertions(); } ] } - ], + ] }, { code: ` @@ -143,7 +143,7 @@ it('my test description', (context) => {context.expect.assertions(); } ] } - ], + ] }, { code: 'it(\'resolves\', () => expect(staged()).toBe(true));', @@ -408,7 +408,7 @@ it('my test description', (context) => {context.expect.assertions(); line: 1, suggestions: [ { - messageId: "suggestAddingHasAssertions", + messageId: 'suggestAddingHasAssertions', output: `it("returns numbers that are greater than four", async () => {expect.hasAssertions(); for (const number of await getNumbers()) { expect(number).toBeGreaterThan(4); @@ -423,7 +423,7 @@ it('my test description', (context) => {context.expect.assertions(); ` }, { - messageId: "suggestAddingAssertions", + messageId: 'suggestAddingAssertions', output: `it("returns numbers that are greater than four", async () => {expect.assertions(); for (const number of await getNumbers()) { expect(number).toBeGreaterThan(4); @@ -446,7 +446,7 @@ it('my test description', (context) => {context.expect.assertions(); line: 7, suggestions: [ { - messageId: "suggestAddingHasAssertions", + messageId: 'suggestAddingHasAssertions', output: `it("returns numbers that are greater than four", async () => { for (const number of await getNumbers()) { expect(number).toBeGreaterThan(4); @@ -461,7 +461,7 @@ it('my test description', (context) => {context.expect.assertions(); ` }, { - messageId: "suggestAddingAssertions", + messageId: 'suggestAddingAssertions', output: `it("returns numbers that are greater than four", async () => { for (const number of await getNumbers()) { expect(number).toBeGreaterThan(4); diff --git a/tests/prefer-vi-mocked.test.ts b/tests/prefer-vi-mocked.test.ts index 99efec95..606da97e 100644 --- a/tests/prefer-vi-mocked.test.ts +++ b/tests/prefer-vi-mocked.test.ts @@ -1,126 +1,126 @@ -import rule, { RULE_NAME } from "../src/rules/prefer-vi-mocked"; -import { ruleTester } from "./ruleTester"; +import rule, { RULE_NAME } from '../src/rules/prefer-vi-mocked' +import { ruleTester } from './ruleTester' ruleTester.run(RULE_NAME, rule, { valid: [ - "foo();", - "vi.mocked(foo).mockReturnValue(1);", - "bar.mockReturnValue(1);", - "sinon.stub(foo).returns(1);", - "foo.mockImplementation(() => 1);", - "obj.foo();", - "mockFn.mockReturnValue(1);", - "arr[0]();", - "obj.foo.mockReturnValue(1);", + 'foo();', + 'vi.mocked(foo).mockReturnValue(1);', + 'bar.mockReturnValue(1);', + 'sinon.stub(foo).returns(1);', + 'foo.mockImplementation(() => 1);', + 'obj.foo();', + 'mockFn.mockReturnValue(1);', + 'arr[0]();', + 'obj.foo.mockReturnValue(1);', 'vi.spyOn(obj, "foo").mockReturnValue(1);', - "(foo as Mock.vi).mockReturnValue(1);", + '(foo as Mock.vi).mockReturnValue(1);', `type MockType = Mock; const mockFn = vi.fn(); -(mockFn as MockType).mockReturnValue(1);`, +(mockFn as MockType).mockReturnValue(1);` ], invalid: [ { - code: "(foo as Mock).mockReturnValue(1);", - output: "(vi.mocked(foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as Mock).mockReturnValue(1);', + output: '(vi.mocked(foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as unknown as string as unknown as Mock).mockReturnValue(1);", - output: "(vi.mocked(foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as unknown as string as unknown as Mock).mockReturnValue(1);', + output: '(vi.mocked(foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as unknown as Mock as unknown as Mock).mockReturnValue(1);", - output: "(vi.mocked(foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as unknown as Mock as unknown as Mock).mockReturnValue(1);', + output: '(vi.mocked(foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo).mockReturnValue(1);", - output: "(vi.mocked(foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo).mockReturnValue(1);', + output: '(vi.mocked(foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as Mock).mockImplementation(1);", - output: "(vi.mocked(foo)).mockImplementation(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as Mock).mockImplementation(1);', + output: '(vi.mocked(foo)).mockImplementation(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as unknown as Mock).mockReturnValue(1);", - output: "(vi.mocked(foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as unknown as Mock).mockReturnValue(1);', + output: '(vi.mocked(foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as unknown).mockReturnValue(1);", - output: "(vi.mocked(foo) as unknown).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as unknown).mockReturnValue(1);', + output: '(vi.mocked(foo) as unknown).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(Obj.foo as Mock).mockReturnValue(1);", - output: "(vi.mocked(Obj.foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(Obj.foo as Mock).mockReturnValue(1);', + output: '(vi.mocked(Obj.foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "([].foo as Mock).mockReturnValue(1);", - output: "(vi.mocked([].foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '([].foo as Mock).mockReturnValue(1);', + output: '(vi.mocked([].foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as MockedFunction).mockReturnValue(1);", - output: "(vi.mocked(foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as MockedFunction).mockReturnValue(1);', + output: '(vi.mocked(foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as MockedFunction).mockImplementation(1);", - output: "(vi.mocked(foo)).mockImplementation(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as MockedFunction).mockImplementation(1);', + output: '(vi.mocked(foo)).mockImplementation(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as unknown as MockedFunction).mockReturnValue(1);", - output: "(vi.mocked(foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(foo as unknown as MockedFunction).mockReturnValue(1);', + output: '(vi.mocked(foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(Obj.foo as MockedFunction).mockReturnValue(1);", - output: "(vi.mocked(Obj.foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(Obj.foo as MockedFunction).mockReturnValue(1);', + output: '(vi.mocked(Obj.foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(new Array(0).fill(null).foo as MockedFunction).mockReturnValue(1);", - output: "(vi.mocked(new Array(0).fill(null).foo)).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(new Array(0).fill(null).foo as MockedFunction).mockReturnValue(1);', + output: '(vi.mocked(new Array(0).fill(null).foo)).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "(vi.fn(() => foo) as MockedFunction).mockReturnValue(1);", - output: "(vi.mocked(vi.fn(() => foo))).mockReturnValue(1);", - errors: [{ messageId: "useViMocked" }], + code: '(vi.fn(() => foo) as MockedFunction).mockReturnValue(1);', + output: '(vi.mocked(vi.fn(() => foo))).mockReturnValue(1);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "const mockedUseFocused = useFocused as MockedFunction;", - output: "const mockedUseFocused = vi.mocked(useFocused);", - errors: [{ messageId: "useViMocked" }], + code: 'const mockedUseFocused = useFocused as MockedFunction;', + output: 'const mockedUseFocused = vi.mocked(useFocused);', + errors: [{ messageId: 'useViMocked' }] }, { - code: "const filter = (MessageService.getMessage as Mock).mock.calls[0][0];", + code: 'const filter = (MessageService.getMessage as Mock).mock.calls[0][0];', output: - "const filter = (vi.mocked(MessageService.getMessage)).mock.calls[0][0];", - errors: [{ messageId: "useViMocked" }], + 'const filter = (vi.mocked(MessageService.getMessage)).mock.calls[0][0];', + errors: [{ messageId: 'useViMocked' }] }, { code: `class A {} (foo as MockedClass)`, output: `class A {} (vi.mocked(foo))`, - errors: [{ messageId: "useViMocked" }], + errors: [{ messageId: 'useViMocked' }] }, { - code: "(foo as MockedObject<{method: () => void}>)", - output: "(vi.mocked(foo))", - errors: [{ messageId: "useViMocked" }], + code: '(foo as MockedObject<{method: () => void}>)', + output: '(vi.mocked(foo))', + errors: [{ messageId: 'useViMocked' }] }, { code: '(Obj["foo"] as MockedFunction).mockReturnValue(1);', output: '(vi.mocked(Obj["foo"])).mockReturnValue(1);', - errors: [{ messageId: "useViMocked" }], + errors: [{ messageId: 'useViMocked' }] }, { code: `( @@ -137,7 +137,7 @@ vi.mocked(new Array(100) .map(x => x.value) .filter(v => !!v).myProperty) ).mockReturnValue(1);`, - errors: [{ messageId: "useViMocked" }], - }, - ], -}); + errors: [{ messageId: 'useViMocked' }] + } + ] +}) diff --git a/tests/require-hook.test.ts b/tests/require-hook.test.ts index 8930d503..55a8eea7 100644 --- a/tests/require-hook.test.ts +++ b/tests/require-hook.test.ts @@ -16,9 +16,9 @@ test('myFn', () => { expect(myFn()).toBe(1); }); `, - languageOptions: { parserOptions: { sourceType: 'module' } } - }, - ` + languageOptions: { parserOptions: { sourceType: 'module' } } + }, + ` class MockLogger { log() {} } diff --git a/tests/valid-describe-callback.test.ts b/tests/valid-describe-callback.test.ts index bc967b59..d8eef9b0 100644 --- a/tests/valid-describe-callback.test.ts +++ b/tests/valid-describe-callback.test.ts @@ -65,7 +65,7 @@ ruleTester.run(RULE_NAME, rule, { }) }) }) - `, + ` ], invalid: [ { @@ -188,7 +188,7 @@ ruleTester.run(RULE_NAME, rule, { `, errors: [ { messageId: 'unexpectedReturnInDescribe', line: 2, column: 40 } - ], + ] }, { code: ` @@ -210,7 +210,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [ { messageId: 'unexpectedReturnInDescribe', line: 3, column: 7 }, { messageId: 'unexpectedReturnInDescribe', line: 9, column: 9 } - ], + ] }, { code: 'describe("foo", done => {})', @@ -240,7 +240,7 @@ ruleTester.run(RULE_NAME, rule, { code: 'describe("foo", { only: true }, done => {})', errors: [ { messageId: 'unexpectedDescribeArgument', line: 1, column: 33 } - ], - }, + ] + } ] }) diff --git a/tests/valid-expect-in-promise.test.ts b/tests/valid-expect-in-promise.test.ts index 355acace..f3d71f18 100644 --- a/tests/valid-expect-in-promise.test.ts +++ b/tests/valid-expect-in-promise.test.ts @@ -1,9 +1,9 @@ -import rule, { RULE_NAME } from '../src/rules/valid-expect-in-promise'; -import { ruleTester } from './ruleTester'; +import rule, { RULE_NAME } from '../src/rules/valid-expect-in-promise' +import { ruleTester } from './ruleTester' ruleTester.run(RULE_NAME, rule, { valid: [ - "test('something', () => Promise.resolve().then(() => expect(1).toBe(2)));", + 'test(\'something\', () => Promise.resolve().then(() => expect(1).toBe(2)));', 'Promise.resolve().then(() => expect(1).toBe(2))', 'const x = Promise.resolve().then(() => expect(1).toBe(2))', ` @@ -827,7 +827,7 @@ ruleTester.run(RULE_NAME, rule, { return Promise.allSettled([onePromise, twoPromise]); }); - `, + ` ], invalid: [ { @@ -849,9 +849,9 @@ ruleTester.run(RULE_NAME, rule, { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise', - line: 9, - }, - ], + line: 9 + } + ] }, { code: ` @@ -862,8 +862,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -874,8 +874,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -886,8 +886,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 10, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 10, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -898,8 +898,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -910,8 +910,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -922,8 +922,8 @@ ruleTester.run(RULE_NAME, rule, { }) `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -934,8 +934,8 @@ ruleTester.run(RULE_NAME, rule, { }) `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -946,8 +946,8 @@ ruleTester.run(RULE_NAME, rule, { }) `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -960,8 +960,8 @@ ruleTester.run(RULE_NAME, rule, { }) `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -973,8 +973,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -986,8 +986,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 55, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 55, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -999,8 +999,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 55, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 55, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1012,8 +1012,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1024,8 +1024,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 58, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 58, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1036,8 +1036,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 28, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 28, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1051,8 +1051,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1066,8 +1066,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1081,8 +1081,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1098,8 +1098,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1114,8 +1114,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 43, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 43, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1130,8 +1130,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 30, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 30, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1143,8 +1143,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1156,8 +1156,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1169,8 +1169,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1182,8 +1182,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1196,8 +1196,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1212,8 +1212,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1228,8 +1228,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1244,8 +1244,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1260,8 +1260,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1276,8 +1276,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1292,8 +1292,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1306,8 +1306,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1320,8 +1320,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1334,8 +1334,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1348,8 +1348,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1362,8 +1362,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1374,8 +1374,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 17, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1386,8 +1386,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 24, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 24, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1400,11 +1400,11 @@ ruleTester.run(RULE_NAME, rule, { }); `, languageOptions: { - parserOptions: { sourceType: 'module' }, + parserOptions: { sourceType: 'module' } }, errors: [ - { column: 24, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 24, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1418,8 +1418,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1433,8 +1433,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' }, - ], + { column: 11, endColumn: 14, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1449,8 +1449,8 @@ ruleTester.run(RULE_NAME, rule, { }); `, errors: [ - { column: 15, endColumn: 13, messageId: 'expectInFloatingPromise' }, - ], + { column: 15, endColumn: 13, messageId: 'expectInFloatingPromise' } + ] }, { code: ` @@ -1471,9 +1471,9 @@ ruleTester.run(RULE_NAME, rule, { column: 15, endColumn: 13, line: 3, - messageId: 'expectInFloatingPromise', - }, - ], + messageId: 'expectInFloatingPromise' + } + ] }, { code: ` @@ -1490,9 +1490,9 @@ ruleTester.run(RULE_NAME, rule, { column: 15, endColumn: 13, line: 3, - messageId: 'expectInFloatingPromise', - }, - ], + messageId: 'expectInFloatingPromise' + } + ] }, { code: ` @@ -1515,9 +1515,9 @@ ruleTester.run(RULE_NAME, rule, { column: 15, endColumn: 13, line: 3, - messageId: 'expectInFloatingPromise', - }, - ], + messageId: 'expectInFloatingPromise' + } + ] }, { code: ` @@ -1532,9 +1532,9 @@ ruleTester.run(RULE_NAME, rule, { column: 11, endColumn: 13, line: 3, - messageId: 'expectInFloatingPromise', - }, - ], + messageId: 'expectInFloatingPromise' + } + ] }, { code: ` @@ -1550,9 +1550,9 @@ ruleTester.run(RULE_NAME, rule, { { messageId: 'expectInFloatingPromise', line: 3, - column: 17, - }, - ], + column: 17 + } + ] }, { code: ` @@ -1570,9 +1570,9 @@ ruleTester.run(RULE_NAME, rule, { { messageId: 'expectInFloatingPromise', line: 3, - column: 17, - }, - ], + column: 17 + } + ] }, { code: ` @@ -1590,9 +1590,9 @@ ruleTester.run(RULE_NAME, rule, { { messageId: 'expectInFloatingPromise', line: 3, - column: 17, - }, - ], + column: 17 + } + ] }, { code: ` @@ -1608,14 +1608,14 @@ ruleTester.run(RULE_NAME, rule, { expect(anotherPromise).resolves.toBe(1); }); `, - languageOptions: { parserOptions: { sourceType: 'module' }}, + languageOptions: { parserOptions: { sourceType: 'module' } }, errors: [ { messageId: 'expectInFloatingPromise', line: 5, - column: 17, - }, - ], + column: 17 + } + ] }, { code: ` @@ -1633,10 +1633,10 @@ ruleTester.run(RULE_NAME, rule, { { messageId: 'expectInFloatingPromise', line: 3, - column: 17, - }, + column: 17 + } ], - settings: { vitest: { globalAliases: { xit: ['promiseThatThis'] } } }, - }, - ], -}); \ No newline at end of file + settings: { vitest: { globalAliases: { xit: ['promiseThatThis'] } } } + } + ] +}) diff --git a/tests/valid-expect.test.ts b/tests/valid-expect.test.ts index 2d066fa3..c94ca0d0 100644 --- a/tests/valid-expect.test.ts +++ b/tests/valid-expect.test.ts @@ -116,7 +116,7 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, + } }, { code: `expectTypeOf().branded.toMatchTypeOf();`, @@ -124,7 +124,7 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, + } }, { code: `expectTypeOf().asserts.toMatchTypeOf();`, @@ -132,7 +132,7 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, + } }, { code: `expectTypeOf().constructorParameters.toMatchTypeOf();`, @@ -140,7 +140,7 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, + } }, { code: `expectTypeOf().parameters.toMatchTypeOf();`, @@ -148,7 +148,7 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, + } }, { code: `expectTypeOf().thisParameter.toMatchTypeOf();`, @@ -156,7 +156,7 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, + } }, { code: `expectTypeOf().guards.toMatchTypeOf();`, @@ -164,7 +164,7 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, + } }, { code: `expectTypeOf().instance.toMatchTypeOf();`, @@ -172,7 +172,7 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, + } }, { code: `expectTypeOf().items.toMatchTypeOf();`, @@ -180,8 +180,8 @@ ruleTester.run(RULE_NAME, rule, { vitest: { typecheck: true } - }, - }, + } + } ], invalid: [ { @@ -307,7 +307,7 @@ ruleTester.run(RULE_NAME, rule, { { endColumn: 26, column: 21, - messageId: 'tooManyArgs', + messageId: 'tooManyArgs' } ] }, @@ -317,7 +317,7 @@ ruleTester.run(RULE_NAME, rule, { { endColumn: 24, column: 21, - messageId: 'tooManyArgs', + messageId: 'tooManyArgs' } ] }, @@ -327,7 +327,7 @@ ruleTester.run(RULE_NAME, rule, { { endColumn: 24, column: 21, - messageId: 'tooManyArgs', + messageId: 'tooManyArgs' } ] }, @@ -337,7 +337,7 @@ ruleTester.run(RULE_NAME, rule, { { endColumn: 24, column: 21, - messageId: 'tooManyArgs', + messageId: 'tooManyArgs' } ] }, diff --git a/tests/valid-title.test.ts b/tests/valid-title.test.ts index 1c2bb859..3d4ada03 100644 --- a/tests/valid-title.test.ts +++ b/tests/valid-title.test.ts @@ -126,7 +126,6 @@ ruleTester.run(RULE_NAME, rule, { ] }) - ruleTester.run(RULE_NAME, rule, { valid: [ { diff --git a/unbuild.config.ts b/unbuild.config.ts index 3f38c8d1..8f6f57f9 100644 --- a/unbuild.config.ts +++ b/unbuild.config.ts @@ -1,7 +1,7 @@ import { defineBuildConfig } from 'unbuild' export default defineBuildConfig({ - entries: [ './src/index.ts' ], + entries: ['./src/index.ts'], declaration: true, clean: true, rollup: { @@ -9,5 +9,5 @@ export default defineBuildConfig({ esbuild: { minify: true } - }, -}) \ No newline at end of file + } +})