Remove no-op string.Format calls with single message argument#123842
Remove no-op string.Format calls with single message argument#123842stephentoub merged 2 commits intomainfrom
Conversation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
There are also $ git grep -P '\$"(?![^"]*\{)[^"]*"' ':/*.cs' | wc -l
2953 |
It is common for people to use |
Btw, the 'structured logging' in ASP.NET doesn't require
Cool. They can apply the same optimization to |
|
There was a problem hiding this comment.
Pull request overview
This PR removes unnecessary string.Format() wrapper calls where a single string literal is passed without any format arguments. This is a code cleanup that improves readability and reduces unnecessary method call overhead.
Changes:
- Removed 239 no-op
string.Format("message")calls across 18 files - All changes are in test files and the GCLogParser tool (no production code affected)
- Every removed call was verified to have no format placeholders in the string
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Threading.Tasks.Parallel/tests/ParallelStateTest.cs | Removed 2 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/TaskScheduler/TaskSchedulerTests.cs | Removed 8 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskStatusTest.cs | Removed 3 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRunSyncTests.cs | Removed 7 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests_Core.cs | Removed numerous no-op string.Format calls from Assert.Fail statements in task completion tests |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskRtTests.cs | Removed 4 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskFromAsyncTest.cs | Removed 6 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskCreateTest.cs | Removed 3 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWith_ContFuncAndActionWithArgsTests.cs | Removed 7 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithTests.cs | Removed 10 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWithAllAnyTests.cs | Removed 6 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAnyTests.cs | Removed 5 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskContinueWhenAllTests.cs | Removed 3 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/Task/TaskCancelWaitTest.cs | Removed 7 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/System.Runtime.CompilerServices/YieldAwaitableTests.cs | Removed 6 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/CancellationTokenTests.cs | Removed 4 no-op string.Format calls from Assert.Fail statements |
| src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/TypeInfoFromProjectN/TypeInfo_PropertyTests.cs | Removed 2 no-op string.Format calls from Assert.True/False statements |
| src/coreclr/tools/GCLogParser/parse-hb-log.cs | Removed 2 no-op string.Format calls used for string concatenation |
Description
string.Format("message")with no format arguments is a no-op. This PR removes the unnecessary wrapper, replacing it with just the string literal.Similar to #123834 which addressed
SR.Formatcalls.Changes
Example
Files Changed
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.