Skip to content

Commit cf4522c

Browse files
Merge branch 'feature/v5.3.1'
2 parents 13e2a92 + f080b9e commit cf4522c

Some content is hidden

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

44 files changed

+151
-182
lines changed

Sources/ReCommendedExtension.Tests/ReCommendedExtension.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="JetBrains.Lifetimes" Version="2020.3.2" />
21-
<PackageReference Include="JetBrains.ReSharper.SDK.Tests" Version="2020.3.0">
21+
<PackageReference Include="JetBrains.ReSharper.SDK.Tests" Version="2020.3.1">
2222
<PrivateAssets>all</PrivateAssets>
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2424
</PackageReference>

Sources/ReCommendedExtension/Analyzers/Annotation/AnnotationAnalyzer.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,7 @@ where Equals(attributeInstance.GetClrName(), ClrTypeNames.SuppressMessageAttribu
273273
new MissingSuppressionJustificationWarning(
274274
attributesOwnerDeclaration,
275275
suppressMessageAttribute.Attribute,
276-
string.Format(
277-
"Suppression justification is missing for {0}:{1}.",
278-
suppressMessageAttribute.Category,
279-
suppressMessageAttribute.CheckId)));
276+
$"Suppression justification is missing for {suppressMessageAttribute.Category}:{suppressMessageAttribute.CheckId}."));
280277
}
281278

