Skip to content

Commit 0b384ac

Browse files
Replace calls to obsolete SonarTreeReportingContextBase.ReportIssue overload (#9377)
1 parent 65f8533 commit 0b384ac

File tree

339 files changed

+461
-502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

339 files changed

+461
-502
lines changed

analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/ApiControllersShouldNotDeriveDirectlyFromController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private static void ReportIssue(SonarSymbolReportingContext context, INamedTypeS
9595

9696
foreach (var location in reportLocations)
9797
{
98-
context.ReportIssue(CSharpFacade.Instance.GeneratedCodeRecognizer, Diagnostic.Create(Rule, location));
98+
context.ReportIssue(CSharpFacade.Instance.GeneratedCodeRecognizer, Rule, location);
9999
}
100100
}
101101
}

analyzers/src/SonarAnalyzer.CSharp/Rules/CheckArgumentException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private static void CheckForIssue(SonarSyntaxNodeReportingContext analysisContex
5454

5555
if (objectCreation.ArgumentList == null || objectCreation.ArgumentList.Arguments.Count == 0)
5656
{
57-
analysisContext.ReportIssue(Diagnostic.Create(Rule, objectCreation.Expression.GetLocation(), ParameterLessConstructorMessage));
57+
analysisContext.ReportIssue(Rule, objectCreation.Expression, ParameterLessConstructorMessage);
5858
return;
5959
}
6060

@@ -75,7 +75,7 @@ private static void CheckForIssue(SonarSyntaxNodeReportingContext analysisContex
7575
var message = constructorMessageArgument.HasValue && methodArgumentNames.Contains(TakeOnlyBeforeDot(constructorMessageArgument))
7676
? ConstructorParametersInverted
7777
: string.Format(InvalidParameterName, constructorParameterArgument.Value);
78-
analysisContext.ReportIssue(Diagnostic.Create(Rule, objectCreation.Expression.GetLocation(), message));
78+
analysisContext.ReportIssue(Rule, objectCreation.Expression, message);
7979
}
8080
}
8181

analyzers/src/SonarAnalyzer.CSharp/Rules/CommentedOutCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private static void CheckTrivia(SonarSyntaxTreeReportingContext context, IEnumer
6262
&& !trivium.ToFullString().TrimStart().StartsWith("///", StringComparison.Ordinal)
6363
&& IsCode(trivium.ToString().Substring(CommentMarkLength)))
6464
{
65-
context.ReportIssue(Diagnostic.Create(Rule, trivium.GetLocation()));
65+
context.ReportIssue(Rule, trivium.GetLocation());
6666
shouldReport = false;
6767
}
6868
}
@@ -81,7 +81,7 @@ private static void CheckMultilineComment(SonarSyntaxTreeReportingContext contex
8181
var lineSpan = context.Tree.GetText().Lines[lineNumber].Span;
8282
var commentLineSpan = lineSpan.Intersection(trivia.GetLocation().SourceSpan);
8383
var location = Location.Create(context.Tree, commentLineSpan ?? lineSpan);
84-
context.ReportIssue(Diagnostic.Create(Rule, location));
84+
context.ReportIssue(Rule, location);
8585
return;
8686
}
8787
}

analyzers/src/SonarAnalyzer.CSharp/Rules/ComparableInterfaceImplementation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ protected override void Initialize(SonarAnalysisContext context) =>
7676

7777
if (membersToOverride.Any())
7878
{
79-
c.ReportIssue(Diagnostic.Create(
79+
c.ReportIssue(
8080
Rule,
81-
classDeclaration.Identifier.GetLocation(),
81+
classDeclaration.Identifier,
8282
string.Join(" or ", implementedComparableInterfaces),
83-
membersToOverride.JoinAnd()));
83+
membersToOverride.JoinAnd());
8484
}
8585
},
8686
SyntaxKind.ClassDeclaration,

analyzers/src/SonarAnalyzer.CSharp/Rules/CompareNaN.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ protected override void Initialize(SonarAnalysisContext context) =>
5151
: MessageFormatComparison;
5252

