eslint-plugin-fp-ts
eslint-plugin-fp-ts copied to clipboard
Prefer flow
If the argument for a pipe is only referenced in the first step, it can be replaced with a flow
:
(foo) => pipe(
foo,
...
)
and
(foo: FooType) => pipe(
foo.bar,
...
)
can be:
flow(
...
)
and
flow(
(foo: FooType): foo.bar,
...
)
Can be easier to read, and keeps it out of scope for the rest of the pipeline.
Aware I've opened quite a few suggestions, hoping to put some time aside to start implementing soon, assuming the approach in https://github.com/buildo/eslint-plugin-fp-ts/pull/64 is ok.
@thewilkybarkid thank you so much, I'm sorry about leaving you hanging on #64, I haven't had a minute to review it, since schools are closed in Italy and this complicated my personal situation a bit 😩
I hope I'll find a minute soon! Thanks for the patience
by the way, this specific suggestion may not be a safe refactor in 100% cases, due to type inference.
I don't have a specific example to bring, but it happens in many cases that refactoring from pipe
to flow
causes the inferred type of the expression to change.
The transform from a => foo(a)
to foo
is technically an eta-reduction, which is safe in theory, but not in TypeScript.
For this reason, I'm not fully convinced about implementing this as a rule/fix, since it may lead to unwanted results.
@thewilkybarkid thank you so much, I'm sorry about leaving you hanging on #64, I haven't had a minute to review it, since schools are closed in Italy and this complicated my personal situation a bit 😩
I hope I'll find a minute soon! Thanks for the patience
Absolutely no problem. Can commit some work time to have a crack at some of these, but don't just want to trigger the usual open-source problem of being demanding. 😅
by the way, this specific suggestion may not be a safe refactor in 100% cases, due to type inference.
I don't have a specific example to bring, but it happens in many cases that refactoring from
pipe
toflow
causes the inferred type of the expression to change.The transform from
a => foo(a)
tofoo
is technically an eta-reduction, which is safe in theory, but not in TypeScript.For this reason, I'm not fully convinced about implementing this as a rule/fix, since it may lead to unwanted results.
It'd be interesting to find real cases where it is unsafe, and see if it's possible to exclude them...
one case I remember (but I don't have time to reproduce fully right now) is when working with Do
/ bind
in fp-ts: using point-free style (i.e. flow
-like calls) there for the bind messes up the inference of the "scope" that's being carried on.
I've discussed this some time ago with @gcanti and I remember he being skeptical about this as well