Skip to content

Commit

Permalink
fix(eslint-plugin): method-signature-style respect getter signature (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Apr 3, 2022
1 parent 363fb0a commit 12dd670
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/eslint-plugin/src/rules/method-signature-style.ts
Expand Up @@ -115,6 +115,10 @@ export default util.createRule<Options, MessageIds>({
return {
...(mode === 'property' && {
TSMethodSignature(methodNode): void {
if (methodNode.kind !== 'method') {
return;
}

const parent = methodNode.parent;
const members =
parent?.type === AST_NODE_TYPES.TSInterfaceBody
Expand Down
16 changes: 16 additions & 0 deletions packages/eslint-plugin/tests/rules/method-signature-style.test.ts
Expand Up @@ -30,12 +30,24 @@ interface Test {
`
interface Test {
'f!': </* a */>(/* b */ x: any /* c */) => void;
}
`,
`
interface Test {
get f(): number;
}
`,
`
interface Test {
set f(value: number): void;
}
`,
'type Test = { readonly f: (a: string) => number };',
"type Test = { ['f']?: (a: boolean) => void };",
'type Test = { readonly f?: <T>(a?: T) => T };',
"type Test = { readonly ['f']?: <T>(a: T, b: T) => T };",
'type Test = { get f(): number };',
'type Test = { set f(value: number): void };',
...batchedSingleLineTests({
options: ['method'],
code: noFormat`
Expand All @@ -44,10 +56,14 @@ interface Test {
interface Test { f<T>(a: T): T }
interface Test { ['f']<T extends {}>(a: T, b: T): T }
interface Test { 'f!'</* a */>(/* b */ x: any /* c */): void }
interface Test { get f(): number }
interface Test { set f(value: number): void }
type Test = { readonly f(a: string): number }
type Test = { ['f']?(a: boolean): void }
type Test = { readonly f?<T>(a?: T): T }
type Test = { readonly ['f']?<T>(a: T, b: T): T }
type Test = { get f(): number }
type Test = { set f(value: number): void }
`,
}),
],
Expand Down

0 comments on commit 12dd670

Please sign in to comment.