fsprojects / fsprojects/FSharpLint

feat: Avoid double-lookup dictionaries: .ContainsKey key followed by indexer call .[key]

Open
#706 1 comment 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.