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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf index 76737e3938..59fdf378b9 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf @@ -990,6 +990,21 @@ Der Typ, der diese Methoden deklariert, sollte auch die folgenden Regeln beachte Assert.Throws darf nur eine einzelne Anweisung/einen einzelnen Ausdruck enthalten + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf index 3e7bb27bc0..70d28d56f8 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf @@ -989,6 +989,21 @@ El tipo que declara estos métodos también debe respetar las reglas siguientes: Assert.Throws debe contener solo una única instrucción o expresión + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf index 8b30fdd14e..180f8ad534 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf @@ -989,6 +989,21 @@ Le type doit être une classe Assert.Throws ne doit contenir qu’une seule instruction + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf index 06dd23cd42..c0365fbc5f 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf @@ -989,6 +989,21 @@ Anche il tipo che dichiara questi metodi deve rispettare le regole seguenti: Assert.Throws deve contenere solo una singola istruzione/espressione + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf index ab704cbb51..162029eac7 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf @@ -989,6 +989,21 @@ The type declaring these methods should also respect the following rules: Assert.Throws には 1 つのステートメントまたは式のみを含める必要があります + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf index e1579bc142..573a18ef87 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf @@ -989,6 +989,21 @@ The type declaring these methods should also respect the following rules: Assert.Throws는 단일 문/식만 포함해야 합니다. + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf index 8b72c8d6e2..30319b967e 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf @@ -989,6 +989,21 @@ Typ deklarujący te metody powinien również przestrzegać następujących regu Element Assert.Throws powinien zawierać tylko jedną instrukcję/wyrażenie + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf index 3e9f3a2913..712d3fc06a 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf @@ -989,6 +989,21 @@ O tipo que declara esses métodos também deve respeitar as seguintes regras: Assert.Throws deve conter apenas uma única declaração/expressão + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf index 2a32db08a3..cfc9dced86 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf @@ -1001,6 +1001,21 @@ The type declaring these methods should also respect the following rules: Assert.Throws должен содержать только одну инструкцию/выражение + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf index 4c959ae0e5..9032d28249 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf @@ -991,6 +991,21 @@ Bu yöntemleri bildiren tipin ayrıca aşağıdaki kurallara uyması gerekir: Assert.Throws yalnızca tek bir deyim/ifade içermelidir. + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf index 2058347afa..7f3ec62120 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf @@ -989,6 +989,21 @@ The type declaring these methods should also respect the following rules: Assert.Throws 应仅包含单个语句/表达式 + + 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 + + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf index 228d78acdd..bb61755702 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf @@ -989,6 +989,21 @@ The type declaring these methods should also respect the following rules: Assert.Throws 應該只包含單一陳述式/運算式 + + 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 + + \ No newline at end of file diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs index 9423776f70..497c198a36 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs @@ -67,4 +67,32 @@ public async Task WhenDoNotParallelizeAttributeSet_NoDiagnostic() await VerifyAsync(code, includeTestAdapter: true); await VerifyAsync(code, includeTestAdapter: false); } + + [TestMethod] + public async Task WhenBothAttributesSet_Diagnostic() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] + [assembly: DoNotParallelize] + """; + + await VerifyAsync(code, includeTestAdapter: true, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithNoLocation()); + await VerifyAsync(code, includeTestAdapter: false, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithNoLocation()); + } + + [TestMethod] + public async Task WhenBothAttributesSetInDifferentOrder_Diagnostic() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [assembly: DoNotParallelize] + [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] + """; + + await VerifyAsync(code, includeTestAdapter: true, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithNoLocation()); + await VerifyAsync(code, includeTestAdapter: false, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithNoLocation()); + } } From c458eb38e6b7d4127ddf738b4464ed594887fe31 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 15:07:55 +0000 Subject: [PATCH 03/11] Fix MSTEST0058 to report diagnostic regardless of test adapter reference Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../UseParallelizeAttributeAnalyzer.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs index a95978acd1..824d11718c 100644 --- a/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs +++ b/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs @@ -62,16 +62,6 @@ public override void Initialize(AnalysisContext context) private static void AnalyzeCompilation(CompilationAnalysisContext context) { - bool hasTestAdapter = context.Options.AnalyzerConfigOptionsProvider.GlobalOptions.TryGetValue("build_property.IsMSTestTestAdapterReferenced", out string? isAdapterReferenced) && - bool.TryParse(isAdapterReferenced, out bool isAdapterReferencedValue) && - isAdapterReferencedValue; - - if (!hasTestAdapter) - { - // We shouldn't produce a diagnostic if only the test framework is referenced, but not the adapter. - return; - } - INamedTypeSymbol? parallelizeAttributeSymbol = context.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftVisualStudioTestToolsUnitTestingParallelizeAttribute); INamedTypeSymbol? doNotParallelizeAttributeSymbol = context.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftVisualStudioTestToolsUnitTestingDoNotParallelizeAttribute); @@ -94,8 +84,20 @@ private static void AnalyzeCompilation(CompilationAnalysisContext context) { // Both attributes are present - this is an error context.ReportNoLocationDiagnostic(DoNotUseBothAttributesRule); + return; } - else if (!hasParallelizeAttribute && !hasDoNotParallelizeAttribute) + + bool hasTestAdapter = context.Options.AnalyzerConfigOptionsProvider.GlobalOptions.TryGetValue("build_property.IsMSTestTestAdapterReferenced", out string? isAdapterReferenced) && + bool.TryParse(isAdapterReferenced, out bool isAdapterReferencedValue) && + isAdapterReferencedValue; + + if (!hasTestAdapter) + { + // We shouldn't produce a diagnostic if only the test framework is referenced, but not the adapter. + return; + } + + if (!hasParallelizeAttribute && !hasDoNotParallelizeAttribute) { // We cannot provide any good location for assembly level missing attributes context.ReportNoLocationDiagnostic(Rule); From 0e4143c3d1a0f82e1b0c633c235f81531eae0d29 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 00:01:13 +0000 Subject: [PATCH 04/11] Add Locked markers and report diagnostics with locations Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- src/Analyzers/MSTest.Analyzers/Resources.resx | 3 ++ .../UseParallelizeAttributeAnalyzer.cs | 24 ++++++++++---- .../UseParallelizeAttributeAnalyzerTests.cs | 32 ++++++++++++++----- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx index 7bfe77c51e..8d89c511d9 100644 --- a/src/Analyzers/MSTest.Analyzers/Resources.resx +++ b/src/Analyzers/MSTest.Analyzers/Resources.resx @@ -686,11 +686,14 @@ The type declaring these methods should also respect the following rules: Do not use both Parallelize and DoNotParallelize attributes + {Locked="Parallelize","DoNotParallelize"} Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} 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. + {Locked="[Parallelize]","[DoNotParallelize]"} \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs index 824d11718c..416489c1b6 100644 --- a/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs +++ b/src/Analyzers/MSTest.Analyzers/UseParallelizeAttributeAnalyzer.cs @@ -65,25 +65,35 @@ private static void AnalyzeCompilation(CompilationAnalysisContext context) INamedTypeSymbol? parallelizeAttributeSymbol = context.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftVisualStudioTestToolsUnitTestingParallelizeAttribute); INamedTypeSymbol? doNotParallelizeAttributeSymbol = context.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftVisualStudioTestToolsUnitTestingDoNotParallelizeAttribute); - bool hasParallelizeAttribute = false; - bool hasDoNotParallelizeAttribute = false; + AttributeData? parallelizeAttribute = null; + AttributeData? doNotParallelizeAttribute = null; foreach (AttributeData attribute in context.Compilation.Assembly.GetAttributes()) { if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, parallelizeAttributeSymbol)) { - hasParallelizeAttribute = true; + parallelizeAttribute = attribute; } if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, doNotParallelizeAttributeSymbol)) { - hasDoNotParallelizeAttribute = true; + doNotParallelizeAttribute = attribute; } } - if (hasParallelizeAttribute && hasDoNotParallelizeAttribute) + if (parallelizeAttribute is not null && doNotParallelizeAttribute is not null) { // Both attributes are present - this is an error - context.ReportNoLocationDiagnostic(DoNotUseBothAttributesRule); + // Report on both attribute locations + if (parallelizeAttribute.ApplicationSyntaxReference is not null) + { + context.ReportDiagnostic(parallelizeAttribute.ApplicationSyntaxReference.CreateDiagnostic(DoNotUseBothAttributesRule, context.CancellationToken)); + } + + if (doNotParallelizeAttribute.ApplicationSyntaxReference is not null) + { + context.ReportDiagnostic(doNotParallelizeAttribute.ApplicationSyntaxReference.CreateDiagnostic(DoNotUseBothAttributesRule, context.CancellationToken)); + } + return; } @@ -97,7 +107,7 @@ private static void AnalyzeCompilation(CompilationAnalysisContext context) return; } - if (!hasParallelizeAttribute && !hasDoNotParallelizeAttribute) + if (parallelizeAttribute is null && doNotParallelizeAttribute is null) { // We cannot provide any good location for assembly level missing attributes context.ReportNoLocationDiagnostic(Rule); diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs index 497c198a36..1aa1b8dd58 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs @@ -74,12 +74,20 @@ public async Task WhenBothAttributesSet_Diagnostic() string code = """ using Microsoft.VisualStudio.TestTools.UnitTesting; - [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] - [assembly: DoNotParallelize] + {|#0:[assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)]|} + {|#1:[assembly: DoNotParallelize]|} """; - await VerifyAsync(code, includeTestAdapter: true, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithNoLocation()); - await VerifyAsync(code, includeTestAdapter: false, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithNoLocation()); + await VerifyAsync( + code, + includeTestAdapter: true, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0), + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1)); + await VerifyAsync( + code, + includeTestAdapter: false, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0), + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1)); } [TestMethod] @@ -88,11 +96,19 @@ public async Task WhenBothAttributesSetInDifferentOrder_Diagnostic() string code = """ using Microsoft.VisualStudio.TestTools.UnitTesting; - [assembly: DoNotParallelize] - [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] + {|#0:[assembly: DoNotParallelize]|} + {|#1:[assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)]|} """; - await VerifyAsync(code, includeTestAdapter: true, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithNoLocation()); - await VerifyAsync(code, includeTestAdapter: false, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithNoLocation()); + await VerifyAsync( + code, + includeTestAdapter: true, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1), + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0)); + await VerifyAsync( + code, + includeTestAdapter: false, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1), + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0)); } } From 4757a3cb96449ca2f8519403630da81a30c9b612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 30 Oct 2025 09:34:05 +0100 Subject: [PATCH 05/11] Apply suggestion from @Evangelink --- src/Analyzers/MSTest.Analyzers/Resources.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx index 8d89c511d9..5850836079 100644 --- a/src/Analyzers/MSTest.Analyzers/Resources.resx +++ b/src/Analyzers/MSTest.Analyzers/Resources.resx @@ -689,7 +689,7 @@ The type declaring these methods should also respect the following rules: {Locked="Parallelize","DoNotParallelize"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity {Locked="[Parallelize]","[DoNotParallelize]"} From cbd895820e704da94c8725c1df90e7583646768f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 30 Oct 2025 09:34:36 +0100 Subject: [PATCH 06/11] Apply suggestion from @Evangelink --- src/Analyzers/MSTest.Analyzers/Resources.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx index 5850836079..8075eb94b3 100644 --- a/src/Analyzers/MSTest.Analyzers/Resources.resx +++ b/src/Analyzers/MSTest.Analyzers/Resources.resx @@ -685,7 +685,7 @@ 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 + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes {Locked="Parallelize","DoNotParallelize"} From 223122ac9c02e977a6f387e73814f6bf9b6957ab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 08:45:30 +0000 Subject: [PATCH 07/11] Add code fixes to remove conflicting parallelization attributes and update description Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../CodeFixResources.resx | 8 ++ ...onflictingParallelizationAttributeFixer.cs | 109 ++++++++++++++++++ .../xlf/CodeFixResources.cs.xlf | 10 ++ .../xlf/CodeFixResources.de.xlf | 10 ++ .../xlf/CodeFixResources.es.xlf | 10 ++ .../xlf/CodeFixResources.fr.xlf | 10 ++ .../xlf/CodeFixResources.it.xlf | 10 ++ .../xlf/CodeFixResources.ja.xlf | 10 ++ .../xlf/CodeFixResources.ko.xlf | 10 ++ .../xlf/CodeFixResources.pl.xlf | 10 ++ .../xlf/CodeFixResources.pt-BR.xlf | 10 ++ .../xlf/CodeFixResources.ru.xlf | 10 ++ .../xlf/CodeFixResources.tr.xlf | 10 ++ .../xlf/CodeFixResources.zh-Hans.xlf | 10 ++ .../xlf/CodeFixResources.zh-Hant.xlf | 10 ++ src/Analyzers/MSTest.Analyzers/Resources.resx | 2 +- .../UseParallelizeAttributeAnalyzerTests.cs | 48 +++++++- 17 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 src/Analyzers/MSTest.Analyzers.CodeFixes/RemoveConflictingParallelizationAttributeFixer.cs diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx b/src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx index 569baca6de..fd4c9ac9ad 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx @@ -207,4 +207,12 @@ Use 'TestContext.CancellationToken' instead + + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/RemoveConflictingParallelizationAttributeFixer.cs b/src/Analyzers/MSTest.Analyzers.CodeFixes/RemoveConflictingParallelizationAttributeFixer.cs new file mode 100644 index 0000000000..d7a42440e4 --- /dev/null +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/RemoveConflictingParallelizationAttributeFixer.cs @@ -0,0 +1,109 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Immutable; +using System.Composition; + +using Analyzer.Utilities; + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeActions; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +using MSTest.Analyzers.Helpers; + +namespace MSTest.Analyzers; + +/// +/// Code fixer for MSTEST0058 to remove one of the conflicting parallelization attributes. +/// +[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(RemoveConflictingParallelizationAttributeFixer))] +[Shared] +public sealed class RemoveConflictingParallelizationAttributeFixer : CodeFixProvider +{ + /// + public override ImmutableArray FixableDiagnosticIds { get; } + = ImmutableArray.Create(DiagnosticIds.DoNotUseParallelizeAndDoNotParallelizeTogetherRuleId); + + /// + public override FixAllProvider GetFixAllProvider() + // See https://github.com/dotnet/roslyn/blob/main/docs/analyzers/FixAllProvider.md for more information on Fix All Providers + => WellKnownFixAllProviders.BatchFixer; + + /// + public override async Task RegisterCodeFixesAsync(CodeFixContext context) + { + SyntaxNode root = await context.Document.GetRequiredSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); + + foreach (Diagnostic diagnostic in context.Diagnostics) + { + // Find the attribute syntax node at the diagnostic location + SyntaxNode node = root.FindNode(diagnostic.Location.SourceSpan); + + if (node is not AttributeSyntax attributeSyntax) + { + continue; + } + + // Determine which attribute this is + string? attributeName = attributeSyntax.Name.ToString(); + if (attributeName is null) + { + continue; + } + + // Normalize the attribute name (handle both short and full names) + bool isParallelizeAttribute = attributeName.Contains("Parallelize") && !attributeName.Contains("DoNotParallelize"); + bool isDoNotParallelizeAttribute = attributeName.Contains("DoNotParallelize"); + + if (isParallelizeAttribute) + { + // This is [Parallelize] - offer to remove it + context.RegisterCodeFix( + CodeAction.Create( + title: CodeFixResources.RemoveParallelizeAttributeFix, + createChangedDocument: c => RemoveAttributeAsync(context.Document, attributeSyntax, c), + equivalenceKey: nameof(RemoveConflictingParallelizationAttributeFixer) + "_RemoveParallelize"), + diagnostic); + } + else if (isDoNotParallelizeAttribute) + { + // This is [DoNotParallelize] - offer to remove it + context.RegisterCodeFix( + CodeAction.Create( + title: CodeFixResources.RemoveDoNotParallelizeAttributeFix, + createChangedDocument: c => RemoveAttributeAsync(context.Document, attributeSyntax, c), + equivalenceKey: nameof(RemoveConflictingParallelizationAttributeFixer) + "_RemoveDoNotParallelize"), + diagnostic); + } + } + } + + private static async Task RemoveAttributeAsync(Document document, AttributeSyntax attributeSyntax, CancellationToken cancellationToken) + { + SyntaxNode root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); + + // Find the AttributeListSyntax that contains this attribute + if (attributeSyntax.Parent is not AttributeListSyntax attributeList) + { + return document; + } + + SyntaxNode nodeToRemove; + + // If this is the only attribute in the list, remove the entire attribute list + if (attributeList.Attributes.Count == 1) + { + nodeToRemove = attributeList; + } + else + { + // Otherwise, just remove this specific attribute + nodeToRemove = attributeSyntax; + } + + SyntaxNode newRoot = root.RemoveNode(nodeToRemove, SyntaxRemoveOptions.KeepNoTrivia)!; + return document.WithSyntaxRoot(newRoot); + } +} diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.cs.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.cs.xlf index 8f9a0a8393..492257858a 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.cs.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.cs.xlf @@ -152,6 +152,16 @@ Použít {0} + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.de.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.de.xlf index 374b6d3bde..ea883cb182 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.de.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.de.xlf @@ -152,6 +152,16 @@ "{0}" verwenden + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.es.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.es.xlf index 66742db404..7763b57161 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.es.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.es.xlf @@ -152,6 +152,16 @@ Usar "{0}" + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.fr.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.fr.xlf index ec66aaf4da..b4b5beb6a8 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.fr.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.fr.xlf @@ -152,6 +152,16 @@ Utiliser « {0} » + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.it.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.it.xlf index fad6511ba2..b6d7111c7f 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.it.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.it.xlf @@ -152,6 +152,16 @@ Usa '{0}' + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ja.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ja.xlf index 422dd62c24..41e822100c 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ja.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ja.xlf @@ -152,6 +152,16 @@ '{0}' を使用します + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ko.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ko.xlf index 2bd87cf1af..f862a6f499 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ko.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ko.xlf @@ -152,6 +152,16 @@ '{0}' 사용 + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pl.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pl.xlf index 3ce2f0eda3..bcfa2107ff 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pl.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pl.xlf @@ -152,6 +152,16 @@ Użyj „{0}” + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pt-BR.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pt-BR.xlf index 3e7f19fb87..5ac44dc455 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pt-BR.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pt-BR.xlf @@ -152,6 +152,16 @@ Usar '{0}' + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ru.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ru.xlf index e442c31ee5..c120e066ef 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ru.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ru.xlf @@ -152,6 +152,16 @@ Использовать "{0}" + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.tr.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.tr.xlf index 28c764a1ea..7240a89282 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.tr.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.tr.xlf @@ -152,6 +152,16 @@ '{0}' kullan + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hans.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hans.xlf index 6563ec971c..c11dff60f2 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hans.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hans.xlf @@ -152,6 +152,16 @@ 使用“{0}” + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hant.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hant.xlf index bca5bd3526..d55dd180f6 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hant.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hant.xlf @@ -152,6 +152,16 @@ 使用 '{0}' + + Remove '[Parallelize]' attribute + Remove '[Parallelize]' attribute + {Locked="[Parallelize]"} + + + Remove '[DoNotParallelize]' attribute + Remove '[DoNotParallelize]' attribute + {Locked="[DoNotParallelize]"} + \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers/Resources.resx b/src/Analyzers/MSTest.Analyzers/Resources.resx index 8075eb94b3..01f07ad530 100644 --- a/src/Analyzers/MSTest.Analyzers/Resources.resx +++ b/src/Analyzers/MSTest.Analyzers/Resources.resx @@ -693,7 +693,7 @@ The type declaring these methods should also respect the following rules: {Locked="[Parallelize]","[DoNotParallelize]"} - 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. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. {Locked="[Parallelize]","[DoNotParallelize]"} \ No newline at end of file diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs index 1aa1b8dd58..3483ca5fb2 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs @@ -5,7 +5,7 @@ using VerifyCS = MSTest.Analyzers.Test.CSharpCodeFixVerifier< MSTest.Analyzers.UseParallelizeAttributeAnalyzer, - Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>; + MSTest.Analyzers.RemoveConflictingParallelizationAttributeFixer>; namespace MSTest.Analyzers.Test; @@ -111,4 +111,50 @@ await VerifyAsync( VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1), VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0)); } + + [TestMethod] + public async Task WhenBothAttributesSet_CodeFixRemovesParallelize() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] + [assembly: DoNotParallelize] + """; + + string fixedCode = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [assembly: DoNotParallelize] + """; + + await VerifyCS.VerifyCodeFixAsync( + code, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0).WithArguments(), + fixedCode, + 0); + } + + [TestMethod] + public async Task WhenBothAttributesSet_CodeFixRemovesDoNotParallelize() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] + [assembly: DoNotParallelize] + """; + + string fixedCode = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] + """; + + await VerifyCS.VerifyCodeFixAsync( + code, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1).WithArguments(), + fixedCode, + 1); + } } From 62102dd3323adf2e2e661397fe01617d5d629a91 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:15:52 +0000 Subject: [PATCH 08/11] Add test for multiple attributes in same attribute list Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../UseParallelizeAttributeAnalyzerTests.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs index 3483ca5fb2..639ef4649e 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs @@ -157,4 +157,55 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode, 1); } + + [TestMethod] + public async Task WhenBothAttributesSetWithMultipleAttributesInList_CodeFixRemovesOnlyTargetAttribute() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + using System; + + [AttributeUsage(AttributeTargets.Assembly)] + public class MyAsmAttribute : Attribute { } + + [assembly: {|#0:Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)|}, MyAsm] + [assembly: {|#1:DoNotParallelize|}, MyAsm] + """; + + string fixedCodeRemovingParallelize = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + using System; + + [AttributeUsage(AttributeTargets.Assembly)] + public class MyAsmAttribute : Attribute { } + + [assembly: MyAsm] + [assembly: DoNotParallelize, MyAsm] + """; + + string fixedCodeRemovingDoNotParallelize = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + using System; + + [AttributeUsage(AttributeTargets.Assembly)] + public class MyAsmAttribute : Attribute { } + + [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel), MyAsm] + [assembly: MyAsm] + """; + + // Test removing Parallelize attribute + await VerifyCS.VerifyCodeFixAsync( + code, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0).WithArguments(), + fixedCodeRemovingParallelize, + 0); + + // Test removing DoNotParallelize attribute + await VerifyCS.VerifyCodeFixAsync( + code, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1).WithArguments(), + fixedCodeRemovingDoNotParallelize, + 1); + } } From 7680a705ea0bdbb097d66c273725b509d76f4179 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 08:37:41 +0000 Subject: [PATCH 09/11] Remove code fixer and adjust tests Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../CodeFixResources.resx | 8 -- ...onflictingParallelizationAttributeFixer.cs | 109 ------------------ .../xlf/CodeFixResources.cs.xlf | 10 -- .../xlf/CodeFixResources.de.xlf | 10 -- .../xlf/CodeFixResources.es.xlf | 10 -- .../xlf/CodeFixResources.fr.xlf | 10 -- .../xlf/CodeFixResources.it.xlf | 10 -- .../xlf/CodeFixResources.ja.xlf | 10 -- .../xlf/CodeFixResources.ko.xlf | 10 -- .../xlf/CodeFixResources.pl.xlf | 10 -- .../xlf/CodeFixResources.pt-BR.xlf | 10 -- .../xlf/CodeFixResources.ru.xlf | 10 -- .../xlf/CodeFixResources.tr.xlf | 10 -- .../xlf/CodeFixResources.zh-Hans.xlf | 10 -- .../xlf/CodeFixResources.zh-Hant.xlf | 10 -- .../UseParallelizeAttributeAnalyzerTests.cs | 91 ++------------- 16 files changed, 10 insertions(+), 328 deletions(-) delete mode 100644 src/Analyzers/MSTest.Analyzers.CodeFixes/RemoveConflictingParallelizationAttributeFixer.cs diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx b/src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx index fd4c9ac9ad..569baca6de 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx @@ -207,12 +207,4 @@ Use 'TestContext.CancellationToken' instead - - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/RemoveConflictingParallelizationAttributeFixer.cs b/src/Analyzers/MSTest.Analyzers.CodeFixes/RemoveConflictingParallelizationAttributeFixer.cs deleted file mode 100644 index d7a42440e4..0000000000 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/RemoveConflictingParallelizationAttributeFixer.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Immutable; -using System.Composition; - -using Analyzer.Utilities; - -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeActions; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -using MSTest.Analyzers.Helpers; - -namespace MSTest.Analyzers; - -/// -/// Code fixer for MSTEST0058 to remove one of the conflicting parallelization attributes. -/// -[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(RemoveConflictingParallelizationAttributeFixer))] -[Shared] -public sealed class RemoveConflictingParallelizationAttributeFixer : CodeFixProvider -{ - /// - public override ImmutableArray FixableDiagnosticIds { get; } - = ImmutableArray.Create(DiagnosticIds.DoNotUseParallelizeAndDoNotParallelizeTogetherRuleId); - - /// - public override FixAllProvider GetFixAllProvider() - // See https://github.com/dotnet/roslyn/blob/main/docs/analyzers/FixAllProvider.md for more information on Fix All Providers - => WellKnownFixAllProviders.BatchFixer; - - /// - public override async Task RegisterCodeFixesAsync(CodeFixContext context) - { - SyntaxNode root = await context.Document.GetRequiredSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); - - foreach (Diagnostic diagnostic in context.Diagnostics) - { - // Find the attribute syntax node at the diagnostic location - SyntaxNode node = root.FindNode(diagnostic.Location.SourceSpan); - - if (node is not AttributeSyntax attributeSyntax) - { - continue; - } - - // Determine which attribute this is - string? attributeName = attributeSyntax.Name.ToString(); - if (attributeName is null) - { - continue; - } - - // Normalize the attribute name (handle both short and full names) - bool isParallelizeAttribute = attributeName.Contains("Parallelize") && !attributeName.Contains("DoNotParallelize"); - bool isDoNotParallelizeAttribute = attributeName.Contains("DoNotParallelize"); - - if (isParallelizeAttribute) - { - // This is [Parallelize] - offer to remove it - context.RegisterCodeFix( - CodeAction.Create( - title: CodeFixResources.RemoveParallelizeAttributeFix, - createChangedDocument: c => RemoveAttributeAsync(context.Document, attributeSyntax, c), - equivalenceKey: nameof(RemoveConflictingParallelizationAttributeFixer) + "_RemoveParallelize"), - diagnostic); - } - else if (isDoNotParallelizeAttribute) - { - // This is [DoNotParallelize] - offer to remove it - context.RegisterCodeFix( - CodeAction.Create( - title: CodeFixResources.RemoveDoNotParallelizeAttributeFix, - createChangedDocument: c => RemoveAttributeAsync(context.Document, attributeSyntax, c), - equivalenceKey: nameof(RemoveConflictingParallelizationAttributeFixer) + "_RemoveDoNotParallelize"), - diagnostic); - } - } - } - - private static async Task RemoveAttributeAsync(Document document, AttributeSyntax attributeSyntax, CancellationToken cancellationToken) - { - SyntaxNode root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - - // Find the AttributeListSyntax that contains this attribute - if (attributeSyntax.Parent is not AttributeListSyntax attributeList) - { - return document; - } - - SyntaxNode nodeToRemove; - - // If this is the only attribute in the list, remove the entire attribute list - if (attributeList.Attributes.Count == 1) - { - nodeToRemove = attributeList; - } - else - { - // Otherwise, just remove this specific attribute - nodeToRemove = attributeSyntax; - } - - SyntaxNode newRoot = root.RemoveNode(nodeToRemove, SyntaxRemoveOptions.KeepNoTrivia)!; - return document.WithSyntaxRoot(newRoot); - } -} diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.cs.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.cs.xlf index 492257858a..8f9a0a8393 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.cs.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.cs.xlf @@ -152,16 +152,6 @@ Použít {0} - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.de.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.de.xlf index ea883cb182..374b6d3bde 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.de.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.de.xlf @@ -152,16 +152,6 @@ "{0}" verwenden - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.es.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.es.xlf index 7763b57161..66742db404 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.es.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.es.xlf @@ -152,16 +152,6 @@ Usar "{0}" - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.fr.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.fr.xlf index b4b5beb6a8..ec66aaf4da 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.fr.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.fr.xlf @@ -152,16 +152,6 @@ Utiliser « {0} » - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.it.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.it.xlf index b6d7111c7f..fad6511ba2 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.it.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.it.xlf @@ -152,16 +152,6 @@ Usa '{0}' - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ja.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ja.xlf index 41e822100c..422dd62c24 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ja.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ja.xlf @@ -152,16 +152,6 @@ '{0}' を使用します - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ko.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ko.xlf index f862a6f499..2bd87cf1af 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ko.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ko.xlf @@ -152,16 +152,6 @@ '{0}' 사용 - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pl.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pl.xlf index bcfa2107ff..3ce2f0eda3 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pl.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pl.xlf @@ -152,16 +152,6 @@ Użyj „{0}” - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pt-BR.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pt-BR.xlf index 5ac44dc455..3e7f19fb87 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pt-BR.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.pt-BR.xlf @@ -152,16 +152,6 @@ Usar '{0}' - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ru.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ru.xlf index c120e066ef..e442c31ee5 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ru.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.ru.xlf @@ -152,16 +152,6 @@ Использовать "{0}" - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.tr.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.tr.xlf index 7240a89282..28c764a1ea 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.tr.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.tr.xlf @@ -152,16 +152,6 @@ '{0}' kullan - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hans.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hans.xlf index c11dff60f2..6563ec971c 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hans.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hans.xlf @@ -152,16 +152,6 @@ 使用“{0}” - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hant.xlf b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hant.xlf index d55dd180f6..bca5bd3526 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hant.xlf +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/xlf/CodeFixResources.zh-Hant.xlf @@ -152,16 +152,6 @@ 使用 '{0}' - - Remove '[Parallelize]' attribute - Remove '[Parallelize]' attribute - {Locked="[Parallelize]"} - - - Remove '[DoNotParallelize]' attribute - Remove '[DoNotParallelize]' attribute - {Locked="[DoNotParallelize]"} - \ No newline at end of file diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs index 639ef4649e..0d716cb624 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs @@ -5,7 +5,7 @@ using VerifyCS = MSTest.Analyzers.Test.CSharpCodeFixVerifier< MSTest.Analyzers.UseParallelizeAttributeAnalyzer, - MSTest.Analyzers.RemoveConflictingParallelizationAttributeFixer>; + Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>; namespace MSTest.Analyzers.Test; @@ -113,53 +113,7 @@ await VerifyAsync( } [TestMethod] - public async Task WhenBothAttributesSet_CodeFixRemovesParallelize() - { - string code = """ - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] - [assembly: DoNotParallelize] - """; - - string fixedCode = """ - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [assembly: DoNotParallelize] - """; - - await VerifyCS.VerifyCodeFixAsync( - code, - VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0).WithArguments(), - fixedCode, - 0); - } - - [TestMethod] - public async Task WhenBothAttributesSet_CodeFixRemovesDoNotParallelize() - { - string code = """ - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] - [assembly: DoNotParallelize] - """; - - string fixedCode = """ - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)] - """; - - await VerifyCS.VerifyCodeFixAsync( - code, - VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1).WithArguments(), - fixedCode, - 1); - } - - [TestMethod] - public async Task WhenBothAttributesSetWithMultipleAttributesInList_CodeFixRemovesOnlyTargetAttribute() + public async Task WhenBothAttributesSetWithMultipleAttributesInList_Diagnostic() { string code = """ using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -172,40 +126,15 @@ public class MyAsmAttribute : Attribute { } [assembly: {|#1:DoNotParallelize|}, MyAsm] """; - string fixedCodeRemovingParallelize = """ - using Microsoft.VisualStudio.TestTools.UnitTesting; - using System; - - [AttributeUsage(AttributeTargets.Assembly)] - public class MyAsmAttribute : Attribute { } - - [assembly: MyAsm] - [assembly: DoNotParallelize, MyAsm] - """; - - string fixedCodeRemovingDoNotParallelize = """ - using Microsoft.VisualStudio.TestTools.UnitTesting; - using System; - - [AttributeUsage(AttributeTargets.Assembly)] - public class MyAsmAttribute : Attribute { } - - [assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel), MyAsm] - [assembly: MyAsm] - """; - - // Test removing Parallelize attribute - await VerifyCS.VerifyCodeFixAsync( + await VerifyAsync( code, - VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0).WithArguments(), - fixedCodeRemovingParallelize, - 0); - - // Test removing DoNotParallelize attribute - await VerifyCS.VerifyCodeFixAsync( + includeTestAdapter: true, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0), + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1)); + await VerifyAsync( code, - VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1).WithArguments(), - fixedCodeRemovingDoNotParallelize, - 1); + includeTestAdapter: false, + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(0), + VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.DoNotUseBothAttributesRule).WithLocation(1)); } } From 492443c8f1a6658acd040caec31a20840ababaf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 31 Oct 2025 15:32:20 +0100 Subject: [PATCH 10/11] Fix xlf --- .../MSTest.Analyzers/xlf/Resources.cs.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.de.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.es.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.fr.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.it.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.ja.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.ko.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.pl.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.pt-BR.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.ru.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.tr.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.zh-Hans.xlf | 18 +++++++++--------- .../MSTest.Analyzers/xlf/Resources.zh-Hant.xlf | 18 +++++++++--------- 13 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf index 343b0cacf4..4324f2289b 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.cs.xlf @@ -990,19 +990,19 @@ Typ deklarující tyto metody by měl také respektovat následující pravidla: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf index 59fdf378b9..23f7407c5f 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.de.xlf @@ -991,19 +991,19 @@ Der Typ, der diese Methoden deklariert, sollte auch die folgenden Regeln beachte - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf index 70d28d56f8..90b7fcd00b 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.es.xlf @@ -990,19 +990,19 @@ El tipo que declara estos métodos también debe respetar las reglas siguientes: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf index 180f8ad534..0e4fc46724 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf @@ -990,19 +990,19 @@ Le type doit être une classe - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf index c0365fbc5f..c835a6f441 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.it.xlf @@ -990,19 +990,19 @@ Anche il tipo che dichiara questi metodi deve rispettare le regole seguenti: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf index 162029eac7..f25b71f4df 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ja.xlf @@ -990,19 +990,19 @@ The type declaring these methods should also respect the following rules: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf index 573a18ef87..3bc6cbebe3 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ko.xlf @@ -990,19 +990,19 @@ The type declaring these methods should also respect the following rules: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf index 30319b967e..be3069c36e 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pl.xlf @@ -990,19 +990,19 @@ Typ deklarujący te metody powinien również przestrzegać następujących regu - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf index 712d3fc06a..c5057e1525 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.pt-BR.xlf @@ -990,19 +990,19 @@ O tipo que declara esses métodos também deve respeitar as seguintes regras: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf index cfc9dced86..3fd37b2408 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.ru.xlf @@ -1002,19 +1002,19 @@ The type declaring these methods should also respect the following rules: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf index 9032d28249..b21dfc7bde 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.tr.xlf @@ -992,19 +992,19 @@ Bu yöntemleri bildiren tipin ayrıca aşağıdaki kurallara uyması gerekir: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf index 7f3ec62120..f8d6b11f60 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hans.xlf @@ -990,19 +990,19 @@ The type declaring these methods should also respect the following rules: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} diff --git a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf index bb61755702..bc3f35063a 100644 --- a/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf +++ b/src/Analyzers/MSTest.Analyzers/xlf/Resources.zh-Hant.xlf @@ -990,19 +990,19 @@ The type declaring these methods should also respect the following rules: - 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. - + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + An assembly should have either [Parallelize] or [DoNotParallelize] attribute, but not both. Having both attributes creates an ambiguous configuration. When both are present, [DoNotParallelize] takes precedence and parallelization will be disabled. + {Locked="[Parallelize]","[DoNotParallelize]"} - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - Assembly has both [Parallelize] and [DoNotParallelize] attributes which creates ambiguity - + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + Assembly has both '[Parallelize]' and '[DoNotParallelize]' attributes which creates ambiguity + {Locked="[Parallelize]","[DoNotParallelize]"} - Do not use both Parallelize and DoNotParallelize attributes - Do not use both Parallelize and DoNotParallelize attributes - + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + Do not use both '[Parallelize]' and '[DoNotParallelize]' attributes + {Locked="Parallelize","DoNotParallelize"} From 2d1f9c60d729475db371e8f1f99428080cf6bc74 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 15:23:56 +0000 Subject: [PATCH 11/11] Fix test location markers and assembly attribute ordering Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../UseParallelizeAttributeAnalyzerTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs index 0d716cb624..0df13088d3 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs @@ -74,8 +74,8 @@ public async Task WhenBothAttributesSet_Diagnostic() string code = """ using Microsoft.VisualStudio.TestTools.UnitTesting; - {|#0:[assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)]|} - {|#1:[assembly: DoNotParallelize]|} + [assembly: {|#0:Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)|}] + [assembly: {|#1:DoNotParallelize|}] """; await VerifyAsync( @@ -96,8 +96,8 @@ public async Task WhenBothAttributesSetInDifferentOrder_Diagnostic() string code = """ using Microsoft.VisualStudio.TestTools.UnitTesting; - {|#0:[assembly: DoNotParallelize]|} - {|#1:[assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)]|} + [assembly: {|#0:DoNotParallelize|}] + [assembly: {|#1:Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)|}] """; await VerifyAsync( @@ -119,11 +119,11 @@ public async Task WhenBothAttributesSetWithMultipleAttributesInList_Diagnostic() using Microsoft.VisualStudio.TestTools.UnitTesting; using System; - [AttributeUsage(AttributeTargets.Assembly)] - public class MyAsmAttribute : Attribute { } - [assembly: {|#0:Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)|}, MyAsm] [assembly: {|#1:DoNotParallelize|}, MyAsm] + + [AttributeUsage(AttributeTargets.Assembly)] + public class MyAsmAttribute : Attribute { } """; await VerifyAsync(