Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [CLI] Fix filtering of projects (relates to `--projects` or `--ignored-projects` parameter) ([#914](https://github.com/josefpihrt/roslynator/pull/914)).
- Refactoring "Add using directive" (RR0014) now works when file-scoped namespace is used ([#932](https://github.com/josefpihrt/roslynator/pull/932)).
- Add parentheses if necessary in a code fix for [RCS1197](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1197.md) ([#928](https://github.com/josefpihrt/roslynator/pull/928) by @karl-sjogren).

-----
<!-- Content below does not adhere to 'Keep a Changelog' format -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private static InvocationExpressionSyntax CreateInvocationExpression(
Argument(
SubtractExpression(
SimpleMemberAccessExpression(invocationInfo.Expression, IdentifierName("Length")),
arguments[0].Expression)));
arguments[0].Expression.Parenthesize())));

return CreateNewInvocationExpression(outerInvocationExpression, "Append", argumentList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,42 @@ void M()
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.OptimizeStringBuilderAppendCall)]
public async Task Test_Substring_Int32_Int32_Calculation()
{
await VerifyDiagnosticAndFixAsync(@"
using System.Text;

class C
{
void M()
{
string s = null;
var start = 2;
var len = 5;
var sb = new StringBuilder();

sb.Append([|s.Substring(start + len)|]);
}
}
", @"
using System.Text;

class C
{
void M()
{
string s = null;
var start = 2;
var len = 5;
var sb = new StringBuilder();

sb.Append(s, start + len, s.Length - (start + len));
}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.OptimizeStringBuilderAppendCall)]
public async Task Test_Substring_Int32()
{
Expand Down