dotnet / dotnet/wpf

Code Style Initiative

Open
#10,270 6 comments 6 reactions 0 assignees View on GitHub
area-Styling Good First Issue help wanted
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

## Description
This is a tracker issue to ensure that our code style and guidelines align with the standards set by dotnet. This is a follow-up of the [issue ](#10017 ).

As in the [PR](#10109) we have added .editorconfig that helps us ensure these style requirements during the build. Given the current state of code, quite a few of these analyzers are disabled in _src/Microsoft.DotNet.Wpf/src_ and _src/Microsoft.DotNet.Wpf/cycle-breakers_ in their respective .editorconfig. The overall idea is to get rid of .editorconfig(s) in the _src_ and have a single .editorconfig (the one in the root).

## Steps to proceed with the task
Assume that we are fixing **IDE0044: Make field readonly**
1) Remove the analyzer's severity from .editorconfig in _src_ folder. It is generally added as `dotnet_diagnostic.IDE0044.severity = suggestion`.
2) Using the script [start-vs.cmd](https://github.com/dotnet/wpf/blob/main/start-vs.cmd), open WPF in Visual Studio
3) Build the solution (if not already built).
4) The build is likely to fail with errors/warnings of IDE0044.
5) Click on any of the warning/error from `Error List` window, and it should navigate to the line that violates the rule.
6) On that line, use the shortcut `Ctrl + .` or right click to find `Quick Actions and Refactoring`
7) It should open the possible fixes, one of which would be related to the warning being fixed (as in the image below).
![Image](https://github.com/user-attachments/assets/d5d58ac2-d8df-4847-bde8-9124c8baeec5)
8) As in the image above, click on Fix all occurrences in **Solution**, which should resolve the warning in the solution.

### Alternatively
After the step 1, use the command
`dotnet format analyzers --diagnostics IDE0044 --severity warn .\src\Microsoft.DotNet.Wpf\src\PresentationBuildTasks\PresentationBuildTasks.csproj`. This will fix occurrences of IDE0044 violations in `PresentationBuildTasks.csproj`. Similarly, fix the occurrences in all the csproj.

## Raising the PR

- There should be no changes to the public API contract. If there are violations, instead of fixing them, suppress the warning.
- Apart from the suppressions, ensure that all the changes are automated.
- There should be no behavioral changes in these PRs; they should only comprise the fixes for these analyzer changes.
- Unless the changes in one resolution are very small (10-20 files), raise a single PR for a single fix. This will help in the easier review process.
- If fixing a single warning changes a lot of files (>=500), try creating sub-PRs for individual assemblies if that helps reduce the count.
- Name the PR with the pre-text [StyleCleanUp] for better visibility.
- As with other PRs, each PR will be taken for a test pass.
- Try branching out fixes on top of others to minimize merge conflicts. Let us know the order in which you would like the PRs to be taken.

## Warnings to be removed
Feel free to create individual sub-issues and assign it to yourself before picking up any of these.
- [ ] #10271
- [ ] CA1052
- [ ] CA1066
- [ ] CA1067
- [ ] CA1070
- [ ] CA1310
- [ ] CA1419
- [x] #10294
- [ ] CA1510
- [ ] CA1512
- [ ] CA1513
- [ ] CA1514
- [ ] CA1725
- [ ] CA1802
- [ ] CA1805
- [ ] CA1810
- [ ] CA1815
- [ ] CA1821
- [ ] CA1822
- [ ] CA1823
- [ ] CA1825
- [ ] CA1834
- [ ] CA1838
- [x] #10298
- [x] #10299
- [x] #10297
- [ ] CA1851
- [ ] CA1852
- [ ] CA1853
- [ ] CA1854
- [ ] CA1858
- [ ] CA1859
- [ ] CA2011
- [ ] CA2019
- [ ] CA2020
- [ ] CA2201
- [ ] CA2207
- [ ] CA2208
- [ ] CA2211
- [ ] CA2219
- [ ] CA2242
- [x] #10282
- [x] #10296
- [ ] CA2300
- [ ] CA2302
- [ ] CA5350
- [ ] CA5351
- [ ] CA5362
- [ ] CA5394
- [x] CSIsNull001
- [x] CSIsNull002
- [ ] IDE0005
- [x] IDE0017
- [x] IDE0019
- [x] IDE0020
- [x] IDE0029
- [ ] IDE0030
- [ ] IDE0031
- [ ] IDE0034
- [ ] IDE0036
- [ ] IDE0040
- [ ] IDE0041
- [ ] IDE0044
- [ ] IDE0051
- [ ] IDE0052
- [x] IDE0057
- [ ] IDE0059
- [ ] IDE0060
- [ ] IDE0062
- [ ] IDE0063
- [ ] IDE0065
- [ ] IDE0066
- [ ] IDE0073
- [ ] IDE0074
- [ ] IDE0075
- [ ] IDE0076
- [ ] IDE0077
- [ ] IDE0078
- [ ] IDE0082
- [ ] IDE0100
- [x] #10272
- [ ] IDE0180
- [ ] IDE0251
- [ ] IDE0270
- [ ] IDE0300
- [ ] IDE1006
- [x] SA1001
- [x] SA1005
- [x] SA1014
- [x] SA1027
- [x] SA1028
- [x] SA1121
- [x] SA1129
- [x] SA1131
- [x] SA1206
- [ ] SA1400
- [x] SA1404
- [x] SA1408
- [x] SA1500
- [x] SA1505
- [x] SA1507
- [x] SA1508
- [x] SA1513
- [x] SA1518
- [ ] SYSLIB1045

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.