Skip to content

Commit 35c324e

Browse files
committed
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
1 parent 99ba578 commit 35c324e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/NamingMethodPascal.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context)
108108

109109
private static bool IsTestMethod(IMethodSymbol methodSymbol)
110110
{
111-
// Test framework namespaces - checking namespace is more flexible than specific attribute names
111+
// Test framework namespaces - any method decorated with an attribute from these namespaces
112+
// is considered a test method and exempt from PascalCase validation
112113
string[] testFrameworkNamespaces =
113114
[
114115
"Xunit", // xUnit (note: namespace is "Xunit", not "XUnit")
@@ -117,7 +118,8 @@ private static bool IsTestMethod(IMethodSymbol methodSymbol)
117118
"TUnit.Core" // TUnit
118119
];
119120

120-
// Fallback attribute names for test environments where namespace metadata may be incomplete
121+
// Fallback attribute names - needed because our test infrastructure (DiagnosticVerifier)
122+
// doesn't add references to test framework assemblies, so ContainingNamespace would be null
121123
string[] commonTestAttributeNames =
122124
[
123125
"TestMethod", "TestMethodAttribute", // MSTest
@@ -136,15 +138,15 @@ private static bool IsTestMethod(IMethodSymbol methodSymbol)
136138
return false;
137139
}
138140

139-
// Check namespace first (more robust for production code)
141+
// Check namespace first (works in production with proper assembly references)
140142
string containingNamespace = attribute.AttributeClass.ContainingNamespace?.ToDisplayString();
141143
if (containingNamespace != null &&
142144
testFrameworkNamespaces.Any(ns => containingNamespace.StartsWith(ns, StringComparison.Ordinal)))
143145
{
144146
return true;
145147
}
146148

147-
// Fallback: check attribute name for common test attributes
149+
// Fallback: check attribute name (needed for test environment)
148150
string attributeName = attribute.AttributeClass.Name;
149151
return commonTestAttributeNames.Contains(attributeName);
150152
});

0 commit comments

Comments
 (0)