Skip to content

Commit

Permalink
Update message of S4635 (#7435)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-marichal authored Jun 16, 2023
1 parent b6ce681 commit 6cde32d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ namespace IntentionalFindings
public static class S4635
{
public static int TestMethod() =>
"Test".Substring(1).IndexOf('t', StringComparison.InvariantCulture); // Noncompliant (S4635) {{Replace 'IndexOf' with the overload that accepts an offset parameter.}}
"Test".Substring(1).IndexOf('t', StringComparison.InvariantCulture); // Noncompliant (S4635) {{Replace 'IndexOf' with the overload that accepts a startIndex parameter.}}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace SonarAnalyzer.Rules.CSharp
public sealed class StringOffsetMethods : SonarDiagnosticAnalyzer
{
internal const string DiagnosticId = "S4635";
private const string MessageFormat = "Replace '{0}' with the overload that accepts an offset parameter.";
private const string MessageFormat = "Replace '{0}' with the overload that accepts a startIndex parameter.";

private static readonly DiagnosticDescriptor rule =
DescriptorFactory.Create(DiagnosticId, MessageFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class StringOffsetMethods
{
public StringOffsetMethods()
{
"""Test""".Substring(1).IndexOf('t'); // Noncompliant {{Replace 'IndexOf' with the overload that accepts an offset parameter.}}
"""Test""".Substring(1).IndexOf('t'); // Noncompliant {{Replace 'IndexOf' with the overload that accepts a startIndex parameter.}}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class StringOffsetMethods
{
public StringOffsetMethods()
{
"Test".Substring(1).IndexOf('t'); // Noncompliant {{Replace 'IndexOf' with the overload that accepts an offset parameter.}}
"Test".Substring(1).IndexOf('t'); // Noncompliant {{Replace 'IndexOf' with the overload that accepts a startIndex parameter.}}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}

Expand Down Expand Up @@ -34,23 +34,23 @@ public void StringOffsetMethodsCases(string x)
"Test".IndexOfAny(new[] { 't' });
"Test".IndexOfAny(new[] { 't' }, 2);
"Test".IndexOfAny(new[] { 't' }, 1, 2);
"Test".Substring(1).IndexOfAny(new[] { 't' }); // Noncompliant {{Replace 'IndexOfAny' with the overload that accepts an offset parameter.}}
"Test".Substring(1).IndexOfAny(new[] { 't' }); // Noncompliant {{Replace 'IndexOfAny' with the overload that accepts a startIndex parameter.}}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

"Test".LastIndexOf('t');
"Test".LastIndexOf('t', 1);
"Test".LastIndexOf("t");
"Test".LastIndexOf("t", 1);
"Test".LastIndexOf("t", 1, 3);
"Test".Substring(1).LastIndexOf('t'); // Noncompliant {{Replace 'LastIndexOf' with the overload that accepts an offset parameter.}}
"Test".Substring(1).LastIndexOf('t'); // Noncompliant {{Replace 'LastIndexOf' with the overload that accepts a startIndex parameter.}}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"Test".Substring(1).LastIndexOf("t"); // Noncompliant


"Test".LastIndexOfAny(new[] { 't' });
"Test".LastIndexOfAny(new[] { 't' }, 1);
"Test".LastIndexOfAny(new[] { 't' }, 1, 3);
"Test".Substring(1).LastIndexOfAny(new[] { 't' }); // Noncompliant {{Replace 'LastIndexOfAny' with the overload that accepts an offset parameter.}}
"Test".Substring(1).LastIndexOfAny(new[] { 't' }); // Noncompliant {{Replace 'LastIndexOfAny' with the overload that accepts a startIndex parameter.}}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

x.Substring(1).IndexOf('t'); // Noncompliant
Expand Down

0 comments on commit 6cde32d

Please sign in to comment.