5353
c.ReportIssue(
54-
Diagnostic.Create(Rule,
55-
binaryExpressionSyntax.GetLocation(),
56-
string.Format(messageFormat, KnownTypeAliasMap[floatingPointType])));
54+
Rule,
55+
binaryExpressionSyntax,
56+
string.Format(messageFormat, KnownTypeAliasMap[floatingPointType]));
5757
}
5858
},
5959
SyntaxKind.GreaterThanExpression,

analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalsWithSameCondition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private static void CheckMatchingExpressionsInSucceedingStatements<T>(SonarSynta
5151
if (CSharpEquivalenceChecker.AreEquivalent(currentExpression, previousExpression)
5252
&& !ContainsPossibleUpdate(previousStatement, currentExpression, context.SemanticModel))
5353
{
54-
context.ReportIssue(Diagnostic.Create(Rule, currentExpression.GetLocation(), previousExpression.GetLineNumberToReport()));
54+
context.ReportIssue(Rule, currentExpression, previousExpression.GetLineNumberToReport().ToString());
5555
}
5656
}
5757
}

analyzers/src/SonarAnalyzer.CSharp/Rules/ConstructorArgumentValueShouldExist.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ protected override void ReportIssue(SonarSyntaxNodeReportingContext c, Attribute
5353
{
5454
var attributeSyntax =
5555
(AttributeSyntax)constructorArgumentAttribute.ApplicationSyntaxReference.GetSyntax();
56-
c.ReportIssue(Diagnostic.Create(rule,
57-
attributeSyntax.ArgumentList.Arguments[0].GetLocation()));
56+
c.ReportIssue(rule, attributeSyntax.ArgumentList.Arguments[0]);
5857
}
5958
}
6059
}

analyzers/src/SonarAnalyzer.CSharp/Rules/ConstructorOverridableCall.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ private static void CheckOverridableCallInConstructor(SonarSyntaxNodeReportingCo
6060
IsMethodOverridable(methodSymbol) &&
6161
enclosingSymbol.IsInType(methodSymbol.ContainingType))
6262
{
63-
context.ReportIssue(Diagnostic.Create(rule, invocationExpression.Expression.GetLocation(),
64-
methodSymbol.Name));
63+
context.ReportIssue(rule, invocationExpression.Expression, methodSymbol.Name);
6564
}
6665
}
6766

analyzers/src/SonarAnalyzer.CSharp/Rules/ControlCharacterInString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private static void CheckControlCharacter(SonarSyntaxNodeReportingContext c, str
113113
{
114114
if (EscapedControlCharacters.TryGetValue(text[charPos], out var escapeSequence))
115115
{
116-
c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation(), displayPosIncrement + charPos, escapeSequence));
116+
c.ReportIssue(Rule, c.Node, (displayPosIncrement + charPos).ToString(), escapeSequence);
117117
return;
118118
}
119119
}

