You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SA1117: Add a code fix for inconsistent parameter lines - #4353
SA1117 reports parameter and argument lists whose items are inconsistently split across lines, but had no code fix. This adds a fix that places each list item on a separate line with indentation based on the opening delimiter, preserving comments and supporting parameter, argument, attribute, and array-rank lists. The action text is localized in the existing Russian and Chinese resources.
The regression test failed before the fix because no applicable code action was offered. The analyzer is unchanged; the implementation runs only when the user invokes the code fix, so analyzer performance is unaffected.
Validation: the C# 6 and C# 15 SA1117 suites pass (76 and 99 tests), and the test project builds with zero warnings.
Allow parameter and argument lists with inconsistent line breaks to be reformatted as one item per line.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Avoid offering a fix for omitted array-rank sizes and preserve multiline item indentation when splitting lists.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The omitted-rank guard still misses arrays nested in arguments. For Consume(new int[1][,,\n]);, FindToken returns ], and GetContainingList walks past the rank to the enclosing invocation's argument list. Its argument has a nonempty span, so an action is offered, but invoking it throws at elements.Count < 2. Reject empty diagnostic spans before registering the action, and add a nested-array regression test alongside the standalone omitted-rank test.
Adjust each moved multiline item relative to its existing indentation so trailing lambdas remain formatted consistently.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Do not offer a fix for zero-width diagnostics that resolve to an enclosing argument list.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The omitted-rank guard still misses arrays nested in arguments.
Added an early guard for zero-width diagnostic spans and a nested Consume(new int[1][,, ...]) regression test. The code fix is not offered for the enclosing invocation argument in this case.
The omitted-rank guard still fails when the array is nested in an argument, such as Bar(new int[1][,,\n]); with Bar(object value). The zero-width diagnostic at ] resolves to the enclosing argument list, which passes the guard because its argument is nonempty. Invoking the action then throws at the single-element check. Reject empty diagnostic spans before token lookup, and add a regression asserting that no action is offered for this nested case.
Adjust continuation lines for already-multiline elements
Continuation lines also need adjustment when an element already starts on a new line. With Bar(1, 2, at eight spaces followed by a multiline lambda at eight spaces, the fix moves the lambda's first line to twelve spaces but leaves its braces at eight and its body at twelve. startsOnSameLine is false, so the continuation tokens are skipped. Apply the indentation adjustment whenever the element's first-line indentation changes, and add a regression for this already-multiline case.
Preserve nested indentation when a multiline item moves either direction, including trivia on both sides of tokens and blank lines.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Shift continuations whenever a list item moves to a different indentation, including items that already start on a separate line.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Continuation lines also need adjustment when an element already starts on a new line.
The fix now shifts multiline continuations whenever the item's original line indentation differs from the target, whether the item originally began inline or on a separate line. Added regression coverage for the already-multiline argument; the nested omitted-rank case is covered by an empty-diagnostic-span guard and its own test.
An argument that already starts on a new line still has its first token moved to targetIndentation, but startsOnSameLine prevents its continuation lines from moving. For example:
Bar(()=>{Work();},2,3);
Fixing SA1117 moves the lambda header from 8 to 12 spaces while leaving its braces/body at 8/12 spaces. Apply the indentation adjustment whenever the element's indentation changes, not only when it follows the delimiter on the same line. Add a regression test with a multiline argument already starting on a separate line.
When an item follows a preserved // comment, its old indentation after the newline is copied unchanged. For Bar(1, // comment\n 2, 3); with the call indented eight spaces, the comment and other arguments move to twelve spaces, but 2 stays at eight. A multiline lambda in that position also keeps its old header indentation while its braces and body shift. Reindent the retained first-token trivia and add regression tests for a commented argument and a commented multiline lambda whose indentation must change.
For Bar(1, 2,\n() =>\n{\n Work();\n});, the lambda's braces start at column zero and have empty leading trivia. ShiftTrivia therefore returns an empty list, leaving the braces at column zero while the lambda header and body move right. Insert indentation when a continuation token starts a line with empty trivia and the element's original indentation is empty. Add a column-zero regression; the existing multiline tests all have indentation whitespace.
❌ Patch coverage is 87.83270% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.62%. Comparing base (abc4947) to head (1abc1d4). ⚠️ Report is 1 commits behind head on master.
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
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.
Fixes #1504
SA1117 reports parameter and argument lists whose items are inconsistently split across lines, but had no code fix. This adds a fix that places each list item on a separate line with indentation based on the opening delimiter, preserving comments and supporting parameter, argument, attribute, and array-rank lists. The action text is localized in the existing Russian and Chinese resources.
The regression test failed before the fix because no applicable code action was offered. The analyzer is unchanged; the implementation runs only when the user invokes the code fix, so analyzer performance is unaffected.
Validation: the C# 6 and C# 15 SA1117 suites pass (76 and 99 tests), and the test project builds with zero warnings.