Skip to content

Commit ddb1145

Browse files
PR Feedback
1 parent 1a54f21 commit ddb1145

7 files changed

Lines changed: 10 additions & 39 deletions

File tree

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/AttributesOnSeparateLinesTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ static void Main()
394394
[Description("Analyzer should not report on generated code")]
395395
public void AttributesOnSameLine_InGeneratedCode_NoDiagnostic()
396396
{
397-
// AttributesOnSeparateLines uses GeneratedCodeAnalysisFlags.Analyze | ReportDiagnostics,
398-
// meaning it reports inside generated code. It should skip generated code.
399397
string test = @"using System;
400398
using System.CodeDom.Compiler;
401399

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/DiagnosticUriBuilderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public void GetUrl_TitleWithTabsAndMultipleSpaces_HyphenatesCorrectly()
5252
{
5353
string actual = DiagnosticUrlBuilder.GetUrl("Fields Multiple\tSpaces", "INTL9999");
5454

55-
Assert.IsTrue(actual.Contains("FIELDS--MULTIPLE-SPACES", StringComparison.OrdinalIgnoreCase),
56-
$"Expected all whitespace replaced with hyphens but got: '{actual}'");
55+
Assert.IsTrue(actual.Contains("FIELDS-MULTIPLE-SPACES", StringComparison.OrdinalIgnoreCase),
56+
$"Expected consecutive whitespace collapsed to a single hyphen but got: '{actual}'");
5757
}
5858
}
5959
}

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/FavorEnumeratorDirectoryCallsTests.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,8 @@ static void Main(string[] args)
213213
}
214214

215215
[TestMethod]
216-
[Description("Identifier comparison should use OrdinalIgnoreCase, not CurrentCultureIgnoreCase")]
217216
public void DirectoryIdentifier_CaseInsensitiveOrdinal_ProducesInfoMessage()
218217
{
219-
// Verifies that an oddly-cased but valid Directory.GetFiles call is still caught.
220-
// CurrentCultureIgnoreCase could fail in Turkish locale for identifiers with 'I'.
221218
string source = @"
222219
using System;
223220
using System.IO;
@@ -246,11 +243,9 @@ static void Main(string[] args)
246243
}
247244

248245
[TestMethod]
249-
[Description("Analyzer misses fully-qualified System.IO.Directory.GetFiles()")]
246+
[Description("Detect fully-qualified System.IO.Directory.GetFiles()")]
250247
public void FullyQualifiedDirectoryGetFiles_ProducesInfoMessage()
251248
{
252-
// The analyzer only checks IdentifierNameSyntax, so System.IO.Directory.GetFiles()
253-
// is missed because the expression is a MemberAccessExpressionSyntax, not IdentifierNameSyntax.
254249
string source = @"
255250
using System;
256251
@@ -278,7 +273,7 @@ static void Main(string[] args)
278273
}
279274

280275
[TestMethod]
281-
[Description("Analyzer misses fully-qualified System.IO.Directory.GetDirectories()")]
276+
[Description("Detect fully-qualified System.IO.Directory.GetDirectories()")]
282277
public void FullyQualifiedDirectoryGetDirectories_ProducesInfoMessage()
283278
{
284279
string source = @"

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/NamingFieldPascalUnderscoreTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Linq;
21
using System.Threading.Tasks;
32
using Microsoft.CodeAnalysis;
43
using Microsoft.CodeAnalysis.CodeFixes;
@@ -453,11 +452,9 @@ class TypeName
453452
}
454453

