-
Notifications
You must be signed in to change notification settings - Fork 75
Add new rule NoPartialFunctions #453
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
Conversation
| | PatternMatch | ||
| | Function of functionName:string | ||
|
|
||
| let private partialFunctionIdentifiers = |
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.
@Krzysztof-Cieslak I added all the partial collection functions that I'm aware of, anything else we should add?
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.
@jgardella how about Map.Item -> Map.TryFind
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.
@knocte At the moment it'll require a little bit more work to handle methods on an object instance (some type checking) - might be worth another PR for that, we could potentially add:
Map.find -> Map.tryFind
Map.findKey -> Map.tryFindKey
|
who needs to review this? would be nice to get it merged |
|
Just tried to resolve the conflicts in the Github UI, was not a good idea 😅 |
|
@knocte Looks good to go in. Potentially worth considering having these be hints although there is the downside which is that we'd lose the applicable documentation page |
FSharpLint's new recently added rule[1] complains about function Seq.tail being a partial function, so we need an alternative before all try-prefixed versions get included in FSharp.Core[2]. This is not actually a tryTail function but at least most uses of Seq.tail use a Seq.head before it, so we can replace both calls to Seq.(try)head & Seq.tail with a single-call to this Seq.tryHeadTail which shouldn't be considered a partial function anymore (even if it calls Seq.tail underneath). Adding it in FSharpx.Collections would be a nice stopgap instead of having to include this function in every F# project that wants to enable this new FSharpLint rule. [1] fsprojects/FSharpLint#453 [2] fsharp/fslang-suggestions#803
FSharpLint's new recently added rule[1] complains about function Seq.tail being a partial function, so we need an alternative before all try-prefixed versions get included in FSharp.Core[2]. This is not actually a tryTail function but at least most uses of Seq.tail use a Seq.head before it, so we can replace both calls to Seq.(try)head & Seq.tail with a single-call to this Seq.tryHeadTail which shouldn't be considered a partial function anymore (even if it calls Seq.tail underneath). Adding it in FSharpx.Collections would be a nice stopgap instead of having to include this function in every F# project that wants to enable this new FSharpLint rule. [1] fsprojects/FSharpLint#453 [2] fsharp/fslang-suggestions#803
FSharpLint's new recently added rule[1] complains about function Seq.tail being a partial function, so we need an alternative before all try-prefixed versions get included in FSharp.Core[2]. This is not actually a tryTail function but at least most uses of Seq.tail use a Seq.head before it, so we can replace both calls to Seq.(try)head & Seq.tail with a single-call to this Seq.tryHeadTail which shouldn't be considered a partial function anymore (even if it calls Seq.tail underneath). Adding it in FSharpx.Collections would be a nice stopgap instead of having to include this function in every F# project that wants to enable this new FSharpLint rule. [1] fsprojects/FSharpLint#453 [2] fsharp/fslang-suggestions#803
FSharpLint's new recently added rule[1] complains about function Seq.tail being a partial function, so we need an alternative before all try-prefixed versions get included in FSharp.Core[2]. This is not actually a tryTail function but at least most uses of Seq.tail use a Seq.head before it, so we can replace both calls to Seq.(try)head & Seq.tail with a single-call to this Seq.tryHeadTail which shouldn't be considered a partial function anymore (even if it calls Seq.tail underneath). Adding it in FSharpx.Collections would be a nice stopgap instead of having to include this function in every F# project that wants to enable this new FSharpLint rule. [1] fsprojects/FSharpLint#453 [2] fsharp/fslang-suggestions#803
Adds a new rule to disallow partial functions. The rule will suggest to use non-partial functions or pattern matching instead.