From d3477ed2f057a55890cd8c5b8d192e98c61b1db6 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 29 Oct 2025 13:54:55 +0000
Subject: [PATCH 01/11] Initial plan
From 993c1834e6061de81f06a40bd02a6a39e684375a Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 29 Oct 2025 14:09:20 +0000
Subject: [PATCH 02/11] Add MSTEST0058 analyzer to detect both Parallelize and
DoNotParallelize attributes
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
---
.../AnalyzerReleases.Unshipped.md | 6 ++++
.../MSTest.Analyzers/Helpers/DiagnosticIds.cs | 1 +
src/Analyzers/MSTest.Analyzers/Resources.resx | 9 ++++++
.../UseParallelizeAttributeAnalyzer.cs | 24 ++++++++++++++--
.../MSTest.Analyzers/xlf/Resources.cs.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.de.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.es.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.fr.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.it.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.ja.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.ko.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.pl.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.pt-BR.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.ru.xlf | 15 ++++++++++
.../MSTest.Analyzers/xlf/Resources.tr.xlf | 15 ++++++++++
.../xlf/Resources.zh-Hans.xlf | 15 ++++++++++
.../xlf/Resources.zh-Hant.xlf | 15 ++++++++++
.../UseParallelizeAttributeAnalyzerTests.cs | 28 +++++++++++++++++++
18 files changed, 261 insertions(+), 2 deletions(-)
diff --git a/src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md b/src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md
index f2b7fad657..5ef7f5dc72 100644
--- a/src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md
+++ b/src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md
@@ -1,2 +1,8 @@
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
+
+### New Rules
+
+Rule ID | Category | Severity | Notes
+--------|----------|----------|-------
+MSTEST0058 | Usage | Warning | DoNotUseParallelizeAndDoNotParallelizeTogetherAnalyzer
diff --git a/src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs b/src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs
index d7f58d9e67..712872903e 100644
--- a/src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs
+++ b/src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs
@@ -62,4 +62,5 @@ internal static class DiagnosticIds
public const string IgnoreStringMethodReturnValueRuleId = "MSTEST0055";
public const string TestMethodAttributeShouldSetDisplayNameCorrectlyRuleId = "MSTEST0056";
public const string TestMethodAttributeShouldPropagateSourceInformationRuleId = "MSTEST0057";
+ public const string DoNotUseParallelizeAndDoNotParallelizeTogetherRuleId = "MSTEST0058";
}
diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx
index 0c8a17d969..7bfe77c51e 100644
--- a/src/Analyzers/MSTest.Analyzers/Resources.resx
+++ b/src/Analyzers/MSTest.Analyzers/Resources.resx
@@ -684,4 +684,13 @@ The type declaring these methods should also respect the following rules:
Methods like Contains, StartsWith, and EndsWith return boolean values that indicate whether the condition was met. Ignoring these return values is likely a mistake.
+
+ Do not use both Parallelize and DoNotParallelize attributes
+
+
+ Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity
+
+
+ An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration that can lead to unexpected test execution behavior.
+
\ No newline at end of file
diff --git a/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs
index c55f840285..a95978acd1 100644
--- a/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs
+++ b/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs
@@ -14,6 +14,7 @@ namespace MSTest.Analyzers;
///
/// MSTEST0001: .
+/// MSTEST0058: .
///
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class UseParallelizeAttributeAnalyzer : DiagnosticAnalyzer
@@ -22,6 +23,10 @@ public sealed class UseParallelizeAttributeAnalyzer : DiagnosticAnalyzer
private static readonly LocalizableResourceString MessageFormat = new(nameof(Resources.UseParallelizeAttributeAnalyzerMessageFormat), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableResourceString Description = new(nameof(Resources.UseParallelizeAttributeAnalyzerDescription), Resources.ResourceManager, typeof(Resources));
+ private static readonly LocalizableResourceString BothAttributesTitle = new(nameof(Resources.DoNotUseParallelizeAndDoNotParallelizeTogetherTitle), Resources.ResourceManager, typeof(Resources));
+ private static readonly LocalizableResourceString BothAttributesMessageFormat = new(nameof(Resources.DoNotUseParallelizeAndDoNotParallelizeTogetherMessageFormat), Resources.ResourceManager, typeof(Resources));
+ private static readonly LocalizableResourceString BothAttributesDescription = new(nameof(Resources.DoNotUseParallelizeAndDoNotParallelizeTogetherDescription), Resources.ResourceManager, typeof(Resources));
+
///
public static readonly DiagnosticDescriptor Rule = DiagnosticDescriptorHelper.Create(
DiagnosticIds.UseParallelizedAttributeRuleId,
@@ -32,9 +37,19 @@ public sealed class UseParallelizeAttributeAnalyzer : DiagnosticAnalyzer
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
+ ///
+ public static readonly DiagnosticDescriptor DoNotUseBothAttributesRule = DiagnosticDescriptorHelper.Create(
+ DiagnosticIds.DoNotUseParallelizeAndDoNotParallelizeTogetherRuleId,
+ BothAttributesTitle,
+ BothAttributesMessageFormat,
+ BothAttributesDescription,
+ Category.Usage,
+ DiagnosticSeverity.Warning,
+ isEnabledByDefault: true);
+
///
public override ImmutableArray SupportedDiagnostics { get; }
- = ImmutableArray.Create(Rule);
+ = ImmutableArray.Create(Rule, DoNotUseBothAttributesRule);
///
public override void Initialize(AnalysisContext context)
@@ -75,7 +90,12 @@ private static void AnalyzeCompilation(CompilationAnalysisContext context)
}
}
- if (!hasParallelizeAttribute && !hasDoNotParallelizeAttribute)
+ if (hasParallelizeAttribute && hasDoNotParallelizeAttribute)
+ {
+ // Both attributes are present - this is an error
+ context.ReportNoLocationDiagnostic(DoNotUseBothAttributesRule);
+ }
+ else if (!hasParallelizeAttribute && !hasDoNotParallelizeAttribute)
{
// We cannot provide any good location for assembly level missing attributes
context.ReportNoLocationDiagnostic(Rule);
diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
index ba62836f66..343b0cacf4 100644
--- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
+++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf
@@ -989,6 +989,21 @@ Typ deklarující tyto metody by měl také respektovat následující pravidla:
Parametr Assert.Throws by měl obsahovat jenom jeden příkaz nebo výraz
+
+ An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration that can lead to unexpected test execution behavior.
+ An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration that can lead to unexpected test execution behavior.
+
+
+
+ Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity
+ Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity
+
+
+
+ Do not use both Parallelize and DoNotParallelize attributes
+ Do not use both Parallelize and DoNotParallelize attributes
+
+