Skip to content

Commit fd59d0f

Browse files
Deal with analyzers
1 parent 3b3a7d8 commit fd59d0f

11 files changed

Lines changed: 31 additions & 38 deletions

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class AAttribute : Attribute
120120
}
121121
}";
122122

123-
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(12, 6));
123+
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(12, 6));
124124
}
125125

126126
[TestMethod]
@@ -146,7 +146,7 @@ static void Main()
146146
}
147147
}
148148
}";
149-
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(15, 13));
149+
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(15, 13));
150150
}
151151

152152
[TestMethod]
@@ -172,7 +172,7 @@ static void Main()
172172
}
173173
}
174174
}";
175-
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(13, 13));
175+
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(13, 13));
176176
}
177177

178178
[TestMethod]
@@ -200,7 +200,7 @@ static void Main()
200200
int Prop {get;set;}
201201
}
202202
}";
203-
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(19, 13));
203+
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(19, 13));
204204
}
205205

206206
[TestMethod]
@@ -221,7 +221,7 @@ [A]static void Main()
221221
}
222222
}
223223
}";
224-
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(11, 10));
224+
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(11, 10));
225225
}
226226

227227
[TestMethod]
@@ -242,7 +242,7 @@ static void Main()
242242
}
243243
}
244244
}";
245-
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(9, 6));
245+
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(9, 6));
246246
}
247247

248248
[TestMethod]
@@ -265,7 +265,7 @@ static void Main()
265265
[A]int Prop {get;set;}
266266
}
267267
}";
268-
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(15, 10));
268+
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(15, 10));
269269
}
270270

271271
[TestMethod]
@@ -291,7 +291,7 @@ static void Main()
291291
}
292292
}
293293
}";
294-
VerifyCSharpDiagnostic(test, GetExpectedDiagnosticResult(11, 10));
294+
VerifyCSharpDiagnostic(test, AttributesOnSeparateLinesTests.GetExpectedDiagnosticResult(11, 10));
295295
}
296296

297297
[TestMethod]
@@ -390,7 +390,7 @@ static void Main()
390390
await VerifyCSharpFix(test, fixTest);
391391
}
392392

