Skip to content

Commit 6cfd468

Browse files
authored
fix(eslint-plugin): [no-untyped-pub-sig] constructor return (#1231)
1 parent f1ab9a2 commit 6cfd468

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

packages/eslint-plugin/src/rules/no-untyped-public-signature.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ export default util.createRule<Options, MessageIds>({
106106
});
107107
}
108108

109-
if (!isReturnTyped(node.value.returnType)) {
109+
if (
110+
node.kind !== 'constructor' &&
111+
!isReturnTyped(node.value.returnType)
112+
) {
110113
context.report({
111114
node,
112115
messageId: 'noReturnType',

packages/eslint-plugin/tests/rules/no-untyped-public-signature.test.ts

+45-7
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ ruleTester.run('no-untyped-public-signature', rule, {
2828
code: `
2929
class A {
3030
public b(c: string):void {
31-
31+
3232
}
3333
}`,
3434
},
3535
{
3636
code: `
3737
class A {
3838
public b(...c):void {
39-
39+
4040
}
4141
}`,
4242
},
4343
{
4444
code: `
4545
class A {
4646
b(c):void {
47-
47+
4848
}
4949
}`,
5050
options: [{ ignoredMethods: ['b'] }],
@@ -71,22 +71,43 @@ ruleTester.run('no-untyped-public-signature', rule, {
7171
code: `
7272
class A {
7373
b(...c):void {
74-
74+
7575
}
76-
76+
7777
d(c):void {
78-
78+
7979
}
8080
}`,
8181
options: [{ ignoredMethods: ['b', 'd'] }],
8282
},
83+
// https://github.com/typescript-eslint/typescript-eslint/issues/1229
84+
`
85+
class Foo {
86+
constructor() {}
87+
}
88+
`,
89+
`
90+
class Foo {
91+
abstract constructor() {}
92+
}
93+
`,
94+
`
95+
class Foo {
96+
constructor(c: string) {}
97+
}
98+
`,
99+
`
100+
class Foo {
101+
abstract constructor(c: string) {}
102+
}
103+
`,
83104
],
84105
invalid: [
85106
//untyped parameter
86107
{
87108
code: `class A {
88109
public b(c):void {
89-
110+
90111
}
91112
}`,
92113
errors: [{ messageId: 'untypedParameter' }],
@@ -206,5 +227,22 @@ ruleTester.run('no-untyped-public-signature', rule, {
206227
}`,
207228
errors: [{ messageId: 'noReturnType' }],
208229
},
230+
// https://github.com/typescript-eslint/typescript-eslint/issues/1229
231+
{
232+
code: `
233+
class Foo {
234+
constructor(c) {}
235+
}
236+
`,
237+
errors: [{ messageId: 'untypedParameter' }],
238+
},
239+
{
240+
code: `
241+
class Foo {
242+
abstract constructor(c) {}
243+
}
244+
`,
245+
errors: [{ messageId: 'untypedParameter' }],
246+
},
209247
],
210248
});

0 commit comments

Comments
 (0)