Commit c5d3e9f
Enforce braces on all control-flow bodies in the C# emitter (cop) (#11062)
Upgrades the C# emitter `braces.cop` cop rule to use the cop library's
new structural braces support, and extends it to enforce braces on
**every** control-flow body.
## Changes
- **`cop-checks/braces.cop`** — replaced the previous line-text regex
heuristic with the code provider's structural parse (`Statement.Braced`
/ `Statement.Children` / `isControlFlow`). Flags any unbraced `if` /
`else` / `for` / `foreach` / `while` body, whether written inline or on
its own line (Allman). Idiomatic `else if` chains (an unbraced `else`
whose child is an `if`) are excluded, while the inner `if` is still
checked.
- **`cop-checks/main.cop`** — wires the predicate to `cb.Statements`
with an updated violation message.
- **`eng/scripts/Invoke-Cop.ps1`** — bumped the pinned cop release
`v2026.6.10.1` → `v2026.6.23.2` (structural braces support).
- **179 existing violations fixed** across 77 `.cs` files by adding
braces via the Roslyn IDE0011 add-braces fixer (`dotnet format style`).
## Validation
- `npm run cop` reports `cop checks passed.` (0 violations).
- `dotnet build Microsoft.TypeSpec.Generator.sln -c Release` succeeds
with 0 warnings / 0 errors (StyleCop clean).
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 85ff828 commit c5d3e9f
80 files changed
Lines changed: 476 additions & 87 deletions
File tree
- packages/http-client-csharp
- cop-checks
- eng/scripts
- generator
- Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src
- Microsoft.TypeSpec.Generator.ClientModel
- src/Providers
- test/Providers
- Definitions
- MrwSerializationTypeDefinitions
- RestClientProviders
- Microsoft.TypeSpec.Generator.Input
- src
- Extensions
- InputTypes
- Serialization/Examples
- test
- Microsoft.TypeSpec.Generator
- perf
- src
- Expressions
- PostProcessing
- Primitives
- Providers
- Snippets
- SourceInput
- Statements
- Utilities
- Writers
- test
- Providers
- EnumProviders
- ModelFactories
- Utilities
- Writers
- common
- TestProjects/Spector.Tests
- Http
- Authentication/OAuth2
- Client/Structure/TwoOperationGroup
- Parameters/Spread
- Resiliency/SrvDriven/V2
- Server
- Endpoint/NotDefined
- Path/Single
- SpecialHeaders/Repeatability
- SpecialWords
- Infrastructure
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
6 | | - | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| 14 | + | |
11 | 15 | | |
12 | | - | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | | - | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| 23 | + | |
19 | 24 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
24 | 31 | | |
25 | | - | |
26 | | - | |
27 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | | - | |
34 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
35 | 45 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| 53 | + | |
51 | 54 | | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| |||
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
| 68 | + | |
64 | 69 | | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
| 78 | + | |
72 | 79 | | |
| 80 | + | |
73 | 81 | | |
74 | 82 | | |
| 83 | + | |
75 | 84 | | |
| 85 | + | |
76 | 86 | | |
77 | 87 | | |
78 | 88 | | |
| |||
101 | 111 | | |
102 | 112 | | |
103 | 113 | | |
| 114 | + | |
104 | 115 | | |
| 116 | + | |
105 | 117 | | |
106 | 118 | | |
107 | 119 | | |
| |||
116 | 128 | | |
117 | 129 | | |
118 | 130 | | |
| 131 | + | |
119 | 132 | | |
| 133 | + | |
120 | 134 | | |
121 | 135 | | |
122 | 136 | | |
| |||
130 | 144 | | |
131 | 145 | | |
132 | 146 | | |
| 147 | + | |
133 | 148 | | |
| 149 | + | |
134 | 150 | | |
135 | 151 | | |
| 152 | + | |
136 | 153 | | |
| 154 | + | |
137 | 155 | | |
138 | 156 | | |
139 | 157 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
340 | 341 | | |
| 342 | + | |
341 | 343 | | |
342 | 344 | | |
343 | 345 | | |
| |||
356 | 358 | | |
357 | 359 | | |
358 | 360 | | |
| 361 | + | |
359 | 362 | | |
| 363 | + | |
360 | 364 | | |
361 | 365 | | |
362 | 366 | | |
363 | 367 | | |
364 | 368 | | |
365 | 369 | | |
366 | 370 | | |
| 371 | + | |
367 | 372 | | |
| 373 | + | |
368 | 374 | | |
369 | 375 | | |
370 | 376 | | |
| |||
373 | 379 | | |
374 | 380 | | |
375 | 381 | | |
| 382 | + | |
376 | 383 | | |
| 384 | + | |
377 | 385 | | |
378 | 386 | | |
379 | 387 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
| 508 | + | |
508 | 509 | | |
| 510 | + | |
| 511 | + | |
509 | 512 | | |
510 | 513 | | |
511 | 514 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1927 | 1927 | | |
1928 | 1928 | | |
1929 | 1929 | | |
| 1930 | + | |
1930 | 1931 | | |
| 1932 | + | |
1931 | 1933 | | |
1932 | 1934 | | |
1933 | 1935 | | |
| |||
2254 | 2256 | | |
2255 | 2257 | | |
2256 | 2258 | | |
| 2259 | + | |
2257 | 2260 | | |
| 2261 | + | |
2258 | 2262 | | |
2259 | 2263 | | |
2260 | 2264 | | |
2261 | 2265 | | |
2262 | 2266 | | |
2263 | 2267 | | |
| 2268 | + | |
2264 | 2269 | | |
2265 | 2270 | | |
| 2271 | + | |
2266 | 2272 | | |
2267 | 2273 | | |
| 2274 | + | |
2268 | 2275 | | |
| 2276 | + | |
2269 | 2277 | | |
2270 | 2278 | | |
2271 | 2279 | | |
2272 | 2280 | | |
2273 | 2281 | | |
2274 | 2282 | | |
2275 | 2283 | | |
| 2284 | + | |
2276 | 2285 | | |
| 2286 | + | |
2277 | 2287 | | |
2278 | 2288 | | |
2279 | 2289 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
| 472 | + | |
472 | 473 | | |
| 474 | + | |
473 | 475 | | |
474 | 476 | | |
475 | 477 | | |
| |||
993 | 995 | | |
994 | 996 | | |
995 | 997 | | |
| 998 | + | |
996 | 999 | | |
| 1000 | + | |
997 | 1001 | | |
998 | 1002 | | |
999 | 1003 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| 281 | + | |
281 | 282 | | |
| 283 | + | |
282 | 284 | | |
283 | 285 | | |
284 | 286 | | |
| |||
0 commit comments