Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: padding-around-expect-groups doesn't detect expectTypeOf as an expect clause #588

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/rules/padding-around-expect-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ export const config: Config[] = [
prevStatementType: StatementType.ExpectToken,
nextStatementType: StatementType.ExpectToken,
},
{
paddingType: PaddingType.Always,
prevStatementType: StatementType.Any,
nextStatementType: StatementType.ExpectTypeOfToken,
},
{
paddingType: PaddingType.Always,
prevStatementType: StatementType.ExpectTypeOfToken,
nextStatementType: StatementType.Any,
},
{
paddingType: PaddingType.Any,
prevStatementType: StatementType.ExpectTypeOfToken,
nextStatementType: StatementType.ExpectTypeOfToken,
},
];

export default createPaddingRule(
Expand Down
2 changes: 2 additions & 0 deletions src/utils/padding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const enum StatementType {
BeforeEachToken,
DescribeToken,
ExpectToken,
ExpectTypeOfToken,
FdescribeToken,
FitToken,
ItToken,
Expand Down Expand Up @@ -175,6 +176,7 @@ const statementTesters: { [T in StatementType]: StatementTester } = {
[StatementType.BeforeEachToken]: createTokenTester('beforeEach'),
[StatementType.DescribeToken]: createTokenTester('describe'),
[StatementType.ExpectToken]: createTokenTester('expect'),
[StatementType.ExpectTypeOfToken]: createTokenTester('expectTypeOf'),
[StatementType.FdescribeToken]: createTokenTester('fdescribe'),
[StatementType.FitToken]: createTokenTester('fit'),
[StatementType.ItToken]: createTokenTester('it'),
Expand Down
42 changes: 40 additions & 2 deletions tests/padding-around-expect-groups.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import type { TSESLint } from '@typescript-eslint/utils';
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: `
Expand Down Expand Up @@ -61,6 +61,16 @@ test('awaited expect', async () => {
await somethingElseAsync();
await expect(hasAPromise()).resolves.toEqual('foo');
});
test('expectTypeOf test', () => {
const hoge = 123;
expectTypeOf(hoge).toBeNumber();
expectTypeOf(hoge).toBeNumber();
const foo = "abc";
// Comment
expectTypeOf(foo).toBeString();
expectTypeOf(foo).toBeString();
});
`,
output: `
foo();
Expand Down Expand Up @@ -129,6 +139,19 @@ test('awaited expect', async () => {
await expect(hasAPromise()).resolves.toEqual('foo');
});
test('expectTypeOf test', () => {
const hoge = 123;
expectTypeOf(hoge).toBeNumber();
expectTypeOf(hoge).toBeNumber();
const foo = "abc";
// Comment
expectTypeOf(foo).toBeString();
expectTypeOf(foo).toBeString();
});
`,
errors: [
{
Expand Down Expand Up @@ -181,8 +204,23 @@ test('awaited expect', async () => {
line: 56,
column: 3,
},
{
messageId: 'missingPadding',
line: 61,
column: 3,
},
{
messageId: 'missingPadding',
line: 63,
column: 3,
},
{
messageId: 'missingPadding',
line: 65,
column: 3,
},
],
} satisfies TSESLint.InvalidTestCase<'missingPadding', never>;
} satisfies InvalidTestCase<'missingPadding', never>;

ruleTester.run(RULE_NAME, rule, {
valid: [testCase.output],
Expand Down