-
Notifications
You must be signed in to change notification settings - Fork 8
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
Turn folding an either into an option into an option.fromEither #64
base: main
Are you sure you want to change the base?
Conversation
src/rules/prefer-constructor.ts
Outdated
calleeIdentifier, | ||
option.filter((callee) => callee.name === "fold"), | ||
option.chain(flow((callee) => callee.parent, option.fromNullable)), | ||
option.filter((parent): parent is TSESTree.MemberExpression => parent.type === AST_NODE_TYPES.MemberExpression), | ||
option.map((parent) => parent.object), | ||
option.filter((object): object is TSESTree.Identifier => object.type === AST_NODE_TYPES.Identifier), | ||
option.exists((object) => object.name === 'either') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently looking for a way to determine if it's either.fold
, even if it's E.fold
or whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two ways:
- use the type information (more accurate, but slower)
- determine whether the "prefix" is imported from
fp-ts
(accurate enough, and faster because it's only a syntactic lookup)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a closer look as soon as I have minute
src/rules/prefer-constructor.ts
Outdated
isLazyValue(utils, "Option", "none"), | ||
isCall(utils, "Option", "some") | ||
])), | ||
option.bind("namespace", flow(readonlyNonEmptyArray.head, findNamespace(utils))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't ideal, would rather use the imports than reading the code.
src/rules/prefer-constructor.ts
Outdated
)) | ||
) | ||
|
||
const isCall = <T extends TSESTree.Node>(utils: ContextUtils, module: Module, name: string) => (node: T) => pipe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s a generic here due to type inference problems.
src/rules/prefer-constructor.ts
Outdated
calleeIdentifier, | ||
option.filter(hasName("constant")), | ||
option.chain(typeOfNode), | ||
option.exists(isFromModule("function")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably just check it’s from fp-ts rather than the type check.
(Guessing @kanbanbot doesn't respond to making PRs ready for review...) |
@thewilkybarkid hehe, no that's very much a human process. There's quite a lot going on but I'll do my best to review this as soon as I have time :-) Thanks! |
Ah, was wondering what it was as the account looks empty! No rush with it, thanks. |
Closes #2520131
Very much a work-in-progress while I get used to the code base, but this is an attempt to implement #61.