fsprojects / fsprojects/FSharpLint
Rule for `List.length l = 1` and `l.Length = 1`
Nobody has claimed this yet.
- Dominant language
- F#
- Stars
- 327
- Forks
- 74
- PR merge metrics
- No merged PRs in 30d
Description
Taking a discussion running on https://github.com/dotnet/fsharp/pull/12998#issuecomment-1101939053 related to replacing list.Length = 1 with cheaper construct.
@smoothdeveloper: Wondering if this wouldn't be worth a rule in FSharpLint?
@knocte : Good idea, although it would be much easier to make the violators of the rule respect it if there was an isSingleton function in FSharp's List, shouldn't we add that function first?
@knocte I don't know the inner philosophy of FSharpLint, if I had to split it the way your question suggests:
- law is the law, it is applicable, but not ideal, the resulting code is not as good as if you defined your own abstraction (
List.isSingletonhere), what matters is, helps the developer to save CPU cycles, more than how the code is changed - the law is only mostly applicable if it becomes path of least resistance, least surprise, most sense, to most, and increasing likelyhood of "code I love" ratings from @dsyme is what matters
First one is like mechanic empathy, the second one is developer empathy, and FSharpLint is probably helping setting good balance where it makes most sense (those easy cases).
I'd say considering the discussion stems from an internal compiler member for now, chance of the fix making it to FSharp.Core soon are not the most favorable, for delaying having the check, for those looking to refactor the code already (they can introduce type extension for it manually), if the check can be added without a lot of work.
We can suggest = [] ... edit. not! we can only suggest to have the module extension, which kind of answers the question.
I'd just like to have this warning or the FCS analyser thing, to be running mostly, and fixing the code is exercise left to the reader.
cc: @auduchinok
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the discussion linked in the issue and inspect the existing FSharpLint rule implementations and tests. Clarify whether the rule should cover both List.length l = 1 and l.Length = 1, and what replacement or warning it should recommend. Done means the agreed cases are detected consistently with tests for the selected forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100