diff --git a/Directory.Build.props b/Directory.Build.props
index 5742c011..46c99a85 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,6 +1,6 @@
true
- 11.0
+ 12.0
\ No newline at end of file
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Integration.Tests/AnalyzerTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Integration.Tests/AnalyzerTests.cs
index 900a1349..8705f45f 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Integration.Tests/AnalyzerTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Integration.Tests/AnalyzerTests.cs
@@ -29,10 +29,7 @@ await ProcessProject(new FileInfo(Path.Combine("..", "..", "..", "..", "IntelliT
public static async Task ProcessProject(FileInfo projectFile)
{
- if (projectFile is null)
- {
- throw new ArgumentNullException(nameof(projectFile));
- }
+ ArgumentNullException.ThrowIfNull(projectFile);
using var workspace = MSBuildWorkspace.Create();
Project project = await workspace.OpenProjectAsync(projectFile.FullName).ConfigureAwait(false);
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AsyncVoidTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AsyncVoidTests.cs
index 72fbb531..2ac43b5f 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AsyncVoidTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AsyncVoidTests.cs
@@ -56,9 +56,9 @@ public async void Sample() { }
Message = "Async methods should not return void",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 31)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs
index af2868b5..cd7a750a 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs
@@ -398,9 +398,9 @@ private static DiagnosticResult GetExpectedDiagnosticResult(int line, int col)
Message = "Attributes should be on separate lines",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", line, col)
- }
+ ]
};
}
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/DateTimeConversionTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/DateTimeConversionTests.cs
index 12ef0640..f2fec53a 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/DateTimeConversionTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/DateTimeConversionTests.cs
@@ -32,9 +32,9 @@ static void Main(string[] args)
Severity = DiagnosticSeverity.Warning,
Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior",
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 10, 38)
- }
+ ]
});
}
@@ -73,9 +73,9 @@ static void Main(string[] args)
Severity = DiagnosticSeverity.Warning,
Message = "Using the symbol 'DateTimeOffset.implicit operator DateTimeOffset(DateTime)' can result in unpredictable behavior",
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 17, 17)
- }
+ ]
});
}
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs
index ec78439d..97af362d 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs
@@ -37,9 +37,9 @@ static void Main(string[] args)
Severity = DiagnosticSeverity.Info,
Message = "Favor using the method `EnumerateFiles` over the `GetFiles` method",
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 11, 30)
- }
+ ]
});
}
@@ -105,9 +105,9 @@ static void Main(string[] args)
Severity = DiagnosticSeverity.Info,
Message = "Favor using the method `EnumerateDirectories` over the `GetDirectories` method",
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 11, 30)
- }
+ ]
});
}
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/CodeFixVerifier.Helper.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/CodeFixVerifier.Helper.cs
index 38c434a7..3bc42ae9 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/CodeFixVerifier.Helper.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/CodeFixVerifier.Helper.cs
@@ -39,8 +39,8 @@ private static async Task ApplyFix(Document document, CodeAction codeA
/// A list of Diagnostics that only surfaced in the code after the CodeFix was applied
private static IEnumerable GetNewDiagnostics(IEnumerable diagnostics, IEnumerable newDiagnostics)
{
- Diagnostic[] oldArray = diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
- Diagnostic[] newArray = newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
+ Diagnostic[] oldArray = [.. diagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
+ Diagnostic[] newArray = [.. newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
int oldIndex = 0;
int newIndex = 0;
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticResult.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticResult.cs
index 04ee5243..7efddc6e 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticResult.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticResult.cs
@@ -43,7 +43,7 @@ public DiagnosticResultLocation[] Locations
{
get
{
- _Locations ??= Array.Empty();
+ _Locations ??= [];
return _Locations;
}
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs
index d141f30d..cfd8c22c 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Helpers/DiagnosticVerifier.Helper.cs
@@ -48,10 +48,7 @@ private static Diagnostic[] GetSortedDiagnostics(string[] sources, string langua
/// An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location
protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer analyzer, Document[] documents)
{
- if (documents is null)
- {
- throw new ArgumentNullException(nameof(documents));
- }
+ ArgumentNullException.ThrowIfNull(documents);
var projects = new HashSet();
foreach (Document document in documents)
@@ -97,7 +94,7 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyz
/// An IEnumerable containing the Diagnostics in order of Location
private static Diagnostic[] SortDiagnostics(IEnumerable diagnostics)
{
- return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
+ return [.. diagnostics.OrderBy(d => d.Location.SourceSpan.Start)];
}
#endregion
@@ -135,7 +132,7 @@ private static Document[] GetDocuments(string[] sources, string language)
/// A Document created from the source string
protected static Document CreateDocument(string source, string language = LanguageNames.CSharp)
{
- return CreateProject(new[] { source }, language).Documents.First();
+ return CreateProject([source], language).Documents.First();
}
///
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingFieldPascalUnderscoreTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingFieldPascalUnderscoreTests.cs
index 127fbec4..324803e5 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingFieldPascalUnderscoreTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingFieldPascalUnderscoreTests.cs
@@ -79,9 +79,9 @@ class TypeName
Message = "Field 'MyField' should be named _PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -111,9 +111,9 @@ class TypeName
Message = "Field '_myField' should be named _PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -143,9 +143,9 @@ class TypeName
Message = "Field '__myField' should be named _PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -443,9 +443,9 @@ class TypeName
Message = "Field '_My_Field' should be named _PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingMethodPascalTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingMethodPascalTests.cs
index ff8fff24..5ee7b0e1 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingMethodPascalTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingMethodPascalTests.cs
@@ -44,9 +44,9 @@ string localMethod() {
Message = "Method 'localMethod' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 17, 24)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -152,9 +152,9 @@ public string myMethod()
Message = "Method 'myMethod' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -187,9 +187,9 @@ public string _MyMethod()
Message = "Method '_MyMethod' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -349,9 +349,9 @@ public string My_Method()
Message = "Method 'My_Method' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -416,9 +416,9 @@ void IInterface.foo() { }
Message = "Method 'foo' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 25)
- }
+ ]
};
var expected2 = new DiagnosticResult
{
@@ -426,9 +426,9 @@ void IInterface.foo() { }
Message = "Method 'foo' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 18, 29)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected1, expected2);
}
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingPropertyPascalTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingPropertyPascalTests.cs
index cb901016..d31f0f2a 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingPropertyPascalTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingPropertyPascalTests.cs
@@ -79,9 +79,9 @@ class TypeName
Message = "Property 'myProperty' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -111,9 +111,9 @@ class TypeName
Message = "Property '_MyProperty' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -290,9 +290,9 @@ class TypeName
Message = "Property 'My_Property' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -356,9 +356,9 @@ public class TypeName : IInterface
Message = "Property 'foo' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 13, 27)
- }
+ ]
};
var expected2 = new DiagnosticResult
{
@@ -366,9 +366,9 @@ public class TypeName : IInterface
Message = "Property 'foo' should be PascalCase",
Severity = DiagnosticSeverity.Warning,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 18, 31)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected1, expected2);
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/UnusedLocalVariableTests.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/UnusedLocalVariableTests.cs
index e87d405c..88e58962 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/UnusedLocalVariableTests.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/UnusedLocalVariableTests.cs
@@ -119,10 +119,10 @@ public void Foo()
Id = Analyzers.UnusedLocalVariable.DiagnosticId,
Message = "Local variable 'foo' should be used",
Severity = DiagnosticSeverity.Info,
- Locations = new[]
- {
+ Locations =
+ [
new DiagnosticResultLocation("Test0.cs", 15, 20)
- }
+ ]
};
VerifyCSharpDiagnostic(test, expected);
@@ -242,9 +242,9 @@ bool Bar(Func func)
Message = "Local variable 't' should be used",
Severity = DiagnosticSeverity.Info,
Locations =
- new[] {
+ [
new DiagnosticResultLocation("Test0.cs", 10, 17)
- }
+ ]
};
VerifyCSharpDiagnostic(test, result);
}
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/CodeFixVerifier.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/CodeFixVerifier.cs
index 5a3fe6cf..253c7b60 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/CodeFixVerifier.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/CodeFixVerifier.cs
@@ -76,7 +76,7 @@ protected async Task VerifyBasicFix(string oldSource, string newSource, int? cod
private static async Task VerifyFix(string language, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string oldSource, string newSource, int? codeFixIndex, bool allowNewCompilerDiagnostics)
{
Document document = CreateDocument(oldSource, language);
- Diagnostic[] analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, new[] { document });
+ Diagnostic[] analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, [document]);
IEnumerable compilerDiagnostics = GetCompilerDiagnostics(document);
int attempts = analyzerDiagnostics.Length;
@@ -86,7 +86,7 @@ private static async Task VerifyFix(string language, DiagnosticAnalyzer analyzer
var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
codeFixProvider.RegisterCodeFixesAsync(context).Wait();
- if (!actions.Any())
+ if (actions.Count == 0)
{
break;
}
@@ -98,7 +98,7 @@ private static async Task VerifyFix(string language, DiagnosticAnalyzer analyzer
}
document = await ApplyFix(document, actions.ElementAt(0));
- analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, new[] { document });
+ analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, [document]);
IEnumerable newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, GetCompilerDiagnostics(document));
@@ -114,7 +114,7 @@ private static async Task VerifyFix(string language, DiagnosticAnalyzer analyzer
}
//check if there are analyzer diagnostics left after the code fix
- if (!analyzerDiagnostics.Any())
+ if (analyzerDiagnostics.Length == 0)
{
break;
}
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/DiagnosticVerifier.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/DiagnosticVerifier.cs
index cb2c3eb3..134d643f 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/DiagnosticVerifier.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer.Test/Verifiers/DiagnosticVerifier.cs
@@ -41,7 +41,7 @@ protected virtual DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
/// DiagnosticResults that should appear after the analyzer is run on the source
protected void VerifyCSharpDiagnostic(string source, params DiagnosticResult[] expected)
{
- VerifyDiagnostics(new[] { source }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected);
+ VerifyDiagnostics([source], LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected);
}
///
@@ -52,7 +52,7 @@ protected void VerifyCSharpDiagnostic(string source, params DiagnosticResult[] e
/// DiagnosticResults that should appear after the analyzer is run on the source
protected void VerifyBasicDiagnostic(string source, params DiagnosticResult[] expected)
{
- VerifyDiagnostics(new[] { source }, LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), expected);
+ VerifyDiagnostics([source], LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), expected);
}
///
@@ -121,7 +121,7 @@ private static void VerifyDiagnosticResults(IEnumerable actualResult
else
{
VerifyDiagnosticLocation(analyzer, actual, actual.Location, expected.Locations.First());
- Location[] additionalLocations = actual.AdditionalLocations.ToArray();
+ Location[] additionalLocations = [.. actual.AdditionalLocations];
Assert.AreEqual(additionalLocations.Length,
expected.Locations.Length - 1,
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/AttributesOnSeparateLines.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/AttributesOnSeparateLines.cs
index c0bc1625..7a9e6422 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/AttributesOnSeparateLines.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/AttributesOnSeparateLines.cs
@@ -40,7 +40,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context)
if (namedTypeSymbol.GetAttributes().Any())
{
- IDictionary lineDictionary = new Dictionary();
+ Dictionary lineDictionary = [];
foreach (AttributeData attribute in namedTypeSymbol.GetAttributes())
{
SyntaxReference applicationSyntaxReference = attribute.ApplicationSyntaxReference;
diff --git a/IntelliTect.Analyzer/IntelliTect.Analyzer/DescriptionAttribute.cs b/IntelliTect.Analyzer/IntelliTect.Analyzer/DescriptionAttribute.cs
index d98f7ee7..7c8d7911 100644
--- a/IntelliTect.Analyzer/IntelliTect.Analyzer/DescriptionAttribute.cs
+++ b/IntelliTect.Analyzer/IntelliTect.Analyzer/DescriptionAttribute.cs
@@ -3,21 +3,16 @@
namespace IntelliTect.Analyzer
{
[AttributeUsage(AttributeTargets.All)]
- internal class DescriptionAttribute : Attribute
+ internal class DescriptionAttribute(string description) : Attribute
{
public static DescriptionAttribute Default { get; } = new DescriptionAttribute();
- public string Description { get; }
+ public string Description { get; } = description;
public DescriptionAttribute() : this(string.Empty)
{
}
- public DescriptionAttribute(string description)
- {
- Description = description;
- }
-
public override bool Equals(object obj)
{
if (ReferenceEquals(obj, this))