Skip to content

Commit d8735b6

Browse files
chore: Update to C# 12.0 (#257)
1 parent c3a9cf3 commit d8735b6

17 files changed

+65
-76
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
33
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
4-
<LangVersion>11.0</LangVersion>
4+
<LangVersion>12.0</LangVersion>
55
</PropertyGroup>
66
</Project>

IntelliTect.Analyzer/IntelliTect.Analyzer.Integration.Tests/AnalyzerTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ await ProcessProject(new FileInfo(Path.Combine("..", "..", "..", "..", "IntelliT
2929

3030
public static async Task ProcessProject(FileInfo projectFile)
3131
{
32-
if (projectFile is null)
33-
{
34-
throw new ArgumentNullException(nameof(projectFile));
35-
}
32+
ArgumentNullException.ThrowIfNull(projectFile);
3633

3734
using var workspace = MSBuildWorkspace.Create();
3835
Project project = await workspace.OpenProjectAsync(projectFile.FullName).ConfigureAwait(false);

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AsyncVoidTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public async void Sample() { }
5656
Message = "Async methods should not return void",
5757
Severity = DiagnosticSeverity.Warning,
5858
Locations =
59-
new[] {
59+
[
6060
new DiagnosticResultLocation("Test0.cs", 13, 31)
61-
}
61+
]
6262
};
6363

6464
VerifyCSharpDiagnostic(test, expected);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ private static DiagnosticResult GetExpectedDiagnosticResult(int line, int col)
398398
Message = "Attributes should be on separate lines",
399399
Severity = DiagnosticSeverity.Warning,
400400
Locations =
401-
new[] {
401+
[
402402
new DiagnosticResultLocation("Test0.cs", line, col)
403-
}
403+
]
404404
};
405405
}
406406

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/DateTimeConversionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static void Main(string[] args)
3232
Severity = DiagnosticSeverity.Warning,
3333
Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior",
3434
Locations =
35-
new[] {
35+
[
3636
new DiagnosticResultLocation("Test0.cs", 10, 38)
37-
}
37+
]
3838
});
3939

4040
}
@@ -73,9 +73,9 @@ static void Main(string[] args)
7373
Severity = DiagnosticSeverity.Warning,
7474
Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior",
7575
Locations =
76-
new[] {
76+
[
7777
new DiagnosticResultLocation("Test0.cs", 17, 17)
78-
}
78+
]
7979
});
8080

8181
}

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ static void Main(string[] args)
3737
Severity = DiagnosticSeverity.Info,
3838
Message = "Favor using the method `EnumerateFiles` over the `GetFiles` method",
3939
Locations =
40-
new[] {
40+
[
4141
new DiagnosticResultLocation("Test0.cs", 11, 30)
42-
}
42+
]
4343
});
4444
}
4545

