Skip to content

[Mouse Jump] Fix CA2227 in layout builders - #50733

Closed
matthudson wants to merge 1 commit into
microsoft:mainfrom
matthudson:feature/ca2227-mousejump-models
Closed

matthudson wants to merge 1 commit into
microsoft:mainfrom
matthudson:feature/ca2227-mousejump-models

Conversation

@matthudson

@matthudson matthudson commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Resolves the CA2227 warnings in Mouse Jump's layout-builder model by making its nested collection properties init-only.

Existing mutation paths and object-initializer construction remain unchanged.

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Changes the nested layout-builder collection properties to use init-only setters.
  • Retains the existing mutable collection instances and all current object-initializer call sites.
  • Does not change layout calculation or rendering behavior.

Validation Steps Performed

  • Built MouseJump.Common.UnitTests with AnalysisMode=All; no targeted CA2227 warnings remain.
  • Ran the Mouse Jump unit tests: 22 passed, 0 failed, 1 pre-existing performance test skipped.
  • Ran git diff --check origin/main...HEAD: clean.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@matthudson

Copy link
Copy Markdown
Contributor Author

Superseded by #50741, which combines these small isolated CA2227 fixes into one focused and fully validated pull request. Closing this draft to keep the review queue clear.

@matthudson matthudson closed this Sep 23, 2026
Yu Leng (moooyo) pushed a commit that referenced this pull request Sep 23, 2026
…#50741)

## Summary of the Pull Request

Resolves isolated CA2227 collection-property warnings in Command Palette
extension settings, Mouse Jump layout models, and Hosts File Editor.

The changes prevent replacement of collection properties while
preserving their existing mutable contents, serialization behavior,
object-initializer construction, and UI binding behavior.

## PR Checklist

- [ ] Closes: N/A — follow-up to #11646 and #50702
- [x] Communication: Continuation requested during review of #50702
- [x] Tests: Focused CmdPal, Mouse Jump, and Hosts builds and tests pass
- [x] Localization: N/A — no user-facing strings changed
- [x] Dev docs: N/A — no developer-facing behavior changed
- [x] New binaries: N/A
- [x] Documentation updated: N/A — internal analyzer cleanup only

## Detailed Description of the Pull Request / Additional comments

### Command Palette

- Makes extension setting collection properties init-only.
- Preserves collection mutability and existing object-initializer
construction.
- Adds coverage confirming ChoiceSetSetting retains and exposes the
supplied choices.
- This narrows a public extension API by preventing post-construction
collection replacement. As discussed on the superseded #50729, the
compatibility risk is considered low because collection contents remain
mutable.

### Mouse Jump

- Makes the nested layout-builder collection properties init-only.
- Retains existing object-initializer construction and subsequent
content mutation.
- Does not change layout calculation or rendering behavior.

### Hosts File Editor

- Makes the Entries collection setter private so callers cannot replace
the collection directly.
- Changes the associated ItemsSource binding from two-way to one-way.
- Preserves collection replacement inside the view model and its
existing PropertyChanged notification after reload.

These were originally opened separately as #50729, #50733, and #50734.
They are combined here because each is a small, isolated CA2227
correction with focused validation and no shared behavioral dependency.

## Visual evidence

No visual change is intended. The Hosts File Editor below was launched
from the exact combined PR commit after a successful x64 Release build;
the affected entries view renders normally after the binding-mode
change.

![Hosts File Editor rendered from PR
build](https://raw.githubusercontent.com/matthudson/PowerToys/76e78f768325e6cf1f9313a4059ceb2a748a82a9/hosts-ca2227-visual-evidence.png)

## Validation Steps Performed

- Built the Command Palette extension test project successfully.
- Ran Command Palette tests: **706 passed, 1 skipped, 0 failed**.
- Built the Mouse Jump test project successfully.
- Ran Mouse Jump tests: **31 passed, 0 failed**.
- Built the Hosts File Editor test project successfully.
- Ran Hosts File Editor tests: **151 passed, 0 failed**.
- Ran git diff --check origin/main...HEAD: clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant