From 1d42a33952061849b0b51d0847967e270870bcfb Mon Sep 17 00:00:00 2001 From: Jianqi Pan Date: Tue, 3 Oct 2023 11:06:23 +0900 Subject: [PATCH] feat(bench): prefer lowercase title for bench (#263) * Update types.ts * Update prefer-lowercase-title.ts * feat: prefer lowercase title for bench --- src/rules/prefer-lowercase-title.ts | 1 + src/utils/parseVitestFnCall.ts | 1 + src/utils/types.ts | 1 + tests/prefer-lowercase-title.test.ts | 14 +++++++++++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/rules/prefer-lowercase-title.ts b/src/rules/prefer-lowercase-title.ts index 6e6f369..3629326 100644 --- a/src/rules/prefer-lowercase-title.ts +++ b/src/rules/prefer-lowercase-title.ts @@ -9,6 +9,7 @@ export type MessageIds = 'lowerCaseTitle'; type IgnorableFunctionExpressions = | TestCaseName.it | TestCaseName.test + | TestCaseName.bench | DescribeAlias.describe; const hasStringAsFirstArgument = ( diff --git a/src/utils/parseVitestFnCall.ts b/src/utils/parseVitestFnCall.ts index 7ab063b..4ab2c4b 100644 --- a/src/utils/parseVitestFnCall.ts +++ b/src/utils/parseVitestFnCall.ts @@ -7,6 +7,7 @@ const ValidVitestFnCallChains = [ 'afterEach', 'beforeAll', 'beforeEach', + 'bench', 'describe', 'describe.each', 'describe.only', diff --git a/src/utils/types.ts b/src/utils/types.ts index aacffff..58154ff 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -12,6 +12,7 @@ export enum TestCaseName { 'test' = 'test', 'xit' = 'xit', 'xtest' = 'xtest', + 'bench' = 'bench', } export enum HookName { diff --git a/tests/prefer-lowercase-title.test.ts b/tests/prefer-lowercase-title.test.ts index 4e0aff1..78931c8 100644 --- a/tests/prefer-lowercase-title.test.ts +++ b/tests/prefer-lowercase-title.test.ts @@ -52,6 +52,18 @@ ruleTester.run(RULE_NAME, rule, { lowercaseFirstCharacterOnly: false } ] - } + }, + { + code: 'bench(`Foo MM mm`, function () {})', + output: 'bench(`foo MM mm`, function () {})', + errors: [ + { + messageId: 'lowerCaseTitle', + data: { + method: TestCaseName.bench + } + } + ] + }, ] })