@@ -105,9 +105,9 @@ static void Main(string[] args)
105105
Severity = DiagnosticSeverity.Info,
106106
Message = "Favor using the method `EnumerateDirectories` over the `GetDirectories` method",
107107
Locations =
108-
new[] {
108+
[
109109
new DiagnosticResultLocation("Test0.cs", 11, 30)
110-
}
110+
]
111111
});
112112
}
113113

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/CodeFixVerifier.Helper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ private static async Task<Document> ApplyFix(Document document, CodeAction codeA
3939
/// <returns>A list of Diagnostics that only surfaced in the code after the CodeFix was applied</returns>
4040
private static IEnumerable<Diagnostic> GetNewDiagnostics(IEnumerable<Diagnostic> diagnostics, IEnumerable<Diagnostic> newDiagnostics)
4141
{
42-
Diagnostic[] oldArray = diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
43-
Diagnostic[] newArray = newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
42+
Diagnostic[] oldArray = [.. diagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
43+
Diagnostic[] newArray = [.. newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
4444

4545
int oldIndex = 0;
4646
int newIndex = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public DiagnosticResultLocation[] Locations
4343
{
4444
get
4545
{
46-
_Locations ??= Array.Empty<DiagnosticResultLocation>();
46+
_Locations ??= [];
4747
return _Locations;
4848
}
4949

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ private static Diagnostic[] GetSortedDiagnostics(string[] sources, string langua
4848
/// <returns>An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location</returns>
4949
protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer analyzer, Document[] documents)
5050
{
51-
if (documents is null)
52-
{
53-
throw new ArgumentNullException(nameof(documents));
54-
}
51+
ArgumentNullException.ThrowIfNull(documents);
5552

5653
var projects = new HashSet<Project>();
5754
foreach (Document document in documents)
@@ -97,7 +94,7 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyz
9794
/// <returns>An IEnumerable containing the Diagnostics in order of Location</returns>
9895
private static Diagnostic[] SortDiagnostics(IEnumerable<Diagnostic> diagnostics)
9996
{
100-
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
97+
return [.. diagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
10198
}
10299

103100
#endregion
@@ -135,7 +132,7 @@ private static Document[] GetDocuments(string[] sources, string language)
135132
/// <returns>A Document created from the source string</returns>
136133
protected static Document CreateDocument(string source, string language = LanguageNames.CSharp)
137134
{
138-
return CreateProject(new[] { source }, language).Documents.First();
135+
return CreateProject([source], language).Documents.First();
139136
}
140137

141138
/// <summary>

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingFieldPascalUnderscoreTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class TypeName
7979
Message = "Field 'MyField' should be named _PascalCase",
8080
Severity = DiagnosticSeverity.Warning,
8181
Locations =
82-
new[] {
82+
[
8383
new DiagnosticResultLocation("Test0.cs", 13, 27)
84-
}
84+
]
8585
};
8686

8787
VerifyCSharpDiagnostic(test, expected);
@@ -111,9 +111,9 @@ class TypeName
111111
Message = "Field '_myField' should be named _PascalCase",
112112
Severity = DiagnosticSeverity.Warning,
113113
Locations =
114-
new[] {
114+
[
115115
new DiagnosticResultLocation("Test0.cs", 13, 27)
116-
}
116+
]
117117
};
118118

119119
VerifyCSharpDiagnostic(test, expected);
@@ -143,9 +143,9 @@ class TypeName
143143
Message = "Field '__myField' should be named _PascalCase",
144144
Severity = DiagnosticSeverity.Warning,
145145
Locations =
146-
new[] {
146+
[
147147
new DiagnosticResultLocation("Test0.cs", 13, 27)
148-
}
148+
]
149149
};
150150

151151
VerifyCSharpDiagnostic(test, expected);
@@ -443,9 +443,9 @@ class TypeName
443443
Message = "Field '_My_Field' should be named _PascalCase",
444444
Severity = DiagnosticSeverity.Warning,
445445
Locations =
446-
new[] {
446+
[
447447
new DiagnosticResultLocation("Test0.cs", 13, 27)
448-
}
448+
]
449449
};
450450

451451
VerifyCSharpDiagnostic(test, expected);

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingMethodPascalTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ string localMethod() {
4444
Message = "Method 'localMethod' should be PascalCase",
4545
Severity = DiagnosticSeverity.Warning,
4646
Locations =
47-
new[] {
47+
[
4848
new DiagnosticResultLocation("Test0.cs", 17, 24)
49-
}
49+
]
5050
};
5151

5252
VerifyCSharpDiagnostic(test, expected);
@@ -152,9 +152,9 @@ public string myMethod()
152152
Message = "Method 'myMethod' should be PascalCase",
153153
Severity = DiagnosticSeverity.Warning,
154154
Locations =
155-
new[] {
155+
[
156156
new DiagnosticResultLocation("Test0.cs", 13, 27)
157-
}
157+
]
158158
};
159159

160160
VerifyCSharpDiagnostic(test, expected);
@@ -187,9 +187,9 @@ public string _MyMethod()
187187
Message = "Method '_MyMethod' should be PascalCase",
188188
Severity = DiagnosticSeverity.Warning,
189189
Locations =
190-
new[] {
190+
[
191191
new DiagnosticResultLocation("Test0.cs", 13, 27)
192-
}
192+
]
193193
};
194194

195195
VerifyCSharpDiagnostic(test, expected);
@@ -349,9 +349,9 @@ public string My_Method()
349349
Message = "Method 'My_Method' should be PascalCase",
350350
Severity = DiagnosticSeverity.Warning,
351351
Locations =
352-
new[] {
352+
[
353353
new DiagnosticResultLocation("Test0.cs", 13, 27)
354-
}
354+
]
355355
};
356356

357357
VerifyCSharpDiagnostic(test, expected);
@@ -416,19 +416,19 @@ void IInterface.foo() { }
416416
Message = "Method 'foo' should be PascalCase",
417417
Severity = DiagnosticSeverity.Warning,
418418
Locations =
419-
new[] {
419+
[
420420
new DiagnosticResultLocation("Test0.cs", 13, 25)
421-
}
421+
]
422422
};
423423
var expected2 = new DiagnosticResult
424424
{
425425
Id = "INTL0003",
426426
Message = "Method 'foo' should be PascalCase",
427427
Severity = DiagnosticSeverity.Warning,
428428
Locations =
429-
new[] {
429+
[
430430
new DiagnosticResultLocation("Test0.cs", 18, 29)
431-
}
431+
]
432432
};
433433
VerifyCSharpDiagnostic(test, expected1, expected2);
434434
}

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingPropertyPascalTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class TypeName
7979
Message = "Property 'myProperty' should be PascalCase",
8080
Severity = DiagnosticSeverity.Warning,
8181
Locations =
82-
new[] {
82+
[
8383
new DiagnosticResultLocation("Test0.cs", 13, 27)
84-
}
84+
]
8585
};
8686

