{
+ return Promise.resolve('siema');
+ }
+ }
+ `,
+ errors: [
+ {
+ column: 11,
+ line: 6,
+ messageId: 'asyncFunc',
+ },
+ ],
+ },
+ {
+ code: `
+ interface Foo {
+ cb(): void;
+ }
+ class Bar implements Foo {
+ async cb() {
+ try {
+ return { a: ['asdf', 1234] };
+ } catch {
+ console.error('error');
+ }
+ }
+ }
+ `,
+ errors: [
+ {
+ column: 11,
+ line: 6,
+ messageId: 'asyncFunc',
+ },
+ ],
+ },
+ {
+ code: `
+ interface Foo {
+ cb(): void;
+ }
+ class Bar implements Foo {
+ cb() {
+ if (maybe) {
+ return Promise.resolve(1);
+ } else {
+ return;
+ }
+ }
+ }
+ `,
+ errors: [
+ {
+ column: 15,
+ line: 8,
+ messageId: 'nonVoidReturn',
+ },
+ ],
+ },
+ {
+ code: `
+ interface Foo1 {
+ cb1(): void;
+ }
+ interface Foo2 {
+ cb2: () => void;
+ }
+ class Bar implements Foo1, Foo2 {
+ async cb1() {}
+ async *cb2() {}
+ }
+ `,
+ errors: [
+ {
+ column: 11,
+ line: 9,
+ messageId: 'asyncFunc',
+ },
+ {
+ column: 11,
+ line: 10,
+ messageId: 'nonVoidFunc',
+ },
+ ],
+ },
+ {
+ code: `
+ interface Foo1 {
+ cb1(): void;
+ }
+ interface Foo2 {
+ cb2: () => void;
+ }
+ class Baz {
+ cb3() {}
+ }
+ class Bar extends Baz implements Foo1, Foo2 {
+ async cb1() {}
+ async *cb2() {}
+ cb3() {
+ return Math.random();
+ }
+ }
+ `,
+ errors: [
+ {
+ column: 11,
+ line: 12,
+ messageId: 'asyncFunc',
+ },
+ {
+ column: 11,
+ line: 13,
+ messageId: 'nonVoidFunc',
+ },
+ {
+ column: 13,
+ line: 15,
+ messageId: 'nonVoidReturn',
+ },
+ ],
+ },
+ {
+ code: `
+ class A extends class {
+ cb() {}
+ } {
+ cb() {
+ return Math.random();
+ }
+ }
+ `,
+ errors: [
+ {
+ column: 13,
+ line: 6,
+ messageId: 'nonVoidReturn',
+ },
+ ],
+ },
+ {
+ code: `
+ class A extends class B {
+ cb() {}
+ } {
+ cb() {
+ return Math.random();
+ }
+ }
+ `,
+ errors: [
+ {
+ column: 13,
+ line: 6,
+ messageId: 'nonVoidReturn',
+ },
+ ],
+ },
+ {
+ code: `
+ interface Foo1 {
+ cb1(): void;
+ }
+ interface Foo2 extends Foo1 {
+ cb2: () => void;
+ }
+ class Bar implements Foo2 {
+ async cb1() {}
+ async *cb2() {}
+ }
+ `,
+ errors: [
+ {
+ column: 11,
+ line: 9,
+ messageId: 'asyncFunc',
+ },
+ {
+ column: 11,
+ line: 10,
+ messageId: 'nonVoidFunc',
+ },
+ ],
+ },
+ {
+ code: `
+ declare let foo: () => () => void;
+ foo = () => () => 1 + 1;
+ `,
+ errors: [{ column: 27, line: 3, messageId: 'nonVoidReturn' }],
+ },
+ {
+ code: `
+ declare let foo: () => () => void;
+ foo = () => () => Math.random();
+ `,
+ errors: [{ column: 27, line: 3, messageId: 'nonVoidReturn' }],
+ },
+ {
+ code: `
+ declare let foo: () => () => void;
+ declare const cb: () => null | false;
+ foo = () => cb;
+ `,
+ errors: [{ column: 21, line: 4, messageId: 'nonVoidFunc' }],
+ },
+ {
+ code: `
+ declare let foo: { f(): () => void };
+ foo = {
+ f() {
+ return () => cb;
+ },
+ };
+ function cb() {}
+ `,
+ errors: [{ column: 26, line: 5, messageId: 'nonVoidReturn' }],
+ },
+ {
+ code: `
+ declare let foo: { f(): () => void };
+ foo.f = function () {
+ return () => {
+ return null;
+ };
+ };
+ `,
+ errors: [{ column: 13, line: 5, messageId: 'nonVoidReturn' }],
+ },
+ {
+ code: `
+ declare let foo: () => (() => void) | string;
+ foo = () => () => {
+ return 'asd' + 'zxc';
+ };
+ `,
+ errors: [{ column: 11, line: 4, messageId: 'nonVoidReturn' }],
+ },
+ {
+ code: `
+ declare function foo(cb: () => () => void): void;
+ foo(function () {
+ return async () => {};
+ });
+ `,
+ errors: [{ column: 27, line: 4, messageId: 'asyncFunc' }],
+ },
+ {
+ code: noFormat`
+ declare function foo(cb: () => () => void): void;
+ foo(() => () => {
+ if (n == 1) {
+ console.log('asd')
+ return [1].map(x => x)
+ }
+ if (n == 2) {
+ console.log('asd')
+ return -Math.random()
+ }
+ if (n == 3) {
+ console.log('asd')
+ return \`x\`.toUpperCase()
+ }
+ return {Math.random()}
+ });
+ `,
+ errors: [
+ { column: 13, line: 6, messageId: 'nonVoidReturn' },
+ { column: 13, line: 10, messageId: 'nonVoidReturn' },
+ { column: 13, line: 14, messageId: 'nonVoidReturn' },
+ { column: 11, line: 16, messageId: 'nonVoidReturn' },
+ ],
+ filename: 'react.tsx',
+ },
+ {
+ code: `
+ declare function foo(cb: (arg: string) => () => void): void;
+ declare function foo(cb: (arg: number) => () => boolean): void;
+ foo((arg: string) => {
+ return cb;
+ });
+ async function* cb() {
+ yield true;
+ }
+ `,
+ errors: [{ column: 18, line: 5, messageId: 'nonVoidFunc' }],
+ },
+ ],
+});
diff --git a/packages/eslint-plugin/tests/schema-snapshots/strict-void-return.shot b/packages/eslint-plugin/tests/schema-snapshots/strict-void-return.shot
new file mode 100644
index 000000000000..3d07ac096c12
--- /dev/null
+++ b/packages/eslint-plugin/tests/schema-snapshots/strict-void-return.shot
@@ -0,0 +1,25 @@
+
+# SCHEMA:
+
+[
+ {
+ "additionalProperties": false,
+ "properties": {
+ "allowReturnAny": {
+ "description": "Whether to allow functions returning `any` to be used in place expecting a `void` function.",
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ }
+]
+
+
+# TYPES:
+
+type Options = [
+ {
+ /** Whether to allow functions returning `any` to be used in place expecting a `void` function. */
+ allowReturnAny?: boolean;
+ },
+];
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy