Skip to content

Commit

Permalink
feat(no-method-signature): properly handle `Readonly<{TSMethodSignatu…
Browse files Browse the repository at this point in the history
…re}>`
  • Loading branch information
rafaelss95 authored and RebeccaStevens committed Aug 28, 2021
1 parent dcc7d7d commit 18d178f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/no-method-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const rule = createRule<keyof typeof errorMessages, Options>(
meta,
defaultOptions,
{
TSMethodSignature: checkTSMethodSignature,
':matches(TSInterfaceBody, TSTypeAliasDeclaration > TSIntersectionType > TSTypeLiteral, TSTypeAliasDeclaration > TSTypeLiteral, TSTypeAliasDeclaration > TSTypeReference:not([typeName.name="Readonly"]) > TSTypeParameterInstantiation > TSIntersectionType > TSTypeLiteral, TSTypeLiteral > TSPropertySignature > TSTypeAnnotation > TSTypeLiteral) > TSMethodSignature':
checkTSMethodSignature,
}
);
69 changes: 69 additions & 0 deletions tests/rules/no-method-signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,50 @@ const valid: ReadonlyArray<ValidTestCase> = [
}`,
optionsSet: [[]],
},
{
code: dedent`
interface Foo extends Readonly<{
methodSignature(): void
}>{}`,
optionsSet: [[]],
},
{
code: dedent`
interface Foo extends Bar, Readonly<Baz & {
methodSignature(): void
}>{}`,
optionsSet: [[]],
},
{
code: dedent`
type Foo2 = {
bar: (a: number, b: string) => number
}`,
optionsSet: [[]],
},
{
code: dedent`
type Foo = Readonly<{
methodSignature(): void
}>`,
optionsSet: [[]],
},
{
code: dedent`
type Foo = Bar & Readonly<Baz & {
methodSignature(): void
}>`,
optionsSet: [[]],
},
{
code: dedent`
type Foo = Bar & Readonly<Baz & {
nested: Readonly<{
methodSignature(): void
}>
}>`,
optionsSet: [[]],
},
];

// Invalid test cases.
Expand Down Expand Up @@ -66,6 +103,38 @@ const invalid: ReadonlyArray<InvalidTestCase> = [
},
],
},
{
code: dedent`
type Foo = Bar & Readonly<Baz> & {
methodSignature(): void
}`,
optionsSet: [[]],
errors: [
{
messageId: "generic",
type: "TSMethodSignature",
line: 2,
column: 3,
},
],
},
{
code: dedent`
type Foo = Bar & Readonly<Baz & {
nested: {
methodSignature(): void
}
}>`,
optionsSet: [[]],
errors: [
{
messageId: "generic",
type: "TSMethodSignature",
line: 3,
column: 5,
},
],
},
];

describeTsOnly("TypeScript", () => {
Expand Down

0 comments on commit 18d178f

Please sign in to comment.