282279
if (!ExcludeFromCodeCoverageJustificationPropertyExists(attributesOwnerDeclaration.GetPsiModule()))
@@ -337,7 +334,7 @@ from attribute in attributesOwnerDeclaration.Attributes
337334
new ConflictingAnnotationWarning(
338335
attributesOwnerDeclaration,
339336
attribute,
340-
string.Format("Annotation conflicts with '{0}' annotation.", conflictingAnnotation)));
337+
$"Annotation conflicts with '{conflictingAnnotation}' annotation."));
341338
}
342339
}
343340
}
@@ -580,7 +577,7 @@ where conditions.Count > 0
580577
attributesOwnerDeclaration,
581578
conditionalAttribute.Attribute,
582579
conditionalAttribute.Conditions.Count == 1
583-
? string.Format("Attribute will be ignored if the '{0}' condition is not defined.", conditionalAttribute.Conditions[0])
580+
? $"Attribute will be ignored if the '{conditionalAttribute.Conditions[0]}' condition is not defined."
584581
: string.Format(
585582
"Attribute will be ignored if none of the following conditions is defined: {0}.",
586583
string.Join(", ", from condition in conditionalAttribute.Conditions orderby condition select $"'{condition}'"))));
@@ -756,7 +753,7 @@ void AnalyzeOther(
756753
case ValueAnalysisMode.PESSIMISTIC:
757754
foreach (var attributeMark in GetAttributeMarks(attributesOwnerDeclaration))
758755
{
759-
if (attributeMark != null && attributeMark.AnnotationNullableValue == CodeAnnotationNullableValue.CAN_BE_NULL)
756+
if (attributeMark?.AnnotationNullableValue == CodeAnnotationNullableValue.CAN_BE_NULL)
760757
{
761758
consumer.AddHighlighting(
762759
new RedundantAnnotationSuggestion(

Sources/ReCommendedExtension/Analyzers/ArgumentExceptionConstructorArgument/ArgumentExceptionConstructorArgumentAnalyzer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ protected override void Run(IObjectCreationExpression element, ElementProblemAna
3232
{
3333
case ILiteralExpression literalExpression:
3434
var literalText = literalExpression.Literal?.GetText();
35-
if (literalText != null &&
36-
literalText.Length > 2 &&
35+
if (literalText?.Length > 2 &&
3736
literalText[0] == '\"' &&
3837
literalText[literalText.Length - 1] == '\"' &&
3938
parameters.Any(p => p.AssertNotNull().ShortName == literalText.Substring(1, literalText.Length - 2)))

Sources/ReCommendedExtension/Analyzers/ArrayWithDefaultValuesInitialization/ArrayWithDefaultValuesInitializationAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ReCommendedExtension.Analyzers.ArrayWithDefaultValuesInitialization
1414
public sealed class ArrayWithDefaultValuesInitializationAnalyzer : ElementProblemAnalyzer<IArrayInitializer>
1515
{
1616
[NotNull]
17-
static string CreateHighlightingMessage([NotNull] string suggestedCode) => string.Format("Use '{0}'.", suggestedCode);
17+
static string CreateHighlightingMessage([NotNull] string suggestedCode) => $"Use '{suggestedCode}'.";
1818

1919
protected override void Run(IArrayInitializer element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
2020
{

Sources/ReCommendedExtension/Analyzers/ArrayWithDefaultValuesInitialization/ReplaceWithNewArrayWithLengthFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override string Text
3131
{
3232
Debug.Assert(CSharpLanguage.Instance != null);
3333

34-
return string.Format("Replace array initialization with '{0}'", highlighting.SuggestedCode);
34+
return $"Replace array initialization with '{highlighting.SuggestedCode}'";
3535
}
3636
}
3737

Sources/ReCommendedExtension/Analyzers/AsyncVoid/AsyncVoidAnalyzer.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ static void Analyze([NotNull] IMethodDeclaration methodDeclaration, [NotNull] IH
8383
{
8484
consumer.AddHighlighting(
8585
new AvoidAsyncVoidWarning(
86-
string.Format(
87-
"'async void' method used {0} time{1} not as a direct event handler.",
88-
count.ToString(),
89-
count == 1 ? "" : "s"),
86+
$"'async void' method used {count.ToString()} time{(count == 1 ? "" : "s")} not as a direct event handler.",
9087
methodDeclaration));
9188
}
9289
}
@@ -113,10 +110,7 @@ static void Analyze([NotNull] ILocalFunctionDeclaration localFunctionDeclaration
113110
{
114111
consumer.AddHighlighting(
115112
new AvoidAsyncVoidWarning(
116-
string.Format(
117-
"'async void' local function used {0} time{1} not as a direct event handler.",
118-
count.ToString(),
119-
count == 1 ? "" : "s"),
113+
$"'async void' local function used {count.ToString()} time{(count == 1 ? "" : "s")} not as a direct event handler.",
120114
localFunctionDeclaration));
121115
}
122116
}

Sources/ReCommendedExtension/Analyzers/ConditionalInvocation/ConditionalInvocationAnalyzer.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,21 @@ where attributeInstance.AssertNotNull().PositionParameterCount == 1
5050
{
5151
foreach (var treeNode in file.Descendants())
5252
{
53-
if (treeNode is IDefineDirective defineDirective)
53+
switch (treeNode)
5454
{
55-
if (!string.IsNullOrEmpty(defineDirective.SymbolName))
56-
{
57-
currentConditions.Add(defineDirective.SymbolName);
58-
}
59-
continue;
60-
}
55+
case IDefineDirective defineDirective:
56+
if (!string.IsNullOrEmpty(defineDirective.SymbolName))
57+
{
58+
currentConditions.Add(defineDirective.SymbolName);
59+
}
60+
continue;
6161

62-
if (treeNode is IUndefDirective undefDirective)
63-
{
64-
if (!string.IsNullOrEmpty(undefDirective.SymbolName))
65-
{
66-
currentConditions.Remove(undefDirective.SymbolName);
67-
}
68-
continue;
62+
case IUndefDirective undefDirective:
63+
if (!string.IsNullOrEmpty(undefDirective.SymbolName))
64+
{
65+
currentConditions.Remove(undefDirective.SymbolName);
66+
}
67+
continue;
6968
}
7069

7170
if (treeNode == invocationExpression ||
@@ -92,7 +91,7 @@ protected override void Run(IInvocationExpression element, ElementProblemAnalyze
9291
consumer.AddHighlighting(
9392
new ConditionalInvocationHint(
9493
conditions.Count == 1
95-
? string.Format("Method invocation will be skipped if the '{0}' condition is not defined.", conditions[0])
94+
? $"Method invocation will be skipped if the '{conditions[0]}' condition is not defined."
9695
: string.Format(
9796
"Method invocation will be skipped if none of the following conditions is defined: {0}.",
9897
string.Join(", ", from condition in conditions orderby condition select $"'{condition}'")),

Sources/ReCommendedExtension/Analyzers/EmptyArrayInitialization/EmptyArrayInitializationAnalyzer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ static string CreateHighlightingMessage([NotNull] IType arrayElementType)
3333
{
3434
Debug.Assert(CSharpLanguage.Instance != null);
3535

36-
return string.Format(
37-
"Use '{0}.{1}<{2}>()'.",
38-
nameof(Array),
39-
nameof(Array.Empty),
40-
arrayElementType.GetPresentableName(CSharpLanguage.Instance));
36+
return $"Use '{nameof(Array)}.{nameof(Array.Empty)}<{arrayElementType.GetPresentableName(CSharpLanguage.Instance)}>()'.";
4137
}
4238

4339
protected override void Run(ICSharpTreeNode element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)

Sources/ReCommendedExtension/Analyzers/LocalSuppression/LocalSuppressionAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ static int GetLeadingWhitespaceCharacterCount([NotNull] string commentText)
1313
{
1414
var leadingWhitespaceCharacters = 0;
1515

16-
for (var i = 0; i < commentText.Length; i++)
16+
foreach (var c in commentText)
1717
{
18-
switch (commentText[i])
18+
switch (c)
1919
{
2020
case ' ':
2121
case '\t':

Sources/ReCommendedExtension/Analyzers/ValueTask/ValueTaskAnalyzer.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ sealed class Inspector : CSharpControlFlowGraphInspector
3636
{
3737
var declaration = controlFlowGraph.Declaration;
3838
Debug.Assert(declaration != null);
39-
39+
4040
var containingFile = (ICSharpFile)declaration.GetContainingFile();
4141

4242
var forceClosuresCollection = false;
4343
if ((uint)analysisMode > 0U && shouldDisableValueAnalysisIfNullableWarningsEnabled)
4444
{
4545
var file = containingFile;
4646
var treeTextRange = declaration.GetTreeTextRange();
47-
ref TreeTextRange local = ref treeTextRange;
47+
ref var local = ref treeTextRange;
4848
if (file.IsNullableWarningsEnabledEverywhereIn(in local))
4949
{
5050
analysisMode = ValueAnalysisMode.OFF;
@@ -321,14 +321,15 @@ static void AnalyzeBlockingAttempt([NotNull] IInvocationExpression invocationExp
321321

322322
protected override void Run(ICSharpTreeNode element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
323323
{
324-
if (element is ICSharpDeclaration declaration)
324+
switch (element)
325325
{
326-
AnalyzeMultipleConsumptions(declaration, consumer, data.GetValueAnalysisMode());
327-
}
326+
case ICSharpDeclaration declaration:
327+
AnalyzeMultipleConsumptions(declaration, consumer, data.GetValueAnalysisMode());
328+
break;
328329

329-
if (element is IInvocationExpression invocationExpression)
330-
{
331-
AnalyzeBlockingAttempt(invocationExpression, consumer);
330+
case IInvocationExpression invocationExpression:
331+
AnalyzeBlockingAttempt(invocationExpression, consumer);
332+
break;
332333
}
333334
}
334335
}

0 commit comments

Comments
 (0)