fsprojects / fsprojects/FSharpLint
feat: Avoid double-lookup dictionaries: .ContainsKey key followed by indexer call .[key]
Open
Nobody has claimed this yet.
- Dominant language
- F#
- Stars
- 327
- Forks
- 74
- PR merge metrics
- No merged PRs in 30d
Description
Avoid double-lookup dictionaries:
.ContainsKey key followed by .[key] should be replaced with .TryGetValue x
for example:
match xs.ContainsKey x with
| true -> ... xs.[x] ...
| false -> ///...
should be replaced with
match xs.TryGetValue x with
| true, xVal -> ... xVal ...
| false, _ -> ///...
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
The issue names no files or tests; start by locating the existing F# lint rules for dictionary usage and their test coverage. Use the provided ContainsKey/indexer and TryGetValue examples to define the expected diagnostic and replacement behavior, then verify the relevant lint tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- performance, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100