8787
VerifyCSharpDiagnostic(test, expected);
@@ -111,9 +111,9 @@ class TypeName
111111
Message = "Property '_MyProperty' should be PascalCase",
112112
Severity = DiagnosticSeverity.Warning,
113113
Locations =
114-
new[] {
114+
[
115115
new DiagnosticResultLocation("Test0.cs", 13, 27)
116-
}
116+
]
117117
};
118118

119119
VerifyCSharpDiagnostic(test, expected);
@@ -290,9 +290,9 @@ class TypeName
290290
Message = "Property 'My_Property' should be PascalCase",
291291
Severity = DiagnosticSeverity.Warning,
292292
Locations =
293-
new[] {
293+
[
294294
new DiagnosticResultLocation("Test0.cs", 13, 27)
295-
}
295+
]
296296
};
297297

298298
VerifyCSharpDiagnostic(test, expected);
@@ -356,19 +356,19 @@ public class TypeName : IInterface
356356
Message = "Property 'foo' should be PascalCase",
357357
Severity = DiagnosticSeverity.Warning,
358358
Locations =
359-
new[] {
359+
[
360360
new DiagnosticResultLocation("Test0.cs", 13, 27)
361-
}
361+
]
362362
};
363363
var expected2 = new DiagnosticResult
364364
{
365365
Id = "INTL0002",
366366
Message = "Property 'foo' should be PascalCase",
367367
Severity = DiagnosticSeverity.Warning,
368368
Locations =
369-
new[] {
369+
[
370370
new DiagnosticResultLocation("Test0.cs", 18, 31)
371-
}
371+
]
372372
};
373373

374374
VerifyCSharpDiagnostic(test, expected1, expected2);

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/UnusedLocalVariableTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ public void Foo()
119119
Id = Analyzers.UnusedLocalVariable.DiagnosticId,
120120
Message = "Local variable 'foo' should be used",
121121
Severity = DiagnosticSeverity.Info,
122-
Locations = new[]
123-
{
122+
Locations =
123+
[
124124
new DiagnosticResultLocation("Test0.cs", 15, 20)
125-
}
125+
]
126126
};
127127

128128
VerifyCSharpDiagnostic(test, expected);
@@ -242,9 +242,9 @@ bool Bar(Func<bool, bool> func)
242242
Message = "Local variable 't' should be used",
243243
Severity = DiagnosticSeverity.Info,
244244
Locations =
245-
new[] {
245+
[
246246
new DiagnosticResultLocation("Test0.cs", 10, 17)
247-
}
247+
]
248248
};
249249
VerifyCSharpDiagnostic(test, result);
250250
}

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/CodeFixVerifier.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected async Task VerifyBasicFix(string oldSource, string newSource, int? cod
7676
private static async Task VerifyFix(string language, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string oldSource, string newSource, int? codeFixIndex, bool allowNewCompilerDiagnostics)
7777
{
7878
Document document = CreateDocument(oldSource, language);
79-
Diagnostic[] analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, new[] { document });
79+
Diagnostic[] analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, [document]);
8080
IEnumerable<Diagnostic> compilerDiagnostics = GetCompilerDiagnostics(document);
8181
int attempts = analyzerDiagnostics.Length;
8282

@@ -86,7 +86,7 @@ private static async Task VerifyFix(string language, DiagnosticAnalyzer analyzer
8686
var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
8787
codeFixProvider.RegisterCodeFixesAsync(context).Wait();
8888

89-
if (!actions.Any())
89+
if (actions.Count == 0)
9090
{
9191
break;
9292
}
@@ -98,7 +98,7 @@ private static async Task VerifyFix(string language, DiagnosticAnalyzer analyzer
9898
}
9999

100100
document = await ApplyFix(document, actions.ElementAt(0));
101-
analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, new[] { document });
101+
analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, [document]);
102102

103103
IEnumerable<Diagnostic> newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, GetCompilerDiagnostics(document));
104104

@@ -114,7 +114,7 @@ private static async Task VerifyFix(string language, DiagnosticAnalyzer analyzer
114114
}
115115

116116
//check if there are analyzer diagnostics left after the code fix
117-
if (!analyzerDiagnostics.Any())
117+
if (analyzerDiagnostics.Length == 0)
118118
{
119119
break;
120120
}

0 commit comments

Comments
 (0)