Enforce braces on all control-flow bodies in the C# emitter (cop)#11062
Open
JoshLove-msft wants to merge 2 commits into
Open
Enforce braces on all control-flow bodies in the C# emitter (cop)#11062JoshLove-msft wants to merge 2 commits into
JoshLove-msft wants to merge 2 commits into
Conversation
Replace the line-text regex heuristic in the C# emitter braces cop rule with the code provider's structural parse (Statement.Braced, Children, isControlFlow). This removes the prior false positives on multi-line conditions and recognizes else if chains correctly. The rule preserves the existing policy: only inline same-line control-flow bodies are reported; Allman next-line bodies remain allowed. Bump the pinned cop release to v2026.6.23.2, where the structural braces support is available and validated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
jsquire
approved these changes
Jun 23, 2026
Contributor
|
No changes needing a change description found. |
Extend braces.cop to flag every unbraced control-flow body (inline and Allman next-line), not just inline bodies. Add braces to the 179 existing violations via the IDE0011 add-braces fixer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgrades the C# emitter
braces.copcop 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 unbracedif/else/for/foreach/whilebody, whether written inline or on its own line (Allman). Idiomaticelse ifchains (an unbracedelsewhose child is anif) are excluded, while the innerifis still checked.cop-checks/main.cop— wires the predicate tocb.Statementswith an updated violation message.eng/scripts/Invoke-Cop.ps1— bumped the pinned cop releasev2026.6.10.1→v2026.6.23.2(structural braces support)..csfiles by adding braces via the Roslyn IDE0011 add-braces fixer (dotnet format style).Validation
npm run copreportscop checks passed.(0 violations).dotnet build Microsoft.TypeSpec.Generator.sln -c Releasesucceeds with 0 warnings / 0 errors (StyleCop clean).