eslint-plugin-functional icon indicating copy to clipboard operation
eslint-plugin-functional copied to clipboard

prefer-immutable-types: upgrade from v5 to v6 introduces an infinite recursion issue

Open danielnixon opened this issue 11 months ago • 2 comments

Bug Report

Hi, me again with another recursion issue :P

export type ReadonlyURLSearchParams = Readonly<
  OmitStrict<URLSearchParams, "append" | "delete" | "set" | "sort" | "forEach">
>;

// explosion here
export const readonlyURLSearchParams = (
  // eslint-disable-next-line functional/prefer-immutable-types
  init?:
    | readonly (readonly string[])[]
    // eslint-disable-next-line functional/prefer-readonly-type
    | string[][]
    | Record<string, string>
    | string
    | URLSearchParams
    | ReadonlyURLSearchParams,
): ReadonlyURLSearchParams =>
  new URLSearchParams(
    // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, functional/prefer-readonly-type
    init as string[][] | Record<string, string> | string | URLSearchParams,
  );

export type ReadonlyURL = Readonly<OmitStrict<URL, "searchParams">> & {
  readonly searchParams: ReadonlyURLSearchParams;
};

Expected behavior

Linting terminates.

Actual behavior

Stack overflow:

❯ yarn lint 
yarn run v1.22.19
$ eslint src --ext .ts,.tsx --report-unused-disable-directives

Oops! Something went wrong! :(

ESLint: 8.48.0

RangeError: Maximum call stack size exceeded
Occurred while linting /Users/danielnixon/dev/agile-digital/readonly-types/src/index.ts:329
Rule: "functional/prefer-immutable-types"
    at /Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:245:51
    at Array.map (<anonymous>)
    at typeArgumentsToString (/Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:245:47)
    at TypeName.getNameWithArguments (/Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:171:54)
    at /Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:253:26
    at Array.map (<anonymous>)
    at typeArgumentsToString (/Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:245:47)
    at TypeName.getNameWithArguments (/Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:171:54)
    at /Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:253:26
    at Array.map (<anonymous>)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Steps to reproduce

See example code above.

Proposed changes

danielnixon avatar Sep 04 '23 23:09 danielnixon