455454
[TestMethod]
456-
[Description("GeneratedCodeAttribute is checked by Name only, not full type — custom attribute with same name suppresses incorrectly")]
455+
[Description("Custom GeneratedCodeAttribute in different namespace should not suppress diagnostics")]
457456
public void FieldWithNamingViolation_CustomGeneratedCodeAttribute_ShouldStillWarn()
458457
{
459-
// A user-defined GeneratedCodeAttribute (different namespace) should NOT
460-
// suppress the naming diagnostic, but the current code checks by Name only.
461458
string test = @"
462459
using System;
463460

IntelliTect.Analyzer/IntelliTect.Analyzer.Test/UnusedLocalVariableTests.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ namespace IntelliTect.Analyzer.Tests
99
[TestClass]
1010
public class UnusedLocalVariableTests : CodeFixVerifier
1111
{
12-
[TestMethod]
13-
[Description("HelpLinkUri should use DiagnosticUrlBuilder, not a hardcoded generic URL")]
14-
public void Descriptor_HelpLinkUri_ShouldBeSpecific()
15-
{
16-
DiagnosticAnalyzer analyzer = GetCSharpDiagnosticAnalyzer();
17-
DiagnosticDescriptor diagnostic = analyzer.SupportedDiagnostics.Single();
18-
19-
string expectedUrl = DiagnosticUrlBuilder.GetUrl("Local variable unused", "INTL0303");
20-
Assert.AreEqual(expectedUrl, diagnostic.HelpLinkUri,
21-
$"HelpLinkUri should use DiagnosticUrlBuilder but was '{diagnostic.HelpLinkUri}'");
22-
}
23-
2412
[TestMethod]
2513
public void InstanceMemberAccessedOnLocalVariable_NoDiagnosticInformationReturned()
2614
{
@@ -262,11 +250,9 @@ bool Bar(Func<bool, bool> func)
262250
}
263251

264252
[TestMethod]
265-
[Description("Analyzer reports on generated code but should skip it")]
253+
[Description("Analyzer should skip generated code")]
266254
public void UnusedLocalVariable_InGeneratedCode_NoDiagnostic()
267255
{
268-
// UnusedLocalVariable uses GeneratedCodeAnalysisFlags.Analyze | ReportDiagnostics,
269-
// meaning it reports inside generated code. It should use None to skip generated code.
270256
string test = @"
271257
using System;
272258
using System.CodeDom.Compiler;

IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/FavorDirectoryEnumerationCalls.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ private static bool IsDirectoryExpression(ExpressionSyntax expression, SyntaxNod
8787
// For fully-qualified expressions like 'System.IO.Directory'
8888
if (expression is MemberAccessExpressionSyntax)
8989
{
90-
ISymbol resolvedSymbol = symbolInfo.Symbol
91-
?? (symbolInfo.CandidateSymbols.Length > 0 ? symbolInfo.CandidateSymbols[0] : null);
92-
93-
if (resolvedSymbol is INamedTypeSymbol namedType)
90+
if (symbolInfo.Symbol is INamedTypeSymbol namedType)
9491
{
9592
return namedType.OriginalDefinition
9693
.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) == "global::System.IO.Directory";

IntelliTect.Analyzer/IntelliTect.Analyzer/DiagnosticUrlBuilder.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
namespace IntelliTect.Analyzer
55
{
6-
public static partial class DiagnosticUrlBuilder
6+
public static class DiagnosticUrlBuilder
77
{
88
private const string BaseUrl = "https://github.com/IntelliTect/CodingGuidelines";
9+
private static readonly Regex _HyphenateRegex = new(@"\s+", RegexOptions.Compiled);
910

1011
/// <summary>
1112
/// Get the full diagnostic help url
@@ -21,12 +22,9 @@ public static string GetUrl(string title, string diagnosticId)
2122
if (string.IsNullOrWhiteSpace(diagnosticId))
2223
throw new System.ArgumentException("diagnostic ID cannot be empty", nameof(diagnosticId));
2324

24-
string hyphenatedTitle = HyphenateRegex().Replace(title, "-");
25+
string hyphenatedTitle = _HyphenateRegex.Replace(title, "-");
2526

2627
return BaseUrl + $"#{diagnosticId.ToUpperInvariant()}" + $"---{hyphenatedTitle.ToUpperInvariant()}";
2728
}
28-
29-
[GeneratedRegex(@"\s", RegexOptions.Compiled)]
30-
private static partial Regex HyphenateRegex();
3129
}
3230
}

0 commit comments

Comments
 (0)