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(eslint-plugin): method-signature-style respect getter signature #4777

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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