import rule from "./no-nested-fp-ts-effects";
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
import { ESLintUtils } from "@typescript-eslint/utils";
// eslint-disable-next-line functional/prefer-immutable-types
const ruleTester = new ESLintUtils.RuleTester({
parserOptions: {
sourceType: "module",
project: "./tsconfig.tests.json",
},
parser: "@typescript-eslint/parser",
});
// eslint-disable-next-line functional/no-expression-statements
ruleTester.run("no-async-effect-within-io", rule, {
valid: [
// CallExpression with no symbol is okay
{
filename: "file.ts",
code: `
(() => undefined)();
`,
},
// Some other type with coincidentally the same name is okay (zero call signatures)
{
filename: "file.ts",
code: `
export interface IO {
a: A;
}
export interface Task {
a: A;
}
const liftIO = (val: A): IO => ({ a: val });
const liftTask = (val: A): Task => ({ a: val });
const foo = liftIO(liftTask("a"));
`,
},
// Some other type with coincidentally the same name is okay (multiple call signatures)
{
filename: "file.ts",
code: `
export interface IO {
(): A;
(a: string): void;
}
export interface Task {
(): Promise;
(a: string): void;
}
declare const liftIO: (val: A) => IO;
declare const liftTask: (val: A) => Task;
const foo = liftIO(liftTask("a"));
`,
},
// IO is okay
{
filename: "file.ts",
code: `
export interface IO {
(): A;
}
declare const liftIO: (val: A) => IO;
const bar = liftIO("a");
`,
},
],
invalid: [
// IO> is invalid
{
filename: "file.ts",
code: `
export interface IO {
(): A;
}
export interface Task {
(): Promise;
}
declare const liftIO: (val: A) => IO;
declare const liftTask: (val: A) => Task;
const foo = liftIO(liftTask("a"));
`,
errors: [
{
messageId: "errorStringGeneric",
type: AST_NODE_TYPES.CallExpression,
},
],
},
// IO> is invalid
{
filename: "file.ts",
code: `
export interface IO {
(): A;
}
export interface TaskEither {
(): Promise;
}
declare const liftIO: (val: A) => IO;
declare const liftTaskEither: (val: A) => TaskEither;
const foo = liftIO(liftTaskEither("a"));
`,
errors: [
{
messageId: "errorStringGeneric",
type: AST_NODE_TYPES.CallExpression,
},
],
},
// IO> is invalid
{
filename: "file.ts",
code: `
export interface IO {
(): A;
}
declare const liftIO: (val: A) => IO;
const foo = liftIO(Promise.resolve("a"));
`,
errors: [
{
messageId: "errorStringGeneric",
type: AST_NODE_TYPES.CallExpression,
},
],
},
],
} as const);