Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functional/functional-parameters Limit only to specific types #575

Open
danielnixon opened this issue Mar 13, 2023 · 3 comments · May be fixed by #803
Open

functional/functional-parameters Limit only to specific types #575

danielnixon opened this issue Mar 13, 2023 · 3 comments · May be fixed by #803
Labels
Accepted This issue or PR has been accepted. Priority: Low Nice addition, maybe... someday... Type: Feature New features or options.

Comments

@danielnixon
Copy link

Suggestion

When using functional/functional-parameters, we have ignorePrefixSelector but that can't tap into TypeScript type information.

There are a few places that I would love to whitelist in a way that requires type information. It would be great if we had that ability.

Here's one motivating example:

In https://github.com/gcanti/fp-ts, there are many cases where Lazy thunks are used to achieve functional purity.

One case is when lifting Promises (eager, not referentially transparent) into fp-ts TaskEithers (lazy, referentially transparent):

export declare const tryCatch: <E, A>(f: Lazy<Promise<A>>, onRejected: (reason: unknown) => E) => TaskEither<E, A>

When calling that, you are frequently taking some existing code that returns a Promise and doing this to it:

TE.tryCatch(() => existingCodeThatReturnsPromise);

That lazy thunk (() => ...) unfortunately triggers functional/functional-parameters, even though in this case we're writing code that in spirit is extremely functional.

Luckily, fp-ts defines Lazy like so:

export interface Lazy<A> {
  (): A
}

It could have defined it like export type Lazy<A> = () => A;, but for our purposes here we're lucky they made it a named interface.

If we could tap into the type information, we'd know that the contextual type of () => existingCodeThatReturnsPromise is actually Lazy<...> due to it being passed to TE.tryCatch (first param type being: f: Lazy<Promise<A>>). That would allow us to whitelist cases like this.

Note that fp-ts also defines a type IO<A> that is structurally the same as Lazy<A> but has different semantics: IO<A> is assumed to be impure. We would not want to whitelist IOs.

@danielnixon danielnixon added Status: Triage This issue needs to be triaged. Type: Idea Marks an idea, which might be accepted and implemented. labels Mar 13, 2023
@danielnixon
Copy link
Author

Very related: RebeccaStevens/is-immutable-type#47 (comment)

@RebeccaStevens RebeccaStevens added Status: Blocked Progress on this issue is currently not possible. Type: Feature New features or options. and removed Type: Idea Marks an idea, which might be accepted and implemented. Status: Triage This issue needs to be triaged. labels Mar 18, 2023
@RebeccaStevens RebeccaStevens changed the title Feature Request: ignorePrefixSelector with type information functional/functional-parameters Limit only to specific types Mar 18, 2023
@RebeccaStevens
Copy link
Collaborator

What sort of change would you like to see for this? A new option? How do you think it should work?

Note: we already have ignoreLambdaExpression, a sub-option of enforceParameterCount.

@danielnixon
Copy link
Author

Thanks for asking @RebeccaStevens. I'm picturing an ability to override the rule using something like https://github.com/RebeccaStevens/is-immutable-type#overrides, so something like this:

[{ type: { from: "fp-ts", name: "Lazy" }}]

That would be the most 'surgical' override. It would allow ESLint to continue to flag lambdas in the general case (no need for ignoreLambdaExpression) while permitting us to use them whenever they're used to achieve laziness with fp-ts, such as via

TE.tryCatch(() => existingCodeThatReturnsPromise);

I understand if you think this is more trouble than its worth and your recommendation is to just use ignoreLambdaExpression.

@RebeccaStevens RebeccaStevens added Priority: Low Nice addition, maybe... someday... and removed Status: Blocked Progress on this issue is currently not possible. labels Jul 17, 2023
@RebeccaStevens RebeccaStevens added the Accepted This issue or PR has been accepted. label Mar 25, 2024
RebeccaStevens added a commit that referenced this issue Apr 14, 2024
RebeccaStevens added a commit that referenced this issue Apr 14, 2024
RebeccaStevens added a commit that referenced this issue Apr 15, 2024
RebeccaStevens added a commit that referenced this issue Apr 15, 2024
RebeccaStevens added a commit that referenced this issue Apr 16, 2024
RebeccaStevens added a commit that referenced this issue Apr 17, 2024
RebeccaStevens added a commit that referenced this issue Apr 22, 2024
RebeccaStevens added a commit that referenced this issue Apr 22, 2024
RebeccaStevens added a commit that referenced this issue Apr 22, 2024
RebeccaStevens added a commit that referenced this issue Apr 30, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 6, 2024
RebeccaStevens added a commit that referenced this issue May 7, 2024
RebeccaStevens added a commit that referenced this issue May 9, 2024
RebeccaStevens added a commit that referenced this issue May 12, 2024
RebeccaStevens added a commit that referenced this issue May 19, 2024
RebeccaStevens added a commit that referenced this issue May 25, 2024
RebeccaStevens added a commit that referenced this issue May 25, 2024
RebeccaStevens added a commit that referenced this issue May 25, 2024
RebeccaStevens added a commit that referenced this issue May 25, 2024
RebeccaStevens added a commit that referenced this issue May 25, 2024
RebeccaStevens added a commit that referenced this issue May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted This issue or PR has been accepted. Priority: Low Nice addition, maybe... someday... Type: Feature New features or options.
Projects
None yet
2 participants