From 2c8342655ae16127db312ff1b2f0e83765d0a64d Mon Sep 17 00:00:00 2001 From: Manfred Brands Date: Thu, 18 Apr 2024 22:29:55 +0800 Subject: [PATCH] Split off CodeFixes from analyzer .NET8.0 says there should be no Workspace dependency in an analyzer. CodeFixes should only be loaded by an editor. --- build.cake | 11 +++- src/Directory.Build.props | 17 +++++- .../AreEqualClassicModelAssertUsageCodeFix.cs | 1 - ...eNotEqualClassicModelAssertUsageCodeFix.cs | 0 ...reNotSameClassicModelAssertUsageCodeFix.cs | 0 .../AreSameClassicModelAssertUsageCodeFix.cs | 0 .../ClassicModelAssertUsageCodeFix.cs | 0 .../ContainsClassicModelAssertUsageCodeFix.cs | 0 .../GreaterClassicModelAssertUsageCodeFix.cs | 0 ...erOrEqualClassicModelAssertUsageCodeFix.cs | 0 ...nableFromClassicModelAssertUsageCodeFix.cs | 0 .../IsEmptyClassicModelAssertUsageCodeFix.cs | 0 ...eAndFalseClassicModelAssertUsageCodeFix.cs | 0 ...nstanceOfClassicModelAssertUsageCodeFix.cs | 0 .../IsNaNClassicModelAssertUsageCodeFix.cs | 0 ...nableFromClassicModelAssertUsageCodeFix.cs | 0 ...sNotEmptyClassicModelAssertUsageCodeFix.cs | 0 ...nstanceOfClassicModelAssertUsageCodeFix.cs | 0 ...ndNotNullClassicModelAssertUsageCodeFix.cs | 0 ...llAndNullClassicModelAssertUsageCodeFix.cs | 0 ...ueAndTrueClassicModelAssertUsageCodeFix.cs | 0 ...ClassicModelAssertUsageCondensedCodeFix.cs | 0 .../LessClassicModelAssertUsageCodeFix.cs | 0 ...ssOrEqualClassicModelAssertUsageCodeFix.cs | 0 .../NegativeClassicModelAssertUsageCodeFix.cs | 0 .../NotZeroClassicModelAssertUsageCodeFix.cs | 0 .../PositiveClassicModelAssertUsageCodeFix.cs | 0 .../ZeroClassicModelAssertUsageCodeFix.cs | 0 .../CollectionAssertUsageCodeFix.cs | 0 .../ConstActualValueUsageCodeFix.cs | 0 .../BaseConditionConstraintCodeFix.cs | 2 +- .../ComparisonConstraintUsageCodeFix.cs | 0 .../EqualConstraintUsageCodeFix.cs | 0 .../SomeItemsConstraintUsageCodeFix.cs | 0 .../StringConstraintUsageCodeFix.cs | 0 .../DelegateRequiredCodeFix.cs | 0 .../ArgumentListSyntaxExtensions.cs | 10 +++- .../Helpers/CodeFixHelper.cs | 1 + .../Helpers/Constraints.cs | 0 .../MissingProperty/MissingPropertyCodeFix.cs | 0 .../NonTestMethodAccessibilityLevelCodeFix.cs | 0 .../SameAsOnValueTypesCodeFix.cs | 0 .../SimplifyValues/SimplifyValuesCodeFix.cs | 0 .../SourceCommon/UseNameofFix.cs | 0 .../StringAssertUsageCodeFix.cs | 0 .../TestContextWriteIsObsoleteCodeFix.cs | 0 .../TestMethodAccessibilityLevelCodeFix.cs | 0 ...ringFormatToInterpolatableStringCodeFix.cs | 0 .../UseAssertMultipleCodeFix.cs | 0 .../UseCollectionConstraintCodeFix.cs | 0 .../WithinUsage/WithinUsageCodeFix.cs | 0 .../nunit.analyzers.codefixes.csproj | 15 +++++ .../nunit.analyzers.nuspec | 9 +-- src/nunit.analyzers.sln | 6 ++ src/nunit.analyzers.tests/.editorconfig | 14 +++++ .../CollectionAssertUsageAnalyzerTests.cs | 1 - .../DefaultEnabledAnalyzer.cs | 49 ---------------- ...tantiatedInternalClassesSuppressorTests.cs | 2 - .../DisposableFieldsSuppressorTests.cs | 2 - src/nunit.analyzers.tests/SetUpFixture.cs | 3 +- src/nunit.analyzers.tests/TestHelpers.cs | 3 +- .../nunit.analyzers.tests.csproj | 3 +- ...idUninstantiatedInternalClassSuppressor.cs | 1 - ...eferencePossiblyNullReferenceSuppressor.cs | 2 +- ...sableFieldsShouldBeDisposableSuppressor.cs | 1 - .../Extensions/ITypeSymbolExtensions.cs | 2 + .../Helpers/NUnitEqualityComparerHelper.cs | 2 +- .../MissingPropertyAnalyzer.cs | 4 +- src/nunit.analyzers/nunit.analyzers.csproj | 8 +-- src/nunit.analyzers/tools/install.ps1 | 49 ---------------- src/nunit.analyzers/tools/uninstall.ps1 | 56 ------------------- 71 files changed, 87 insertions(+), 187 deletions(-) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFix.cs (99%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/AreNotEqualClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/AreNotSameClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/AreSameClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/ClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/ContainsClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/GreaterClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/GreaterOrEqualClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsAssignableFromClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsEmptyClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsFalseAndFalseClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsInstanceOfClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsNaNClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsNotAssignableFromClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsNotEmptyClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsNotInstanceOfClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsNotNullAndNotNullClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsNullAndNullClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCondensedCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/LessClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/LessOrEqualClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/NegativeClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/NotZeroClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/PositiveClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ClassicModelAssertUsage/ZeroClassicModelAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/CollectionAssertUsage/CollectionAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ConstActualValueUsage/ConstActualValueUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ConstraintUsage/BaseConditionConstraintCodeFix.cs (99%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ConstraintUsage/ComparisonConstraintUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ConstraintUsage/EqualConstraintUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ConstraintUsage/SomeItemsConstraintUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/ConstraintUsage/StringConstraintUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/DelegateRequired/DelegateRequiredCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/Extensions/ArgumentListSyntaxExtensions.cs (92%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/Helpers/CodeFixHelper.cs (99%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/Helpers/Constraints.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/MissingProperty/MissingPropertyCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/NonTestMethodAccessibilityLevel/NonTestMethodAccessibilityLevelCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/SameAsOnValueTypes/SameAsOnValueTypesCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/SimplifyValues/SimplifyValuesCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/SourceCommon/UseNameofFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/StringAssertUsage/StringAssertUsageCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/TestContextWriteIsObsolete/TestContextWriteIsObsoleteCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/TestMethodAccessibilityLevel/TestMethodAccessibilityLevelCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/UpdateStringFormatToInterpolatableString/UpdateStringFormatToInterpolatableStringCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/UseAssertMultiple/UseAssertMultipleCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/UseCollectionConstraint/UseCollectionConstraintCodeFix.cs (100%) rename src/{nunit.analyzers => nunit.analyzers.codefixes}/WithinUsage/WithinUsageCodeFix.cs (100%) create mode 100644 src/nunit.analyzers.codefixes/nunit.analyzers.codefixes.csproj rename src/{nunit.analyzers => }/nunit.analyzers.nuspec (82%) create mode 100644 src/nunit.analyzers.tests/.editorconfig delete mode 100644 src/nunit.analyzers.tests/DefaultEnabledAnalyzer.cs delete mode 100644 src/nunit.analyzers/tools/install.ps1 delete mode 100644 src/nunit.analyzers/tools/uninstall.ps1 diff --git a/build.cake b/build.cake index 8463f445..d1f5a200 100644 --- a/build.cake +++ b/build.cake @@ -28,12 +28,14 @@ var PACKAGE_DIR = PROJECT_DIR + "package/" + configuration; var ANALYZERS_TESTS_OUTPUT_DIR = SRC_DIR + "nunit.analyzers.tests/bin/"; var ANALYZERS_OUTPUT_DIR = SRC_DIR + "nunit.analyzers/bin/"; +var CODEFIXES_OUTPUT_DIR = SRC_DIR + "nunit.analyzers.codefixes/bin/"; // Solution var SOLUTION_FILE = PROJECT_DIR + "src/nunit.analyzers.sln"; // Projects var ANALYZER_PROJECT = SRC_DIR + "nunit.analyzers/nunit.analyzers.csproj"; +var CODEFIXES_PROJECT = SRC_DIR + "nunit.analyzers.codefixes/nunit.analyzers.codefixes.csproj"; var TEST_PROJECT = SRC_DIR + "nunit.analyzers.tests/nunit.analyzers.tests.csproj"; // Package sources for nuget restore @@ -103,6 +105,7 @@ Task("Clean") .Does(() => { CleanDirectory(ANALYZERS_TESTS_OUTPUT_DIR); + CleanDirectory(CODEFIXES_OUTPUT_DIR); CleanDirectory(ANALYZERS_OUTPUT_DIR); }); @@ -128,7 +131,7 @@ Task("Build") .IsDependentOn("RestorePackages") .Does(() => { - DotNetBuild(ANALYZER_PROJECT, new DotNetBuildSettings + var buildSettings = new DotNetBuildSettings { Configuration = configuration, Verbosity = DotNetVerbosity.Minimal, @@ -138,7 +141,9 @@ Task("Build") Version = packageVersion, FileVersion = packageVersion, } - }); + }; + DotNetBuild(ANALYZER_PROJECT, buildSettings); + DotNetBuild(CODEFIXES_PROJECT, buildSettings); }); ////////////////////////////////////////////////////////////////////// @@ -192,7 +197,7 @@ Task("Pack") .IsDependentOn("Build") .Does(() => { - NuGetPack("./src/nunit.analyzers/nunit.analyzers.nuspec", new NuGetPackSettings() + NuGetPack("./src/nunit.analyzers.nuspec", new NuGetPackSettings() { Version = packageVersionString, OutputDirectory = PACKAGE_DIR + "/" + targetFramework, diff --git a/src/Directory.Build.props b/src/Directory.Build.props index ddf9e4ec..7ec0a8c1 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -6,6 +6,8 @@ NUnit Project NUnit Analyzers Copyright © 2018-2025 NUnit project + + true @@ -14,16 +16,24 @@ preview false + true false AllEnabledByDefault - 5 - $(NoWarn);CA1014 + 8 + $(NoWarn);CA1014;CS1591 + + + true + - + @@ -39,6 +49,7 @@ + diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFix.cs similarity index 99% rename from src/nunit.analyzers/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFix.cs index 58fae6e6..21d3fe40 100644 --- a/src/nunit.analyzers/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFix.cs +++ b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreEqualClassicModelAssertUsageCodeFix.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/AreNotEqualClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreNotEqualClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/AreNotEqualClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreNotEqualClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/AreNotSameClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreNotSameClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/AreNotSameClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreNotSameClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/AreSameClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreSameClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/AreSameClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/AreSameClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/ClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/ClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/ClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/ClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/ContainsClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/ContainsClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/ContainsClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/ContainsClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/GreaterClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/GreaterClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/GreaterClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/GreaterClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/GreaterOrEqualClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/GreaterOrEqualClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/GreaterOrEqualClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/GreaterOrEqualClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsAssignableFromClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsAssignableFromClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsAssignableFromClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsAssignableFromClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsEmptyClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsEmptyClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsEmptyClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsEmptyClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsFalseAndFalseClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsFalseAndFalseClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsFalseAndFalseClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsFalseAndFalseClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsInstanceOfClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsInstanceOfClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsInstanceOfClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsInstanceOfClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsNaNClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNaNClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsNaNClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNaNClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsNotAssignableFromClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNotAssignableFromClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsNotAssignableFromClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNotAssignableFromClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsNotEmptyClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNotEmptyClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsNotEmptyClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNotEmptyClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsNotInstanceOfClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNotInstanceOfClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsNotInstanceOfClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNotInstanceOfClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsNotNullAndNotNullClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNotNullAndNotNullClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsNotNullAndNotNullClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNotNullAndNotNullClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsNullAndNullClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNullAndNullClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsNullAndNullClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsNullAndNullClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCondensedCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCondensedCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCondensedCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/IsTrueAndTrueClassicModelAssertUsageCondensedCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/LessClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/LessClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/LessClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/LessClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/LessOrEqualClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/LessOrEqualClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/LessOrEqualClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/LessOrEqualClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/NegativeClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/NegativeClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/NegativeClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/NegativeClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/NotZeroClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/NotZeroClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/NotZeroClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/NotZeroClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/PositiveClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/PositiveClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/PositiveClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/PositiveClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ClassicModelAssertUsage/ZeroClassicModelAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ClassicModelAssertUsage/ZeroClassicModelAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ClassicModelAssertUsage/ZeroClassicModelAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ClassicModelAssertUsage/ZeroClassicModelAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/CollectionAssertUsage/CollectionAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/CollectionAssertUsage/CollectionAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/CollectionAssertUsage/CollectionAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/CollectionAssertUsage/CollectionAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/ConstActualValueUsage/ConstActualValueUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ConstActualValueUsage/ConstActualValueUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ConstActualValueUsage/ConstActualValueUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ConstActualValueUsage/ConstActualValueUsageCodeFix.cs diff --git a/src/nunit.analyzers/ConstraintUsage/BaseConditionConstraintCodeFix.cs b/src/nunit.analyzers.codefixes/ConstraintUsage/BaseConditionConstraintCodeFix.cs similarity index 99% rename from src/nunit.analyzers/ConstraintUsage/BaseConditionConstraintCodeFix.cs rename to src/nunit.analyzers.codefixes/ConstraintUsage/BaseConditionConstraintCodeFix.cs index c6622747..e9a5dc34 100644 --- a/src/nunit.analyzers/ConstraintUsage/BaseConditionConstraintCodeFix.cs +++ b/src/nunit.analyzers.codefixes/ConstraintUsage/BaseConditionConstraintCodeFix.cs @@ -141,7 +141,7 @@ protected virtual (ExpressionSyntax? actual, ExpressionSyntax? constraintExpress { actualArgumentWithCorrectTrivia, constraintArgumentWithCorrectTrivia - }.Union(remainingArguments); + }.Concat(remainingArguments); var newArgumentsList = assertNode.ArgumentList.WithArguments(newArguments); diff --git a/src/nunit.analyzers/ConstraintUsage/ComparisonConstraintUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ConstraintUsage/ComparisonConstraintUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ConstraintUsage/ComparisonConstraintUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ConstraintUsage/ComparisonConstraintUsageCodeFix.cs diff --git a/src/nunit.analyzers/ConstraintUsage/EqualConstraintUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ConstraintUsage/EqualConstraintUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ConstraintUsage/EqualConstraintUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ConstraintUsage/EqualConstraintUsageCodeFix.cs diff --git a/src/nunit.analyzers/ConstraintUsage/SomeItemsConstraintUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ConstraintUsage/SomeItemsConstraintUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ConstraintUsage/SomeItemsConstraintUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ConstraintUsage/SomeItemsConstraintUsageCodeFix.cs diff --git a/src/nunit.analyzers/ConstraintUsage/StringConstraintUsageCodeFix.cs b/src/nunit.analyzers.codefixes/ConstraintUsage/StringConstraintUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/ConstraintUsage/StringConstraintUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/ConstraintUsage/StringConstraintUsageCodeFix.cs diff --git a/src/nunit.analyzers/DelegateRequired/DelegateRequiredCodeFix.cs b/src/nunit.analyzers.codefixes/DelegateRequired/DelegateRequiredCodeFix.cs similarity index 100% rename from src/nunit.analyzers/DelegateRequired/DelegateRequiredCodeFix.cs rename to src/nunit.analyzers.codefixes/DelegateRequired/DelegateRequiredCodeFix.cs diff --git a/src/nunit.analyzers/Extensions/ArgumentListSyntaxExtensions.cs b/src/nunit.analyzers.codefixes/Extensions/ArgumentListSyntaxExtensions.cs similarity index 92% rename from src/nunit.analyzers/Extensions/ArgumentListSyntaxExtensions.cs rename to src/nunit.analyzers.codefixes/Extensions/ArgumentListSyntaxExtensions.cs index f23a88cc..a02d6976 100644 --- a/src/nunit.analyzers/Extensions/ArgumentListSyntaxExtensions.cs +++ b/src/nunit.analyzers.codefixes/Extensions/ArgumentListSyntaxExtensions.cs @@ -13,6 +13,10 @@ public static ArgumentListSyntax WithArguments( this ArgumentListSyntax @this, IEnumerable newArguments) { + using var enumerator = newArguments.GetEnumerator(); + if (!enumerator.MoveNext()) + return @this; + var originalArguments = @this.Arguments; var originalSeparators = originalArguments.GetSeparators().ToArray(); @@ -29,10 +33,12 @@ public static ArgumentListSyntax WithArguments( // or any of the original separators had a trailing newline. var shouldAddTrailingNewlineAfterComma = TryGetFirstEndOfLineTrivia(@this.OpenParenToken, originalSeparators, out var trailingTrivia); - var nodesAndTokens = new List { newArguments.First() }; + var nodesAndTokens = new List { enumerator.Current }; - foreach (var newArgument in newArguments.Skip(1)) + while (enumerator.MoveNext()) { + var newArgument = enumerator.Current; + // If argument is not replaced - take original separator. Otherwise - comma var oldIndex = originalArguments.IndexOf(newArgument); var separator = originalSeparators.ElementAtOrDefault(oldIndex - 1); diff --git a/src/nunit.analyzers/Helpers/CodeFixHelper.cs b/src/nunit.analyzers.codefixes/Helpers/CodeFixHelper.cs similarity index 99% rename from src/nunit.analyzers/Helpers/CodeFixHelper.cs rename to src/nunit.analyzers.codefixes/Helpers/CodeFixHelper.cs index 0fb1d683..229ea613 100644 --- a/src/nunit.analyzers/Helpers/CodeFixHelper.cs +++ b/src/nunit.analyzers.codefixes/Helpers/CodeFixHelper.cs @@ -107,6 +107,7 @@ internal static class CodeFixHelper /// /// The arguments passed to the 'Assert' method. /// The argument needed for the actual method, any more are assumed messages. + /// The params args is passed as an array instead of individual parameters. public static void UpdateStringFormatToFormattableString(List arguments, int minimumNumberOfArguments, bool argsIsArray) { // If only 1 extra argument is passed, it must be a non-formattable message. diff --git a/src/nunit.analyzers/Helpers/Constraints.cs b/src/nunit.analyzers.codefixes/Helpers/Constraints.cs similarity index 100% rename from src/nunit.analyzers/Helpers/Constraints.cs rename to src/nunit.analyzers.codefixes/Helpers/Constraints.cs diff --git a/src/nunit.analyzers/MissingProperty/MissingPropertyCodeFix.cs b/src/nunit.analyzers.codefixes/MissingProperty/MissingPropertyCodeFix.cs similarity index 100% rename from src/nunit.analyzers/MissingProperty/MissingPropertyCodeFix.cs rename to src/nunit.analyzers.codefixes/MissingProperty/MissingPropertyCodeFix.cs diff --git a/src/nunit.analyzers/NonTestMethodAccessibilityLevel/NonTestMethodAccessibilityLevelCodeFix.cs b/src/nunit.analyzers.codefixes/NonTestMethodAccessibilityLevel/NonTestMethodAccessibilityLevelCodeFix.cs similarity index 100% rename from src/nunit.analyzers/NonTestMethodAccessibilityLevel/NonTestMethodAccessibilityLevelCodeFix.cs rename to src/nunit.analyzers.codefixes/NonTestMethodAccessibilityLevel/NonTestMethodAccessibilityLevelCodeFix.cs diff --git a/src/nunit.analyzers/SameAsOnValueTypes/SameAsOnValueTypesCodeFix.cs b/src/nunit.analyzers.codefixes/SameAsOnValueTypes/SameAsOnValueTypesCodeFix.cs similarity index 100% rename from src/nunit.analyzers/SameAsOnValueTypes/SameAsOnValueTypesCodeFix.cs rename to src/nunit.analyzers.codefixes/SameAsOnValueTypes/SameAsOnValueTypesCodeFix.cs diff --git a/src/nunit.analyzers/SimplifyValues/SimplifyValuesCodeFix.cs b/src/nunit.analyzers.codefixes/SimplifyValues/SimplifyValuesCodeFix.cs similarity index 100% rename from src/nunit.analyzers/SimplifyValues/SimplifyValuesCodeFix.cs rename to src/nunit.analyzers.codefixes/SimplifyValues/SimplifyValuesCodeFix.cs diff --git a/src/nunit.analyzers/SourceCommon/UseNameofFix.cs b/src/nunit.analyzers.codefixes/SourceCommon/UseNameofFix.cs similarity index 100% rename from src/nunit.analyzers/SourceCommon/UseNameofFix.cs rename to src/nunit.analyzers.codefixes/SourceCommon/UseNameofFix.cs diff --git a/src/nunit.analyzers/StringAssertUsage/StringAssertUsageCodeFix.cs b/src/nunit.analyzers.codefixes/StringAssertUsage/StringAssertUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/StringAssertUsage/StringAssertUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/StringAssertUsage/StringAssertUsageCodeFix.cs diff --git a/src/nunit.analyzers/TestContextWriteIsObsolete/TestContextWriteIsObsoleteCodeFix.cs b/src/nunit.analyzers.codefixes/TestContextWriteIsObsolete/TestContextWriteIsObsoleteCodeFix.cs similarity index 100% rename from src/nunit.analyzers/TestContextWriteIsObsolete/TestContextWriteIsObsoleteCodeFix.cs rename to src/nunit.analyzers.codefixes/TestContextWriteIsObsolete/TestContextWriteIsObsoleteCodeFix.cs diff --git a/src/nunit.analyzers/TestMethodAccessibilityLevel/TestMethodAccessibilityLevelCodeFix.cs b/src/nunit.analyzers.codefixes/TestMethodAccessibilityLevel/TestMethodAccessibilityLevelCodeFix.cs similarity index 100% rename from src/nunit.analyzers/TestMethodAccessibilityLevel/TestMethodAccessibilityLevelCodeFix.cs rename to src/nunit.analyzers.codefixes/TestMethodAccessibilityLevel/TestMethodAccessibilityLevelCodeFix.cs diff --git a/src/nunit.analyzers/UpdateStringFormatToInterpolatableString/UpdateStringFormatToInterpolatableStringCodeFix.cs b/src/nunit.analyzers.codefixes/UpdateStringFormatToInterpolatableString/UpdateStringFormatToInterpolatableStringCodeFix.cs similarity index 100% rename from src/nunit.analyzers/UpdateStringFormatToInterpolatableString/UpdateStringFormatToInterpolatableStringCodeFix.cs rename to src/nunit.analyzers.codefixes/UpdateStringFormatToInterpolatableString/UpdateStringFormatToInterpolatableStringCodeFix.cs diff --git a/src/nunit.analyzers/UseAssertMultiple/UseAssertMultipleCodeFix.cs b/src/nunit.analyzers.codefixes/UseAssertMultiple/UseAssertMultipleCodeFix.cs similarity index 100% rename from src/nunit.analyzers/UseAssertMultiple/UseAssertMultipleCodeFix.cs rename to src/nunit.analyzers.codefixes/UseAssertMultiple/UseAssertMultipleCodeFix.cs diff --git a/src/nunit.analyzers/UseCollectionConstraint/UseCollectionConstraintCodeFix.cs b/src/nunit.analyzers.codefixes/UseCollectionConstraint/UseCollectionConstraintCodeFix.cs similarity index 100% rename from src/nunit.analyzers/UseCollectionConstraint/UseCollectionConstraintCodeFix.cs rename to src/nunit.analyzers.codefixes/UseCollectionConstraint/UseCollectionConstraintCodeFix.cs diff --git a/src/nunit.analyzers/WithinUsage/WithinUsageCodeFix.cs b/src/nunit.analyzers.codefixes/WithinUsage/WithinUsageCodeFix.cs similarity index 100% rename from src/nunit.analyzers/WithinUsage/WithinUsageCodeFix.cs rename to src/nunit.analyzers.codefixes/WithinUsage/WithinUsageCodeFix.cs diff --git a/src/nunit.analyzers.codefixes/nunit.analyzers.codefixes.csproj b/src/nunit.analyzers.codefixes/nunit.analyzers.codefixes.csproj new file mode 100644 index 00000000..0ccb200a --- /dev/null +++ b/src/nunit.analyzers.codefixes/nunit.analyzers.codefixes.csproj @@ -0,0 +1,15 @@ + + + NUnit.Analyzers + netstandard2.0 + + + + + + + + + + + diff --git a/src/nunit.analyzers/nunit.analyzers.nuspec b/src/nunit.analyzers.nuspec similarity index 82% rename from src/nunit.analyzers/nunit.analyzers.nuspec rename to src/nunit.analyzers.nuspec index e2e61e04..94b9d064 100644 --- a/src/nunit.analyzers/nunit.analyzers.nuspec +++ b/src/nunit.analyzers.nuspec @@ -25,10 +25,11 @@ Version 3.0 and upwards works in Visual Studio 2019 (version 16.3) or newer and - + + - - - + + + diff --git a/src/nunit.analyzers.sln b/src/nunit.analyzers.sln index 26a7cff0..ac6a4c11 100644 --- a/src/nunit.analyzers.sln +++ b/src/nunit.analyzers.sln @@ -112,6 +112,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\global.json = ..\global.json EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.analyzers.codefixes", "nunit.analyzers.codefixes\nunit.analyzers.codefixes.csproj", "{E77F7B58-BD1F-48F6-BB6A-E55CCE12C714}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -126,6 +128,10 @@ Global {070974CB-B483-4347-BA5A-53ED977E639C}.Debug|Any CPU.Build.0 = Debug|Any CPU {070974CB-B483-4347-BA5A-53ED977E639C}.Release|Any CPU.ActiveCfg = Release|Any CPU {070974CB-B483-4347-BA5A-53ED977E639C}.Release|Any CPU.Build.0 = Release|Any CPU + {E77F7B58-BD1F-48F6-BB6A-E55CCE12C714}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E77F7B58-BD1F-48F6-BB6A-E55CCE12C714}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E77F7B58-BD1F-48F6-BB6A-E55CCE12C714}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E77F7B58-BD1F-48F6-BB6A-E55CCE12C714}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/nunit.analyzers.tests/.editorconfig b/src/nunit.analyzers.tests/.editorconfig new file mode 100644 index 00000000..f942396d --- /dev/null +++ b/src/nunit.analyzers.tests/.editorconfig @@ -0,0 +1,14 @@ +# C# files +[*.cs] + +# Not relevant for single execution unit tests + +# CA1861: Avoid constant arrays as arguments +dotnet_diagnostic.CA1861.severity = none + +# CA1859: Use concrete types when possible for improved performance +dotnet_diagnostic.CA1859.severity = none + +# CA1863 Cache a 'CompositeFormat' for repeated use in this formatting operation +dotnet_diagnostic.CA1863.severity = none + diff --git a/src/nunit.analyzers.tests/CollectionAssertUsage/CollectionAssertUsageAnalyzerTests.cs b/src/nunit.analyzers.tests/CollectionAssertUsage/CollectionAssertUsageAnalyzerTests.cs index e6b45990..96d13729 100644 --- a/src/nunit.analyzers.tests/CollectionAssertUsage/CollectionAssertUsageAnalyzerTests.cs +++ b/src/nunit.analyzers.tests/CollectionAssertUsage/CollectionAssertUsageAnalyzerTests.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Gu.Roslyn.Asserts; using Microsoft.CodeAnalysis.Diagnostics; -using NUnit.Analyzers.ClassicModelAssertUsage; using NUnit.Analyzers.CollectionAssertUsage; using NUnit.Analyzers.Constants; using NUnit.Framework; diff --git a/src/nunit.analyzers.tests/DefaultEnabledAnalyzer.cs b/src/nunit.analyzers.tests/DefaultEnabledAnalyzer.cs deleted file mode 100644 index ac90f21d..00000000 --- a/src/nunit.analyzers.tests/DefaultEnabledAnalyzer.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Immutable; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; - -namespace NUnit.Analyzers.Tests -{ - [DiagnosticAnalyzer(LanguageNames.CSharp)] -#pragma warning disable RS1036 // Specify analyzer banned API enforcement setting - internal sealed class DefaultEnabledAnalyzer : DiagnosticAnalyzer -#pragma warning restore RS1036 // Specify analyzer banned API enforcement setting - { - private readonly DiagnosticAnalyzer inner; - - internal DefaultEnabledAnalyzer(DiagnosticAnalyzer inner) - { - this.inner = inner; - this.SupportedDiagnostics = EnabledDiagnostics(inner.SupportedDiagnostics); - - static ImmutableArray EnabledDiagnostics(ImmutableArray source) - { - var builder = ImmutableArray.CreateBuilder(source.Length); - foreach (var diagnostic in source) - { - builder.Add( - new DiagnosticDescriptor( - diagnostic.Id, - diagnostic.Title, - diagnostic.MessageFormat, - diagnostic.Category, - diagnostic.DefaultSeverity, - isEnabledByDefault: true, - diagnostic.Description, - diagnostic.HelpLinkUri, - diagnostic.CustomTags?.ToArray() ?? Array.Empty())); - } - - return builder.MoveToImmutable(); - } - } - - public override ImmutableArray SupportedDiagnostics { get; } - -#pragma warning disable RS1025, RS1026 - public override void Initialize(AnalysisContext context) => this.inner.Initialize(context); -#pragma warning restore RS1025, RS1026 - } -} diff --git a/src/nunit.analyzers.tests/DiagnosticSuppressors/AvoidUninstantiatedInternalClassesSuppressorTests.cs b/src/nunit.analyzers.tests/DiagnosticSuppressors/AvoidUninstantiatedInternalClassesSuppressorTests.cs index 1f44b734..9a6bdc50 100644 --- a/src/nunit.analyzers.tests/DiagnosticSuppressors/AvoidUninstantiatedInternalClassesSuppressorTests.cs +++ b/src/nunit.analyzers.tests/DiagnosticSuppressors/AvoidUninstantiatedInternalClassesSuppressorTests.cs @@ -63,8 +63,6 @@ public void OneTimeSetUp() Assembly netAnalyzerAssembly = Assembly.LoadFrom(netAnalyzersPath); Type analyzerType = netAnalyzerAssembly.GetType("Microsoft.CodeQuality.CSharp.Analyzers.Maintainability.CSharpAvoidUninstantiatedInternalClasses", true)!; this.analyzer = (DiagnosticAnalyzer)Activator.CreateInstance(analyzerType)!; - - this.analyzer = new DefaultEnabledAnalyzer(this.analyzer); } [Test] diff --git a/src/nunit.analyzers.tests/DiagnosticSuppressors/DisposableFieldsSuppressorTests.cs b/src/nunit.analyzers.tests/DiagnosticSuppressors/DisposableFieldsSuppressorTests.cs index 0466dd11..18d9fddf 100644 --- a/src/nunit.analyzers.tests/DiagnosticSuppressors/DisposableFieldsSuppressorTests.cs +++ b/src/nunit.analyzers.tests/DiagnosticSuppressors/DisposableFieldsSuppressorTests.cs @@ -23,8 +23,6 @@ public void OneTimeSetUp() Assembly netAnalyzerAssembly = Assembly.LoadFrom(netAnalyzersPath); Type analyzerType = netAnalyzerAssembly.GetType("Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.TypesThatOwnDisposableFieldsShouldBeDisposableAnalyzer", true)!; this.analyzer = (DiagnosticAnalyzer)Activator.CreateInstance(analyzerType)!; - - this.analyzer = new DefaultEnabledAnalyzer(this.analyzer); } [Test] diff --git a/src/nunit.analyzers.tests/SetUpFixture.cs b/src/nunit.analyzers.tests/SetUpFixture.cs index 8b7b02a5..1988e8c6 100644 --- a/src/nunit.analyzers.tests/SetUpFixture.cs +++ b/src/nunit.analyzers.tests/SetUpFixture.cs @@ -19,7 +19,8 @@ public void SetDefaults() .WithMetadataReferences(MetadataReferences.Transitive(typeof(Assert), typeof(ClassicAssert))) .WithParseOption(new CSharpParseOptions(LanguageVersion.Preview).WithPreprocessorSymbols("NUNIT4")); #else - .WithMetadataReferences(MetadataReferences.Transitive(typeof(Assert))); + .WithMetadataReferences(MetadataReferences.Transitive(typeof(Assert))) + .WithParseOption(new CSharpParseOptions(LanguageVersion.Preview).WithPreprocessorSymbols("NUNIT3")); #endif } } diff --git a/src/nunit.analyzers.tests/TestHelpers.cs b/src/nunit.analyzers.tests/TestHelpers.cs index 82d83bc9..006fec84 100644 --- a/src/nunit.analyzers.tests/TestHelpers.cs +++ b/src/nunit.analyzers.tests/TestHelpers.cs @@ -32,7 +32,8 @@ internal static async Task SuppressedOrNot(DiagnosticAnalyzer analyzer, Diagnost Assert.That(suppressor.SupportedSuppressions.Select(x => x.SuppressedDiagnosticId), Does.Contain(id)); settings ??= Settings.Default; - settings = settings.WithCompilationOptions(Settings.Default.CompilationOptions.WithWarningOrError(analyzer.SupportedDiagnostics)); + settings = settings.WithCompilationOptions(Settings.Default.CompilationOptions.WithWarningOrError(analyzer.SupportedDiagnostics)) + .WithAnalyzerConfig($"dotnet_diagnostic.{id}.severity = error"); Compilation compilation = CreateCompilation(code, settings); diff --git a/src/nunit.analyzers.tests/nunit.analyzers.tests.csproj b/src/nunit.analyzers.tests/nunit.analyzers.tests.csproj index 45b5b851..fff1f31e 100644 --- a/src/nunit.analyzers.tests/nunit.analyzers.tests.csproj +++ b/src/nunit.analyzers.tests/nunit.analyzers.tests.csproj @@ -12,7 +12,7 @@ - + @@ -31,6 +31,7 @@ + diff --git a/src/nunit.analyzers/DiagnosticSuppressors/AvoidUninstantiatedInternalClassSuppressor.cs b/src/nunit.analyzers/DiagnosticSuppressors/AvoidUninstantiatedInternalClassSuppressor.cs index d3ff6b2f..8908dcd6 100644 --- a/src/nunit.analyzers/DiagnosticSuppressors/AvoidUninstantiatedInternalClassSuppressor.cs +++ b/src/nunit.analyzers/DiagnosticSuppressors/AvoidUninstantiatedInternalClassSuppressor.cs @@ -1,5 +1,4 @@ using System.Collections.Immutable; -using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; diff --git a/src/nunit.analyzers/DiagnosticSuppressors/DereferencePossiblyNullReferenceSuppressor.cs b/src/nunit.analyzers/DiagnosticSuppressors/DereferencePossiblyNullReferenceSuppressor.cs index 91017998..98738e4b 100644 --- a/src/nunit.analyzers/DiagnosticSuppressors/DereferencePossiblyNullReferenceSuppressor.cs +++ b/src/nunit.analyzers/DiagnosticSuppressors/DereferencePossiblyNullReferenceSuppressor.cs @@ -188,7 +188,7 @@ arrayType.ElementType is ITypeParameterSymbol typeParameter && /// /// We only try to detect simple cases where the operands being tested for is one of the operands being returned: /// variable is not null ? variable : otherExpression - /// + /// /// We recognize the 'is' pattern operations and normal equality. /// /// Conditional expression to investigate. diff --git a/src/nunit.analyzers/DiagnosticSuppressors/TypesThatOwnDisposableFieldsShouldBeDisposableSuppressor.cs b/src/nunit.analyzers/DiagnosticSuppressors/TypesThatOwnDisposableFieldsShouldBeDisposableSuppressor.cs index c834b60a..ab9588a2 100644 --- a/src/nunit.analyzers/DiagnosticSuppressors/TypesThatOwnDisposableFieldsShouldBeDisposableSuppressor.cs +++ b/src/nunit.analyzers/DiagnosticSuppressors/TypesThatOwnDisposableFieldsShouldBeDisposableSuppressor.cs @@ -1,5 +1,4 @@ using System.Collections.Immutable; -using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; diff --git a/src/nunit.analyzers/Extensions/ITypeSymbolExtensions.cs b/src/nunit.analyzers/Extensions/ITypeSymbolExtensions.cs index 9ad2dc08..a168e1ee 100644 --- a/src/nunit.analyzers/Extensions/ITypeSymbolExtensions.cs +++ b/src/nunit.analyzers/Extensions/ITypeSymbolExtensions.cs @@ -185,6 +185,7 @@ internal static bool IsAwaitable(this ITypeSymbol @this, /// /// Return value indicates whether type implements IEnumerable interface. /// + /// The to check. /// Contains IEnumerable generic argument, or null, if type implements /// only non-generic IEnumerable interface, or no IEnumerable interface at all. internal static bool IsIEnumerable(this ITypeSymbol @this, out ITypeSymbol? elementType) @@ -219,6 +220,7 @@ internal static bool IsIEnumerable(this ITypeSymbol @this, out ITypeSymbol? elem /// /// Return value indicates whether type implements I(Async)Enumerable{T} interface. /// + /// The to check. /// Contains I(Async)Enumerable generic argument, or null, if type implements /// only non-generic IEnumerable interface, or no I(Async)Enumerable interface at all. internal static bool IsIEnumerableOrIAsyncEnumerable(this ITypeSymbol @this, out ITypeSymbol? elementType) diff --git a/src/nunit.analyzers/Helpers/NUnitEqualityComparerHelper.cs b/src/nunit.analyzers/Helpers/NUnitEqualityComparerHelper.cs index 1d239556..25815561 100644 --- a/src/nunit.analyzers/Helpers/NUnitEqualityComparerHelper.cs +++ b/src/nunit.analyzers/Helpers/NUnitEqualityComparerHelper.cs @@ -11,7 +11,7 @@ namespace NUnit.Analyzers.Helpers internal static class NUnitEqualityComparerHelper { /// - /// Returns true if it is possible that + /// Returns true if it is possible that "NUnit.Framework.Constraints.NUnitEqualityComparer.AreEqual" /// returns true for given argument types. /// False otherwise. /// diff --git a/src/nunit.analyzers/MissingProperty/MissingPropertyAnalyzer.cs b/src/nunit.analyzers/MissingProperty/MissingPropertyAnalyzer.cs index 7ae139d7..7f0ecb1a 100644 --- a/src/nunit.analyzers/MissingProperty/MissingPropertyAnalyzer.cs +++ b/src/nunit.analyzers/MissingProperty/MissingPropertyAnalyzer.cs @@ -71,7 +71,9 @@ protected override void AnalyzeAssertInvocation(OperationAnalysisContext context continue; } - var propertyMembers = actualType.GetAllMembers().Where(m => m.Kind == SymbolKind.Property); + var propertyMembers = actualType.GetAllMembers() + .Where(m => m.Kind == SymbolKind.Property) + .ToArray(); if (!propertyMembers.Any(m => m.Name == propertyName)) { var properties = propertyMembers.Select(p => p.Name).Distinct().ToImmutableDictionary(p => p, p => (string?)p); diff --git a/src/nunit.analyzers/nunit.analyzers.csproj b/src/nunit.analyzers/nunit.analyzers.csproj index 45f92b31..577f3cc4 100644 --- a/src/nunit.analyzers/nunit.analyzers.csproj +++ b/src/nunit.analyzers/nunit.analyzers.csproj @@ -2,16 +2,12 @@ NUnit.Analyzers netstandard2.0 - true - - - true - - + + diff --git a/src/nunit.analyzers/tools/install.ps1 b/src/nunit.analyzers/tools/install.ps1 deleted file mode 100644 index 8178834f..00000000 --- a/src/nunit.analyzers/tools/install.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -param($installPath, $toolsPath, $package, $project) - -$analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve - -foreach($analyzersPath in $analyzersPaths) -{ - # Install the language agnostic analyzers. - if (Test-Path $analyzersPath) - { - foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll) - { - if($project.Object.AnalyzerReferences) - { - $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) - } - } - } -} - -# $project.Type gives the language name like (C# or VB.NET) -$languageFolder = "" -if($project.Type -eq "C#") -{ - $languageFolder = "cs" -} -if($project.Type -eq "VB.NET") -{ - $languageFolder = "vb" -} -if($languageFolder -eq "") -{ - return -} - -foreach($analyzersPath in $analyzersPaths) -{ - # Install language specific analyzers. - $languageAnalyzersPath = join-path $analyzersPath $languageFolder - if (Test-Path $languageAnalyzersPath) - { - foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll) - { - if($project.Object.AnalyzerReferences) - { - $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) - } - } - } -} \ No newline at end of file diff --git a/src/nunit.analyzers/tools/uninstall.ps1 b/src/nunit.analyzers/tools/uninstall.ps1 deleted file mode 100644 index 9130bcb5..00000000 --- a/src/nunit.analyzers/tools/uninstall.ps1 +++ /dev/null @@ -1,56 +0,0 @@ -param($installPath, $toolsPath, $package, $project) - -$analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve - -foreach($analyzersPath in $analyzersPaths) -{ - # Uninstall the language agnostic analyzers. - if (Test-Path $analyzersPath) - { - foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll) - { - if($project.Object.AnalyzerReferences) - { - $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) - } - } - } -} - -# $project.Type gives the language name like (C# or VB.NET) -$languageFolder = "" -if($project.Type -eq "C#") -{ - $languageFolder = "cs" -} -if($project.Type -eq "VB.NET") -{ - $languageFolder = "vb" -} -if($languageFolder -eq "") -{ - return -} - -foreach($analyzersPath in $analyzersPaths) -{ - # Uninstall language specific analyzers. - $languageAnalyzersPath = join-path $analyzersPath $languageFolder - if (Test-Path $languageAnalyzersPath) - { - foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll) - { - if($project.Object.AnalyzerReferences) - { - try - { - $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) - } - catch - { - - } - } - } - } -} \ No newline at end of file