This instance will be upgraded to Heptapod 0.17.0 on 2020-11-26 at 14:00 UTC+1 (a few minutes of down time)

Commit 2d168f3c authored by Jesse McGrew's avatar Jesse McGrew

Update projects to .NET 5 RC.

Enable nullable reference type checks.
Clean up various compiler/analysis warnings, including use of "is not" pattern matching.
parent 8ad1cb8bd38a
......@@ -13,7 +13,7 @@
# See other available tags for .NET Core: https://hub.docker.com/r/microsoft/dotnet6
# Learn more about Docker tags: https://docs.docker.com/glossary/?term=tag
# and the Docker itself: https://opensource.com/resources/what-docker
image: mcr.microsoft.com/dotnet/core/sdk:3.1
image: mcr.microsoft.com/dotnet/sdk:5.0
# ### Define variables
#
......
......@@ -31,8 +31,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZilfAnalyzers", "src\Analyz
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZilfAnalyzers.Test", "src\Analyzers\ZilfAnalyzers.Test\ZilfAnalyzers.Test.csproj", "{55BC8693-4255-4F7C-B69D-734406DE6C88}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZilfAnalyzers.Vsix", "src\Analyzers\ZilfAnalyzers.Vsix\ZilfAnalyzers.Vsix.csproj", "{1451DB23-3FE9-4207-9903-9B5395934806}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{639D8160-38EF-4ED1-8202-8B8CFBE22FBD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{65A2B38C-4851-42E5-900C-DAD903A288F8}"
......@@ -221,17 +219,6 @@ Global
{55BC8693-4255-4F7C-B69D-734406DE6C88}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{55BC8693-4255-4F7C-B69D-734406DE6C88}.Release|x86.ActiveCfg = Release|Any CPU
{55BC8693-4255-4F7C-B69D-734406DE6C88}.Release|x86.Build.0 = Release|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.CI|Any CPU.ActiveCfg = Debug|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.CI|x86.ActiveCfg = Debug|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.CI|x86.Build.0 = Debug|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.Debug|x86.ActiveCfg = Debug|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.Debug|x86.Build.0 = Debug|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.Release|Any CPU.Build.0 = Release|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.Release|x86.ActiveCfg = Release|Any CPU
{1451DB23-3FE9-4207-9903-9B5395934806}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -251,7 +238,6 @@ Global
{F05EFB4A-9B94-4E4C-B158-BF1EE09584C7} = {639D8160-38EF-4ED1-8202-8B8CFBE22FBD}
{43F63D35-FA4B-4C7F-892C-E9A6A01AD60A} = {598B603F-F081-440B-BD43-4813EC6E043C}
{55BC8693-4255-4F7C-B69D-734406DE6C88} = {598B603F-F081-440B-BD43-4813EC6E043C}
{1451DB23-3FE9-4207-9903-9B5395934806} = {598B603F-F081-440B-BD43-4813EC6E043C}
{7FFC5410-FA1A-4777-870B-A8BBB5AE555E} = {1E9A9589-73D4-466C-9A3D-D44D058B2359}
{7C9E4970-9997-451B-BCDA-FB869C753F59} = {1E9A9589-73D4-466C-9A3D-D44D058B2359}
{25194AC6-1151-463C-82EA-5D5AD9B56F8D} = {1E9A9589-73D4-466C-9A3D-D44D058B2359}
......
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
......@@ -184,7 +183,6 @@ class Program {
throw new System.NotImplementedException();
}
[JetBrains.Annotations.NotNull]
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new ErrorExceptionUsageAnalyzer();
......
......@@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using JetBrains.Annotations;
using System.Threading.Tasks;
// ReSharper disable once CheckNamespace
......@@ -25,11 +24,11 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="document">The Document to apply the fix on</param>
/// <param name="codeAction">A CodeAction that will be applied to the Document.</param>
/// <returns>A Document with the changes from the CodeAction</returns>
static async Task<Document> ApplyFixAsync([JetBrains.Annotations.NotNull] Document document, [JetBrains.Annotations.NotNull] CodeAction codeAction)
static async Task<Document> ApplyFixAsync(Document document, CodeAction codeAction)
{
var operations = await codeAction.GetOperationsAsync(CancellationToken.None).ConfigureAwait(false);
var solution = operations.OfType<ApplyChangesOperation>().Single().ChangedSolution;
return solution.GetDocument(document.Id);
return solution.GetDocument(document.Id)!;
}
/// <summary>
......@@ -40,7 +39,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="diagnostics">The Diagnostics that existed in the code before the CodeFix was applied</param>
/// <param name="newDiagnostics">The Diagnostics that exist in the code after the CodeFix was applied</param>
/// <returns>A list of Diagnostics that only surfaced in the code after the CodeFix was applied</returns>
static IEnumerable<Diagnostic> GetNewDiagnostics([JetBrains.Annotations.NotNull] [InstantHandle] IEnumerable<Diagnostic> diagnostics, [JetBrains.Annotations.NotNull] [InstantHandle] IEnumerable<Diagnostic> newDiagnostics)
static IEnumerable<Diagnostic> GetNewDiagnostics(IEnumerable<Diagnostic> diagnostics, IEnumerable<Diagnostic> newDiagnostics)
{
var oldArray = diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
var newArray = newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
......@@ -67,9 +66,9 @@ namespace ZilfAnalyzers.Test.Helpers
/// </summary>
/// <param name="document">The Document to run the compiler diagnostic analyzers on</param>
/// <returns>The compiler diagnostics that were found in the code</returns>
static async Task<ImmutableArray<Diagnostic>> GetCompilerDiagnosticsAsync([JetBrains.Annotations.NotNull] Document document)
static async Task<ImmutableArray<Diagnostic>> GetCompilerDiagnosticsAsync(Document document)
{
return (await document.GetSemanticModelAsync().ConfigureAwait(false)).GetDiagnostics();
return (await document.GetSemanticModelAsync().ConfigureAwait(false))!.GetDiagnostics();
}
/// <summary>
......@@ -77,7 +76,6 @@ namespace ZilfAnalyzers.Test.Helpers
/// </summary>
/// <param name="document">The Document to be converted to a string</param>
/// <returns>A string containing the syntax of the Document after formatting</returns>
[JetBrains.Annotations.NotNull]
static async Task<string> GetStringFromDocumentAsync(Document document)
{
var simplifiedDoc = await Simplifier.ReduceAsync(document, Simplifier.Annotation).ConfigureAwait(false);
......
using System;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
// ReSharper disable once CheckNamespace
......@@ -40,10 +39,9 @@ namespace ZilfAnalyzers.Test.Helpers
{
DiagnosticResultLocation[] locations;
[JetBrains.Annotations.NotNull]
public DiagnosticResultLocation[] Locations
{
get => locations ??= new DiagnosticResultLocation[] { };
get => locations ??= Array.Empty<DiagnosticResultLocation>();
set => locations = value;
}
......
......@@ -8,9 +8,7 @@ using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using JetBrains.Annotations;
// ReSharper disable once CheckNamespace
namespace ZilfAnalyzers.Test.Helpers
......@@ -24,7 +22,6 @@ namespace ZilfAnalyzers.Test.Helpers
static readonly IReadOnlyCollection<MetadataReference> ProjectMetadataReferences =
GetProjectMetadataReferences();
[JetBrains.Annotations.NotNull, ItemNotNull]
private static IReadOnlyCollection<MetadataReference> GetProjectMetadataReferences()
{
var result = new List<MetadataReference>
......@@ -37,7 +34,7 @@ namespace ZilfAnalyzers.Test.Helpers
};
// https://luisfsgoncalves.wordpress.com/2017/03/20/referencing-system-assemblies-in-roslyn-compilations/
var trustedAssembliesPaths = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES"))?.Split(Path.PathSeparator);
var trustedAssembliesPaths = ((string?)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES"))?.Split(Path.PathSeparator);
if (trustedAssembliesPaths != null)
{
......@@ -71,8 +68,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="language">The language the source classes are in</param>
/// <param name="analyzer">The analyzer to be run on the sources</param>
/// <returns>An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location</returns>
[ItemNotNull]
private static async Task<Diagnostic[]> GetSortedDiagnosticsAsync([JetBrains.Annotations.NotNull] string[] sources, [JetBrains.Annotations.NotNull] string language, DiagnosticAnalyzer analyzer)
private static async Task<Diagnostic[]> GetSortedDiagnosticsAsync(string[] sources, string language, DiagnosticAnalyzer analyzer)
{
return await GetSortedDiagnosticsFromDocumentsAsync(analyzer, GetDocuments(sources, language)).ConfigureAwait(false);
}
......@@ -84,8 +80,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="analyzer">The analyzer to run on the documents</param>
/// <param name="documents">The Documents that the analyzer will be run on</param>
/// <returns>An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location</returns>
[ItemNotNull]
protected static async Task<Diagnostic[]> GetSortedDiagnosticsFromDocumentsAsync(DiagnosticAnalyzer analyzer, [JetBrains.Annotations.NotNull] Document[] documents)
protected static async Task<Diagnostic[]> GetSortedDiagnosticsFromDocumentsAsync(DiagnosticAnalyzer analyzer, Document[] documents)
{
var projects = new HashSet<Project>();
foreach (var document in documents)
......@@ -97,7 +92,10 @@ namespace ZilfAnalyzers.Test.Helpers
foreach (var project in projects)
{
var compilationWithAnalyzers = (await project.GetCompilationAsync().ConfigureAwait(false))
.WithAnalyzers(ImmutableArray.Create(analyzer));
?.WithAnalyzers(ImmutableArray.Create(analyzer));
if (compilationWithAnalyzers == null)
continue;
Debug.WriteLine("*** BEGIN ALL DIAGS ***");
foreach (var d in await compilationWithAnalyzers.GetAllDiagnosticsAsync())
......@@ -137,8 +135,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// </summary>
/// <param name="diagnostics">The list of Diagnostics to be sorted</param>
/// <returns>An IEnumerable containing the Diagnostics in order of Location</returns>
[JetBrains.Annotations.NotNull]
static Diagnostic[] SortDiagnostics([JetBrains.Annotations.NotNull] IEnumerable<Diagnostic> diagnostics)
static Diagnostic[] SortDiagnostics(IEnumerable<Diagnostic> diagnostics)
{
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
}
......@@ -152,8 +149,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="sources">Classes in the form of strings</param>
/// <param name="language">The language the source code is in</param>
/// <returns>A Tuple containing the Documents produced from the sources and their TextSpans if relevant</returns>
[JetBrains.Annotations.NotNull]
static Document[] GetDocuments([JetBrains.Annotations.NotNull] string[] sources, [JetBrains.Annotations.NotNull] string language)
static Document[] GetDocuments(string[] sources, string language)
{
if (language != LanguageNames.CSharp && language != LanguageNames.VisualBasic)
{
......@@ -188,7 +184,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="sources">Classes in the form of strings</param>
/// <param name="language">The language the source code is in</param>
/// <returns>A Project created out of the Documents created from the source strings</returns>
static Project CreateProject([JetBrains.Annotations.NotNull] string[] sources, string language = LanguageNames.CSharp)
static Project CreateProject(string[] sources, string language = LanguageNames.CSharp)
{
string fileNamePrefix = DefaultFilePathPrefix;
string fileExt = language == LanguageNames.CSharp ? CSharpDefaultFileExt : VisualBasicDefaultExt;
......@@ -208,7 +204,7 @@ namespace ZilfAnalyzers.Test.Helpers
solution = solution.AddDocument(documentId, newFileName, SourceText.From(source));
count++;
}
return solution.GetProject(projectId);
return solution.GetProject(projectId)!;
}
#endregion
}
......
......@@ -2,7 +2,6 @@
using System;
using System.Globalization;
using System.IO;
using JetBrains.Annotations;
// ReSharper disable once CheckNamespace
namespace ZilfAnalyzers.Test.Helpers
......@@ -20,7 +19,7 @@ namespace ZilfAnalyzers.Test.Helpers
ShouldEqualWithDiff(actualValue, expectedValue, diffStyle, Console.Out);
}
public static void ShouldEqualWithDiff([CanBeNull] this string actualValue, [CanBeNull] string expectedValue, DiffStyle diffStyle, TextWriter output)
public static void ShouldEqualWithDiff(this string? actualValue, string? expectedValue, DiffStyle diffStyle, TextWriter output)
{
if (actualValue == null || expectedValue == null)
{
......@@ -53,7 +52,6 @@ namespace ZilfAnalyzers.Test.Helpers
Assert.AreEqual(expectedValue, actualValue);
}
[JetBrains.Annotations.NotNull]
static string ToSafeString(this char c)
{
return c switch
......
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
......@@ -156,7 +155,6 @@ namespace Zilf.Diagnostics {
await VerifyCSharpFixAsync(test, fixtest);
}
[JetBrains.Annotations.NotNull]
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new MessageConstantAnalyzer();
......
......@@ -8,7 +8,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
// ReSharper disable once CheckNamespace
namespace ZilfAnalyzers.Test.Helpers
......@@ -23,14 +22,12 @@ namespace ZilfAnalyzers.Test.Helpers
/// Returns the codefix being tested (C#) - to be implemented in non-abstract class
/// </summary>
/// <returns>The CodeFixProvider to be used for CSharp code</returns>
[JetBrains.Annotations.NotNull]
protected abstract CodeFixProvider GetCSharpCodeFixProvider();
/// <summary>
/// Returns the codefix being tested (VB) - to be implemented in non-abstract class
/// </summary>
/// <returns>The CodeFixProvider to be used for VisualBasic code</returns>
[JetBrains.Annotations.NotNull]
protected abstract CodeFixProvider GetBasicCodeFixProvider();
/// <summary>
......@@ -86,7 +83,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="newSource">A class in the form of a string after the CodeFix was applied to it</param>
/// <param name="codeFixIndex">Index determining which codefix to apply if there are multiple</param>
/// <param name="allowNewCompilerDiagnostics">A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied</param>
static async Task VerifyFixAsync(string language, DiagnosticAnalyzer analyzer, [JetBrains.Annotations.NotNull] CodeFixProvider codeFixProvider, string oldSource, string newSource, int? codeFixIndex, bool allowNewCompilerDiagnostics)
static async Task VerifyFixAsync(string language, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string oldSource, string newSource, int? codeFixIndex, bool allowNewCompilerDiagnostics)
{
var document = CreateDocument(oldSource, language);
var analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync(analyzer, new[] { document }).ConfigureAwait(false);
......@@ -131,7 +128,7 @@ namespace ZilfAnalyzers.Test.Helpers
Assert.Fail(
"Fix introduced new compiler diagnostics:\r\n{0}\r\n\r\nNew document:\r\n{1}\r\n",
string.Join("\r\n", newCompilerDiagnostics.Select(d => d.ToString())),
(await document.GetSyntaxRootAsync().ConfigureAwait(false)).ToFullString());
(await document.GetSyntaxRootAsync().ConfigureAwait(false))?.ToFullString());
}
//check if there are analyzer diagnostics left after the code fix
......
......@@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JetBrains.Annotations;
// ReSharper disable once CheckNamespace
namespace ZilfAnalyzers.Test.Helpers
......@@ -19,13 +18,11 @@ namespace ZilfAnalyzers.Test.Helpers
/// <summary>
/// Get the CSharp analyzer being tested - to be implemented in non-abstract class
/// </summary>
[CanBeNull]
protected abstract DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer();
/// <summary>
/// Get the Visual Basic analyzer being tested (C#) - to be implemented in non-abstract class
/// </summary>
[CanBeNull]
protected abstract DiagnosticAnalyzer GetBasicDiagnosticAnalyzer();
#endregion
......@@ -38,7 +35,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// </summary>
/// <param name="source">A class in the form of a string to run the analyzer on</param>
/// <param name="expected"> DiagnosticResults that should appear after the analyzer is run on the source</param>
protected async Task VerifyCSharpDiagnosticAsync(string source, [JetBrains.Annotations.NotNull] params DiagnosticResult[] expected)
protected async Task VerifyCSharpDiagnosticAsync(string source, params DiagnosticResult[] expected)
{
await VerifyDiagnosticsAsync(new[] { source }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected);
}
......@@ -49,7 +46,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// </summary>
/// <param name="source">A class in the form of a string to run the analyzer on</param>
/// <param name="expected">DiagnosticResults that should appear after the analyzer is run on the source</param>
protected async Task VerifyBasicDiagnosticAsync(string source, [JetBrains.Annotations.NotNull] params DiagnosticResult[] expected)
protected async Task VerifyBasicDiagnosticAsync(string source, params DiagnosticResult[] expected)
{
await VerifyDiagnosticsAsync(new[] { source }, LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), expected);
}
......@@ -60,7 +57,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// </summary>
/// <param name="sources">An array of strings to create source documents from to run the analyzers on</param>
/// <param name="expected">DiagnosticResults that should appear after the analyzer is run on the sources</param>
protected async Task VerifyCSharpDiagnosticAsync([JetBrains.Annotations.NotNull] string[] sources, [JetBrains.Annotations.NotNull] params DiagnosticResult[] expected)
protected async Task VerifyCSharpDiagnosticAsync(string[] sources, params DiagnosticResult[] expected)
{
await VerifyDiagnosticsAsync(sources, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected);
}
......@@ -71,7 +68,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// </summary>
/// <param name="sources">An array of strings to create source documents from to run the analyzers on</param>
/// <param name="expected">DiagnosticResults that should appear after the analyzer is run on the sources</param>
protected async Task VerifyBasicDiagnosticAsync([JetBrains.Annotations.NotNull] string[] sources, [JetBrains.Annotations.NotNull] params DiagnosticResult[] expected)
protected async Task VerifyBasicDiagnosticAsync(string[] sources, params DiagnosticResult[] expected)
{
await VerifyDiagnosticsAsync(sources, LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), expected);
}
......@@ -84,7 +81,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="language">The language of the classes represented by the source strings</param>
/// <param name="analyzer">The analyzer to be run on the source code</param>
/// <param name="expected">DiagnosticResults that should appear after the analyzer is run on the sources</param>
static async Task VerifyDiagnosticsAsync([JetBrains.Annotations.NotNull] string[] sources, [JetBrains.Annotations.NotNull] string language, DiagnosticAnalyzer analyzer, [JetBrains.Annotations.NotNull] params DiagnosticResult[] expected)
static async Task VerifyDiagnosticsAsync(string[] sources, string language, DiagnosticAnalyzer analyzer, params DiagnosticResult[] expected)
{
var diagnostics = await GetSortedDiagnosticsAsync(sources, language, analyzer).ConfigureAwait(false);
VerifyDiagnosticResults(diagnostics, analyzer, expected);
......@@ -100,7 +97,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="actualResults">The Diagnostics found by the compiler after running the analyzer on the source code</param>
/// <param name="analyzer">The analyzer that was being run on the sources</param>
/// <param name="expectedResults">Diagnostic Results that should have appeared in the code</param>
static void VerifyDiagnosticResults([JetBrains.Annotations.NotNull] IEnumerable<Diagnostic> actualResults, DiagnosticAnalyzer analyzer, [JetBrains.Annotations.NotNull] params DiagnosticResult[] expectedResults)
static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResults, DiagnosticAnalyzer analyzer, params DiagnosticResult[] expectedResults)
{
var expectedCount = expectedResults.Length;
var actualResultsArray = actualResults as Diagnostic[] ?? actualResults.ToArray();
......@@ -172,7 +169,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="diagnostic">The diagnostic that was found in the code</param>
/// <param name="actual">The Location of the Diagnostic found in the code</param>
/// <param name="expected">The DiagnosticResultLocation that should have been found</param>
static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, [JetBrains.Annotations.NotNull] Location actual, DiagnosticResultLocation expected)
static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Location actual, DiagnosticResultLocation expected)
{
var actualSpan = actual.GetLineSpan();
......@@ -213,8 +210,7 @@ namespace ZilfAnalyzers.Test.Helpers
/// <param name="analyzer">The analyzer that this verifier tests</param>
/// <param name="diagnostics">The Diagnostics to be formatted</param>
/// <returns>The Diagnostics formatted as a string</returns>
[JetBrains.Annotations.NotNull]
static string FormatDiagnostics(DiagnosticAnalyzer analyzer, [JetBrains.Annotations.NotNull] params Diagnostic[] diagnostics)
static string FormatDiagnostics(DiagnosticAnalyzer analyzer, params Diagnostic[] diagnostics)
{
var builder = new StringBuilder();
for (int i = 0; i < diagnostics.Length; ++i)
......@@ -238,7 +234,7 @@ namespace ZilfAnalyzers.Test.Helpers
Assert.IsTrue(location.IsInSource,
$"Test base does not currently handle diagnostics in metadata locations. Diagnostic in metadata: {diagnostics[i]}\r\n");
string resultMethodName = diagnostics[i].Location.SourceTree.FilePath.EndsWith(".cs", System.StringComparison.InvariantCultureIgnoreCase) ? "GetCSharpResultAt" : "GetBasicResultAt";
string resultMethodName = diagnostics[i].Location.SourceTree!.FilePath.EndsWith(".cs", System.StringComparison.InvariantCultureIgnoreCase) ? "GetCSharpResultAt" : "GetBasicResultAt";
var linePosition = diagnostics[i].Location.GetLineSpan().StartLinePosition;
builder.AppendFormat("{0}({1}, {2}, {3}.{4})",
......
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
......@@ -87,14 +86,14 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting {
new DiagnosticResult
{
Id = "ZILF0005",
Message = "'object.Equals(object)' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
Message = "'object.Equals(object?)' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
Severity = DiagnosticSeverity.Warning,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 20, 17) }
},
new DiagnosticResult
{
Id = "ZILF0005",
Message = "'object.Equals(object)' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
Message = "'object.Equals(object?)' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
Severity = DiagnosticSeverity.Warning,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 23, 17) }
},
......@@ -129,21 +128,21 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting {
new DiagnosticResult
{
Id = "ZILF0005",
Message = "'object.Equals(object, object)' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
Message = "'object.Equals(object?, object?)' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
Severity = DiagnosticSeverity.Warning,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 30, 13) }
},
new DiagnosticResult
{
Id = "ZILF0005",
Message = "'object.Equals(object, object)' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
Message = "'object.Equals(object?, object?)' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
Severity = DiagnosticSeverity.Warning,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 31, 13) }
},
new DiagnosticResult
{
Id = "ZILF0006",
Message = "'FooList' overrides object.Equals(object) but does not override ZilObject.ExactlyEquals(ZilObject)",
Message = "'FooList' overrides object.Equals(object?) but does not override ZilObject.ExactlyEquals(ZilObject)",
Severity = DiagnosticSeverity.Warning,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 36, 30) }
},
......@@ -209,7 +208,6 @@ namespace Zilf.Diagnostics {
#endif
}
[JetBrains.Annotations.NotNull]
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new ZilObjectAnalyzer();
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="JunitXml.TestLogger" Version="2.1.78" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.7.3069">
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.9.1024">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
......
is_global = true
build_property.TargetFramework =
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids = {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
build_property.PublishSingleFile =
build_property.IncludeAllContentForSelfExtract =
build_property._SupportedPlatformList =
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\Microsoft.CodeAnalysis.BannedApiAnalyzers.3.3.0\build\Microsoft.CodeAnalysis.BannedApiAnalyzers.props" Condition="Exists('..\..\..\packages\Microsoft.CodeAnalysis.BannedApiAnalyzers.3.3.0\build\Microsoft.CodeAnalysis.BannedApiAnalyzers.props')" />
<Import Project="..\..\..\packages\Microsoft.VSSDK.BuildTools.16.7.3069\build\Microsoft.VSSDK.BuildTools.props" Condition="Exists('..\..\..\packages\Microsoft.VSSDK.BuildTools.16.7.3069\build\Microsoft.VSSDK.BuildTools.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<PlatformTarget>AnyCPU</PlatformTarget>
<SchemaVersion>2.0</SchemaVersion>