Skip to content

Commit 2630890

Browse files
committed
Rename SA1652 to SA0001 and improve messaging
Fixes #2030
1 parent e31cef3 commit 2630890

12 files changed

Lines changed: 188 additions & 165 deletions

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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

@@ -42,10 +42,7 @@ public async Task TestDisabledDocumentationModesAsync(DocumentationMode document
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/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.Diagnose)
65+
{
66+
Volatile.Write(ref this.documentationAnalysisDisabled, true);
67+
}
68+
}
69+
}
70+
}
71+
}

StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SpecialResources.Designer.cs

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

StyleCop.Analyzers/StyleCop.Analyzers/SpecialRules/SpecialResources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,13 @@ Note that some situations are not affected by the bug:
133133
<data name="SA0000Title" xml:space="preserve">
134134
<value>Workaround incomplete diagnostics in Visual Studio 2015 Update 1</value>
135135
</data>
136+
<data name="SA0001Description" xml:space="preserve">
137+
<value>XML comment analysis can only be performed when the project is configured to parse documentation comments. To enable this functionality, update the project to produce an XML documentation file as part of the build.</value>
138+
</data>
139+
<data name="SA0001MessageFormat" xml:space="preserve">
140+
<value>XML comment analysis is disabled due to project configuration</value>
141+
</data>
142+
<data name="SA0001Title" xml:space="preserve">
143+
<value>XML comment analysis disabled</value>
144+
</data>
136145
</root>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
<Compile Include="DocumentationRules\SA1649FileNameMustMatchTypeName.cs" />
103103
<Compile Include="DocumentationRules\SA1650ElementDocumentationMustBeSpelledCorrectly.cs" />
104104
<Compile Include="DocumentationRules\SA1651DoNotUsePlaceholderElements.cs" />
105-
<Compile Include="DocumentationRules\SA1652EnableXmlDocumentationOutput.cs" />
106105
<Compile Include="DocumentationRules\StandardTextDiagnosticBase.cs" />
107106
<Compile Include="ExcludeFromCodeCoverageAttribute.cs" />
108107
<Compile Include="GeneratedCodeAnalysisExtensions.cs" />
@@ -323,6 +322,7 @@
323322
</Compile>
324323
<Compile Include="SpacingRules\TokenSpacingProperties.cs" />
325324
<Compile Include="SpecialRules\SA0000Roslyn7446Workaround.cs" />
325+
<Compile Include="SpecialRules\SA0001XmlCommentAnalysisDisabled.cs" />
326326
<Compile Include="SpecialRules\SpecialResources.Designer.cs">
327327
<AutoGen>True</AutoGen>
328328
<DesignTime>True</DesignTime>

StyleCopAnalyzers.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "documentation", "documentat
3838
documentation\EnableConfiguration.md = documentation\EnableConfiguration.md
3939
documentation\KnownChanges.md = documentation\KnownChanges.md
4040
documentation\SA0000Roslyn7446Workaround.md = documentation\SA0000Roslyn7446Workaround.md
41+
documentation\SA0001.md = documentation\SA0001.md
4142
documentation\SA1000.md = documentation\SA1000.md
4243
documentation\SA1001.md = documentation\SA1001.md
4344
documentation\SA1002.md = documentation\SA1002.md

0 commit comments

Comments
 (0)