Skip to content

Commit 9e71f5d

Browse files
committed
Merge pull request #2031 from sharwell/fix-2030
Rename SA1652 to SA0001 and improve messaging
2 parents e31cef3 + 1f27f18 commit 9e71f5d

15 files changed

Lines changed: 202 additions & 179 deletions

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1652UnitTests.cs renamed to StyleCop.Analyzers/StyleCop.Analyzers.Test/SpecialRules/SA0001UnitTests.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

4-
namespace StyleCop.Analyzers.Test.DocumentationRules
4+
namespace StyleCop.Analyzers.Test.SpecialRules
55
{
66
using System.Collections.Generic;
77
using System.Threading;
88
using System.Threading.Tasks;
9-
using Analyzers.DocumentationRules;
9+
using Analyzers.SpecialRules;
1010
using Microsoft.CodeAnalysis;
1111
using Microsoft.CodeAnalysis.Diagnostics;
1212
using TestHelper;
1313
using Xunit;
1414

1515
/// <summary>
16-
/// Unit tests for <see cref="SA1652EnableXmlDocumentationOutput"/>.
16+
/// Unit tests for <see cref="SA0001XmlCommentAnalysisDisabled"/>.
1717
/// </summary>
18-
public class SA1652UnitTests : DiagnosticVerifier
18+
public class SA0001UnitTests : DiagnosticVerifier
1919
{
2020
private DocumentationMode documentationMode;
2121

2222
[Theory]
23+
[InlineData(DocumentationMode.Parse)]
2324
[InlineData(DocumentationMode.Diagnose)]
2425
public async Task TestEnabledDocumentationModesAsync(DocumentationMode documentationMode)
2526
{
@@ -34,18 +35,14 @@ public async Task TestEnabledDocumentationModesAsync(DocumentationMode documenta
3435

3536
[Theory]
3637
[InlineData(DocumentationMode.None)]
37-
[InlineData(DocumentationMode.Parse)]
3838
public async Task TestDisabledDocumentationModesAsync(DocumentationMode documentationMode)
3939
{
4040
var testCode = @"public class Foo
4141
{
4242
}
4343
";
4444

45-
DiagnosticResult[] expected =
46-
{
47-
this.CSharpDiagnostic().WithLocation(0, 0)
48-
};
45+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(null, 0, 0);
4946

5047
this.documentationMode = documentationMode;
5148
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
@@ -54,7 +51,7 @@ public async Task TestDisabledDocumentationModesAsync(DocumentationMode document
5451
/// <inheritdoc/>
5552
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
5653
{
57-
yield return new SA1652EnableXmlDocumentationOutput();
54+
yield return new SA0001XmlCommentAnalysisDisabled();
5855
}
5956

6057
protected override Solution CreateSolution(ProjectId projectId, string language)

StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@
167167
<Compile Include="DocumentationRules\SA1649UnitTests.cs" />
168168
<Compile Include="DocumentationRules\SA1650UnitTests.cs" />
169169
<Compile Include="DocumentationRules\SA1651UnitTests.cs" />
170-
<Compile Include="DocumentationRules\SA1652UnitTests.cs" />
171170
<Compile Include="ExclusionTests.cs" />
172171
<Compile Include="ExportCodeFixProviderAttributeNameTest.cs" />
173172
<Compile Include="Helpers\CodeFixVerifier.Helper.cs" />
@@ -360,6 +359,7 @@
360359
<Compile Include="SpacingRules\SA1026UnitTests.cs" />
361360
<Compile Include="SpacingRules\SA1027UnitTests.cs" />
362361
<Compile Include="SpacingRules\SA1028UnitTests.cs" />
362+
<Compile Include="SpecialRules\SA0001UnitTests.cs" />
363363
<Compile Include="Verifiers\CodeFixVerifier.cs" />
364364
<Compile Include="Verifiers\DiagnosticVerifier.cs" />
365365
</ItemGroup>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.Designer.cs

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/DocumentationResources.resx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,6 @@
285285
<data name="SA1651CodeFix" xml:space="preserve">
286286
<value>Finalize placeholder text</value>
287287
</data>
288-
<data name="SA1652Description" xml:space="preserve">
289-
<value>The project is currently configured to not parse XML documentation comments; all diagnostics for documentation comments are disabled. Enable XML documentation output to enable these diagnostics.</value>
290-
</data>
291-
<data name="SA1652MessageFormat" xml:space="preserve">
292-
<value>Enable XML documentation output</value>
293-
</data>
294-
<data name="SA1652Title" xml:space="preserve">
295-
<value>Enable XML documentation output</value>
296-
</data>
297288
<data name="StartingTextGets" xml:space="preserve">
298289
<value>Gets</value>
299290
</data>

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1600ElementsMustBeDocumented.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static class Analyzer
8484
{
8585
public static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
8686
{
87-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
87+
if (context.GetDocumentationMode() == DocumentationMode.None)
8888
{
8989
return;
9090
}
@@ -109,7 +109,7 @@ public static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context,
109109

110110
public static void HandleMethodDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
111111
{
112-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
112+
if (context.GetDocumentationMode() == DocumentationMode.None)
113113
{
114114
return;
115115
}
@@ -129,7 +129,7 @@ public static void HandleMethodDeclaration(SyntaxNodeAnalysisContext context, St
129129

130130
public static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
131131
{
132-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
132+
if (context.GetDocumentationMode() == DocumentationMode.None)
133133
{
134134
return;
135135
}
@@ -149,7 +149,7 @@ public static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext contex
149149

150150
public static void HandleDestructorDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
151151
{
152-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
152+
if (context.GetDocumentationMode() == DocumentationMode.None)
153153
{
154154
return;
155155
}
@@ -169,7 +169,7 @@ public static void HandleDestructorDeclaration(SyntaxNodeAnalysisContext context
169169

170170
public static void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
171171
{
172-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
172+
if (context.GetDocumentationMode() == DocumentationMode.None)
173173
{
174174
return;
175175
}
@@ -189,7 +189,7 @@ public static void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context,
189189

190190
public static void HandleIndexerDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
191191
{
192-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
192+
if (context.GetDocumentationMode() == DocumentationMode.None)
193193
{
194194
return;
195195
}
@@ -209,7 +209,7 @@ public static void HandleIndexerDeclaration(SyntaxNodeAnalysisContext context, S
209209

210210
public static void HandleFieldDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
211211
{
212-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
212+
if (context.GetDocumentationMode() == DocumentationMode.None)
213213
{
214214
return;
215215
}
@@ -234,7 +234,7 @@ public static void HandleFieldDeclaration(SyntaxNodeAnalysisContext context, Sty
234234

235235
public static void HandleDelegateDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
236236
{
237-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
237+
if (context.GetDocumentationMode() == DocumentationMode.None)
238238
{
239239
return;
240240
}
@@ -254,7 +254,7 @@ public static void HandleDelegateDeclaration(SyntaxNodeAnalysisContext context,
254254

255255
public static void HandleEventDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
256256
{
257-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
257+
if (context.GetDocumentationMode() == DocumentationMode.None)
258258
{
259259
return;
260260
}
@@ -274,7 +274,7 @@ public static void HandleEventDeclaration(SyntaxNodeAnalysisContext context, Sty
274274

275275
public static void HandleEventFieldDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
276276
{
277-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
277+
if (context.GetDocumentationMode() == DocumentationMode.None)
278278
{
279279
return;
280280
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1601PartialElementsMustBeDocumented.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private static class Analyzer
109109
{
110110
public static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
111111
{
112-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
112+
if (context.GetDocumentationMode() == DocumentationMode.None)
113113
{
114114
return;
115115
}
@@ -133,7 +133,7 @@ public static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context,
133133

134134
public static void HandleMethodDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
135135
{
136-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
136+
if (context.GetDocumentationMode() == DocumentationMode.None)
137137
{
138138
return;
139139
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1602EnumerationItemsMustBeDocumented.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private static class Analyzer
7474
{
7575
public static void HandleEnumMemberDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
7676
{
77-
if (context.GetDocumentationMode() != DocumentationMode.Diagnose)
77+
if (context.GetDocumentationMode() == DocumentationMode.None)
7878
{
7979
return;
8080
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1652EnableXmlDocumentationOutput.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.SpecialRules
5+
{
6+
using System;
7+
using System.Collections.Immutable;
8+
using System.Threading;
9+
using Microsoft.CodeAnalysis;
10+
using Microsoft.CodeAnalysis.Diagnostics;
11+
12+
/// <summary>
13+
/// The project is configured to not parse XML documentation comments.
14+
/// </summary>
15+
[NoCodeFix("The necessary actions for this code fix are not supported by the analysis infrastructure.")]
16+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
17+
internal class SA0001XmlCommentAnalysisDisabled : DiagnosticAnalyzer
18+
{
19+
/// <summary>
20+
/// The ID for diagnostics produced by the <see cref="SA0001XmlCommentAnalysisDisabled"/> analyzer.
21+
/// </summary>
22+
public const string DiagnosticId = "SA0001";
23+
private const string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA0001.md";
24+
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(SpecialResources.SA0001Title), SpecialResources.ResourceManager, typeof(SpecialResources));
25+
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(SpecialResources.SA0001MessageFormat), SpecialResources.ResourceManager, typeof(SpecialResources));
26+
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(SpecialResources.SA0001Description), SpecialResources.ResourceManager, typeof(SpecialResources));
27+
28+
private static readonly DiagnosticDescriptor Descriptor =
29+
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
30+
31+
private static readonly Action<CompilationStartAnalysisContext> CompilationStartAction = HandleCompilationStart;
32+
33+
/// <inheritdoc/>
34+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
35+
ImmutableArray.Create(Descriptor);
36+
37+
/// <inheritdoc/>
38+
public override void Initialize(AnalysisContext context)
39+
{
40+
context.RegisterCompilationStartAction(CompilationStartAction);
41+
}
42+
43+
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
44+
{
45+
Analyzer analyzer = new Analyzer();
46+
context.RegisterSyntaxTreeActionHonorExclusions(analyzer.HandleSyntaxTree);
47+
context.RegisterCompilationEndAction(analyzer.HandleCompilation);
48+
}
49+
50+
private sealed class Analyzer
51+
{
52+
private bool documentationAnalysisDisabled;
53+
54+
public void HandleCompilation(CompilationAnalysisContext context)
55+
{
56+
if (Volatile.Read(ref this.documentationAnalysisDisabled))
57+
{
58+
context.ReportDiagnostic(Diagnostic.Create(Descriptor, Location.None));
59+
}
60+
}
61+
62+
public void HandleSyntaxTree(SyntaxTreeAnalysisContext context)
63+
{
64+
if (context.Tree.Options.DocumentationMode == DocumentationMode.None)
65+
{
66+
Volatile.Write(ref this.documentationAnalysisDisabled, true);
67+
}
68+
}
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)