import parser from '@typescript-eslint/parser'; import { RuleTester } from '@typescript-eslint/rule-tester'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import dedent from 'dedent'; import { noNestedFpTsEffects } from './no-nested-fp-ts-effects.mjs'; const ruleTester = new RuleTester({ languageOptions: { parserOptions: { sourceType: 'module', project: './tsconfig.tests.json', }, parser, }, }); ruleTester.run('no-async-effect-within-io', noNestedFpTsEffects, { valid: [ // CallExpression with no symbol is okay { filename: 'file.ts', code: dedent` (() => undefined)(); `, }, // Some other type with coincidentally the same name is okay (zero call signatures) { filename: 'file.ts', code: dedent` 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: dedent` 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: dedent` export interface IO { (): A; } declare const liftIO: (val: A) => IO; const bar = liftIO("a"); `, }, ], invalid: [ // IO> is invalid { filename: 'file.ts', code: dedent` 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: dedent` 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: dedent` 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);