analyzers/src/SonarAnalyzer.CSharp/Rules/CryptographicKeyShouldNotBeTooShort.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected override void Initialize(SonarAnalysisContext context)
111111
// https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsacryptoserviceprovider.keysize
112112
if (containingType.IsAny(KnownType.System_Security_Cryptography_DSACryptoServiceProvider, KnownType.System_Security_Cryptography_RSACryptoServiceProvider))
113113
{
114-
c.ReportIssue(Diagnostic.Create(Rule, assignment.GetLocation(), MinimalCommonKeyLength, CipherName(containingType), UselessAssignmentInfo));
114+
c.ReportIssue(Rule, assignment, MinimalCommonKeyLength.ToString(), CipherName(containingType), UselessAssignmentInfo);
115115
}
116116
else
117117
{
@@ -132,7 +132,7 @@ private void CheckAlgorithmCreation(SonarSyntaxNodeReportingContext c, ITypeSymb
132132

133133
if (containingType.IsAny(SystemSecurityCryptographyDsaRsa) && IsInvalidCommonKeyLength(c, firstParam))
134134
{
135-
c.ReportIssue(Diagnostic.Create(Rule, invocation.GetLocation(), MinimalCommonKeyLength, CipherName(containingType), string.Empty));
135+
c.ReportIssue(Rule, invocation, MinimalCommonKeyLength.ToString(), CipherName(containingType), string.Empty);
136136
}
137137
else
138138
{
@@ -173,7 +173,7 @@ private void CheckCurveNameKeyLength(SonarSyntaxNodeReportingContext c, SyntaxNo
173173
var match = namedEllipticCurve.SafeMatch(curveName);
174174
if (match.Success && int.TryParse(match.Groups["KeyLength"].Value, out var keyLength) && keyLength < MinimalEllipticCurveKeyLength)
175175
{
176-
c.ReportIssue(Diagnostic.Create(Rule, syntaxElement.GetLocation(), MinimalEllipticCurveKeyLength, "EC", string.Empty));
176+
c.ReportIssue(Rule, syntaxElement, MinimalEllipticCurveKeyLength.ToString(), "EC", string.Empty);
177177
}
178178
}
179179

@@ -184,7 +184,7 @@ private static void CheckSystemSecurityCryptographyAlgorithms(SonarSyntaxNodeRep
184184
if (containingType.Is(KnownType.System_Security_Cryptography_DSACryptoServiceProvider)
185185
|| (containingType.Is(KnownType.System_Security_Cryptography_RSACryptoServiceProvider) && HasDefaultSize(c, objectCreation.ArgumentList)))
186186
{
187-
c.ReportIssue(Diagnostic.Create(Rule, objectCreation.Expression.GetLocation(), MinimalCommonKeyLength, CipherName(containingType), string.Empty));
187+
c.ReportIssue(Rule, objectCreation.Expression, MinimalCommonKeyLength.ToString(), CipherName(containingType), string.Empty);
188188
}
189189
else
190190
{
@@ -204,7 +204,7 @@ private static void CheckGenericDsaRsaCryptographyAlgorithms(SonarSyntaxNodeRepo
204204
{
205205
if (containingType.DerivesFromAny(SystemSecurityCryptographyDsaRsa) && keyLengthSyntax != null && IsInvalidCommonKeyLength(c, keyLengthSyntax))
206206
{
207-
c.ReportIssue(Diagnostic.Create(Rule, syntaxElement.GetLocation(), MinimalCommonKeyLength, CipherName(containingType), string.Empty));
207+
c.ReportIssue(Rule, syntaxElement, MinimalCommonKeyLength.ToString(), CipherName(containingType), string.Empty);
208208
}
209209
}
210210

@@ -216,7 +216,7 @@ private static void CheckBouncyCastleParametersGenerators(SonarSyntaxNodeReporti
216216
&& IsInvalidCommonKeyLength(c, firstParam))
217217
{
218218
var cipherAlgorithmName = containingType.Is(KnownType.Org_BouncyCastle_Crypto_Generators_DHParametersGenerator) ? "DH" : "DSA";
219-
c.ReportIssue(Diagnostic.Create(Rule, invocation.GetLocation(), MinimalCommonKeyLength, cipherAlgorithmName, string.Empty));
219+
c.ReportIssue(Rule, invocation, MinimalCommonKeyLength.ToString(), cipherAlgorithmName, string.Empty);
220220
}
221221
}
222222

@@ -226,7 +226,7 @@ private static void CheckBouncyCastleKeyGenerationParameters(SonarSyntaxNodeRepo
226226
&& containingType.Is(KnownType.Org_BouncyCastle_Crypto_Parameters_RsaKeyGenerationParameters)
227227
&& IsInvalidCommonKeyLength(c, keyLengthParam))
228228
{
229-
c.ReportIssue(Diagnostic.Create(Rule, objectCreation.Expression.GetLocation(), MinimalCommonKeyLength, "RSA", string.Empty));
229+
c.ReportIssue(Rule, objectCreation.Expression, MinimalCommonKeyLength.ToString(), "RSA", string.Empty);
230230
}
231231
}
232232

0 commit comments

Comments
 (0)