393-
private DiagnosticResult GetExpectedDiagnosticResult(int line, int col)
393+
private static DiagnosticResult GetExpectedDiagnosticResult(int line, int col)
394394
{
395395
return new DiagnosticResult
396396
{

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticResult.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace TestHelper
66
/// <summary>
77
/// Location where the diagnostic appears, as determined by path, line number, and column number.
88
/// </summary>
9-
public struct DiagnosticResultLocation
9+
public readonly struct DiagnosticResultLocation
1010
{
1111
public DiagnosticResultLocation(string path, int line, int column)
1212
{
@@ -43,10 +43,7 @@ public DiagnosticResultLocation[] Locations
4343
{
4444
get
4545
{
46-
if (_Locations == null)
47-
{
48-
_Locations = Array.Empty<DiagnosticResultLocation>();
49-
}
46+
_Locations ??= Array.Empty<DiagnosticResultLocation>();
5047
return _Locations;
5148
}
5249

IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/BanImplicitDateTimeToDateTimeOffsetConversion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override void Initialize(AnalysisContext context)
3333

3434
private void AnalyzeInvocation(OperationAnalysisContext context)
3535
{
36-
if (!(context.Operation is IConversionOperation conversionOperation))
36+
if (context.Operation is not IConversionOperation conversionOperation)
3737
{
3838
return;
3939
}

IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/FavorDirectoryEnumerationCalls.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ private void AnalyzeInvocation(SyntaxNodeAnalysisContext context)
4444
{
4545
var expression = (InvocationExpressionSyntax)context.Node;
4646

47-
if (!(expression.Expression is MemberAccessExpressionSyntax memberAccess))
47+
if (expression.Expression is not MemberAccessExpressionSyntax memberAccess)
4848
{
4949
return;
5050
}
5151

52-
if (!(memberAccess.Expression is IdentifierNameSyntax nameSyntax))
52+
if (memberAccess.Expression is not IdentifierNameSyntax nameSyntax)
5353
{
5454
return;
5555
}
@@ -87,7 +87,7 @@ private static class Rule301
8787
internal const string DiagnosticId = "INTL0301";
8888
internal const string Title = "Favor using EnumerateFiles";
8989
internal const string MessageFormat = "Favor using the method `EnumerateFiles` over the `GetFiles` method";
90-
#pragma warning disable INTL0001 // Allow field to not be prefixed with an underscore ot match the style
90+
#pragma warning disable INTL0001 // Allow field to not be prefixed with an underscore to match the style
9191
internal static readonly string HelpMessageUri = DiagnosticUrlBuilder.GetUrl(Title,
9292
DiagnosticId);
9393
#pragma warning restore INTL0001
@@ -101,7 +101,7 @@ private static class Rule302
101101
internal const string DiagnosticId = "INTL0302";
102102
internal const string Title = "Favor using EnumerateDirectories";
103103
internal const string MessageFormat = "Favor using the method `EnumerateDirectories` over the `GetDirectories` method";
104-
#pragma warning disable INTL0001 // Allow field to not be prefixed with an underscore ot match the style
104+
#pragma warning disable INTL0001 // Allow field to not be prefixed with an underscore to match the style
105105
internal static readonly string HelpMessageUri = DiagnosticUrlBuilder.GetUrl(Title,
106106
DiagnosticId);
107107
#pragma warning restore INTL0001

IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/NamingFieldPascalUnderscore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context)
4747
}
4848

4949
//Enum members should not be flagged
50-
if (!(namedTypeSymbol.ContainingType.EnumUnderlyingType is null))
50+
if (namedTypeSymbol.ContainingType.EnumUnderlyingType is not null)
5151
{
5252
return;
5353
}

IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/UnusedLocalVariable.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace IntelliTect.Analyzer.Analyzers
1212
public class UnusedLocalVariable : DiagnosticAnalyzer
1313
{
1414
public const string DiagnosticId = "INTL0303";
15-
private const string _Title = "Local variable unused";
16-
private const string _MessageFormat = "Local variable '{0}' should be used";
17-
private const string _Description = "All local variables should be accessed, or named with underscores to indicate they are unused.";
18-
private const string _Category = "Flow";
19-
private const string _HelpLinkUri = "https://github.com/IntelliTect/CodingGuidelines";
20-
21-
private static readonly DiagnosticDescriptor _Rule = new(DiagnosticId, _Title, _MessageFormat,
22-
_Category, DiagnosticSeverity.Info, isEnabledByDefault: true, description: _Description, _HelpLinkUri);
15+
private const string Title = "Local variable unused";
16+
private const string MessageFormat = "Local variable '{0}' should be used";
17+
private const string Description = "All local variables should be accessed, or named with underscores to indicate they are unused.";
18+
private const string Category = "Flow";
19+
private const string HelpLinkUri = "https://github.com/IntelliTect/CodingGuidelines";
20+
21+
private static readonly DiagnosticDescriptor _Rule = new(DiagnosticId, Title, MessageFormat,
22+
Category, DiagnosticSeverity.Info, isEnabledByDefault: true, description: Description, HelpLinkUri);
2323

2424
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(_Rule);
2525

IntelliTect.Analyzer/IntelliTect.Analyzer/CodeFixes/AsyncVoid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
4343
diagnostic);
4444
}
4545

46-
private async Task<Document> MakeReturnTask(Document document, MethodDeclarationSyntax declaration, CancellationToken cancellationToken)
46+
private static async Task<Document> MakeReturnTask(Document document, MethodDeclarationSyntax declaration, CancellationToken cancellationToken)
4747
{
4848
SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
4949
SyntaxNode newRoot = root.ReplaceNode(declaration.ReturnType, SyntaxFactory.ParseTypeName(typeof(Task).Name).WithTrailingTrivia(SyntaxFactory.Space));

IntelliTect.Analyzer/IntelliTect.Analyzer/CodeFixes/AttributesOnSeparateLines.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
5656
diagnostic);
5757
}
5858

59-
private async Task<Document> PutOnSeparateLine(Document document, SyntaxNode parentDeclaration, CancellationToken cancellationToken)
59+
private static async Task<Document> PutOnSeparateLine(Document document, SyntaxNode parentDeclaration, CancellationToken cancellationToken)
6060
{
6161
var attributeLists = new SyntaxList<AttributeListSyntax>();
6262

IntelliTect.Analyzer/IntelliTect.Analyzer/CodeFixes/NamingFieldPascalUnderscore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
4444
diagnostic);
4545
}
4646

47-
private async Task<Solution> MakePascalWithUnderscore(Document document, SyntaxToken declaration, CancellationToken cancellationToken)
47+
private static async Task<Solution> MakePascalWithUnderscore(Document document, SyntaxToken declaration, CancellationToken cancellationToken)
4848
{
4949
string nameOfField = declaration.ValueText;
5050
string nameWithoutUnderscore = nameOfField.TrimStart('_');
@@ -53,7 +53,7 @@ private async Task<Solution> MakePascalWithUnderscore(Document document, SyntaxT
5353
SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
5454
ISymbol symbol = semanticModel.GetDeclaredSymbol(declaration.Parent, cancellationToken);
5555
Solution solution = document.Project.Solution;
56-
SymbolRenameOptions options = new SymbolRenameOptions()
56+
SymbolRenameOptions options = new()
5757
{
5858
RenameOverloads = true
5959
};

IntelliTect.Analyzer/IntelliTect.Analyzer/CodeFixes/NamingIdentifierPascal.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
4444
diagnostic);
4545
}
4646

47-
private async Task<Solution> MakePascal(Document document, SyntaxToken declaration, CancellationToken cancellationToken)
47+
private static async Task<Solution> MakePascal(Document document, SyntaxToken declaration, CancellationToken cancellationToken)
4848
{
4949
string nameOfField = declaration.ValueText;
5050
string newName = char.ToUpper(nameOfField.First()) + nameOfField.Substring(1);
5151

5252
SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
5353
ISymbol symbol = semanticModel.GetDeclaredSymbol(declaration.Parent, cancellationToken);
5454
Solution solution = document.Project.Solution;
55-
SymbolRenameOptions options = new SymbolRenameOptions()
55+
SymbolRenameOptions options = new()
5656
{
5757
RenameOverloads = true
5858
};

0 commit comments

Comments
 (0)