├── .editorconfig ├── .gitattributes ├── .gitignore ├── .mailmap ├── .nuget └── packages.config ├── CONTRIBUTING.md ├── DOCUMENTATION.md ├── DocumentationAnalyzers.sln ├── DocumentationAnalyzers ├── Directory.Build.props ├── Directory.Build.targets ├── DocumentationAnalyzers.CodeFixes │ ├── DocumentationAnalyzers.CodeFixes.csproj │ ├── DocumentationAnalyzers.Metadata.nuspec │ ├── DocumentationAnalyzers.nuspec │ ├── Helpers │ │ ├── CustomBatchFixAllProvider.cs │ │ ├── CustomFixAllProviders.cs │ │ ├── FixAllContextHelper.cs │ │ └── XmlSyntaxFactory.cs │ ├── PortabilityRules │ │ ├── DOC200CodeFixProvider.cs │ │ ├── DOC201CodeFixProvider.cs │ │ ├── DOC202CodeFixProvider.cs │ │ ├── DOC203CodeFixProvider.cs │ │ └── DOC204CodeFixProvider.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RefactoringRules │ │ ├── DOC900CodeFixProvider+DocumentationCommentPrinter.cs │ │ ├── DOC900CodeFixProvider+DocumentationCommentTextWriter.cs │ │ ├── DOC900CodeFixProvider.cs │ │ └── DOC901CodeFixProvider.cs │ ├── StyleRules │ │ ├── BlockLevelDocumentationCodeFixProvider.cs │ │ ├── DOC103CodeFixProvider.cs │ │ ├── DOC104CodeFixProvider.cs │ │ ├── DOC105CodeFixProvider.cs │ │ ├── DOC106CodeFixProvider.cs │ │ ├── DOC107CodeFixProvider.cs │ │ └── DOC108CodeFixProvider.cs │ └── tools │ │ ├── install.ps1 │ │ └── uninstall.ps1 ├── DocumentationAnalyzers.Internal.ruleset ├── DocumentationAnalyzers.Status.Generator │ ├── CodeFixStatus.cs │ ├── DocumentationAnalyzers.Status.Generator.csproj │ ├── DocumentationDiagnostic.cs │ ├── FixAllStatus.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── SolutionReader.cs │ └── app.config ├── DocumentationAnalyzers.Test.CSharp7 │ ├── AnalyzerConfigurationTestsCSharp7.cs │ ├── DocumentationAnalyzers.Test.CSharp7.csproj │ ├── PortabilityRules │ │ ├── DOC200CSharp7UnitTests.cs │ │ ├── DOC201CSharp7UnitTests.cs │ │ ├── DOC202CSharp7UnitTests.cs │ │ ├── DOC203CSharp7UnitTests.cs │ │ ├── DOC204CSharp7UnitTests.cs │ │ ├── DOC207CSharp7UnitTests.cs │ │ └── DOC209CSharp7UnitTests.cs │ ├── RefactoringRules │ │ ├── DOC900CSharp7UnitTests.cs │ │ └── DOC901CSharp7UnitTests.cs │ └── StyleRules │ │ ├── DOC100CSharp7UnitTests.cs │ │ ├── DOC101CSharp7UnitTests.cs │ │ ├── DOC102CSharp7UnitTests.cs │ │ ├── DOC103CSharp7UnitTests.cs │ │ ├── DOC104CSharp7UnitTests.cs │ │ ├── DOC105CSharp7UnitTests.cs │ │ ├── DOC106CSharp7UnitTests.cs │ │ └── DOC107CSharp7UnitTests.cs ├── DocumentationAnalyzers.Test │ ├── AnalyzerConfigurationTests.cs │ ├── AttributeTests.cs │ ├── DocumentationAnalyzers.Test.csproj │ ├── ExportCodeFixProviderAttributeNameTest.cs │ ├── PortabilityRules │ │ ├── DOC200UnitTests.cs │ │ ├── DOC201UnitTests.cs │ │ ├── DOC202UnitTests.cs │ │ ├── DOC203UnitTests.cs │ │ ├── DOC204UnitTests.cs │ │ ├── DOC207UnitTests.cs │ │ └── DOC209UnitTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── PublicApiTests.cs │ ├── RefactoringRules │ │ ├── DOC900UnitTests.cs │ │ └── DOC901UnitTests.cs │ ├── SequentialTestCollection.cs │ ├── StyleRules │ │ ├── DOC100UnitTests.cs │ │ ├── DOC101UnitTests.cs │ │ ├── DOC102UnitTests.cs │ │ ├── DOC103UnitTests.cs │ │ ├── DOC104UnitTests.cs │ │ ├── DOC105UnitTests.cs │ │ ├── DOC106UnitTests.cs │ │ ├── DOC107UnitTests.cs │ │ └── DOC108UnitTests.cs │ ├── Verifiers │ │ ├── CSharpAnalyzerVerifier`1+Test.cs │ │ ├── CSharpAnalyzerVerifier`1.cs │ │ ├── CSharpCodeFixVerifier`2+Test.cs │ │ ├── CSharpCodeFixVerifier`2.cs │ │ ├── CSharpCodeRefactoringVerifier`1+Test.cs │ │ ├── CSharpCodeRefactoringVerifier`1.cs │ │ ├── CSharpVerifierHelper.cs │ │ ├── VisualBasicAnalyzerVerifier`1+Test.cs │ │ ├── VisualBasicAnalyzerVerifier`1.cs │ │ ├── VisualBasicCodeFixVerifier`2+Test.cs │ │ ├── VisualBasicCodeFixVerifier`2.cs │ │ ├── VisualBasicCodeRefactoringVerifier`1+Test.cs │ │ └── VisualBasicCodeRefactoringVerifier`1.cs │ └── WorkItemAttribute.cs ├── DocumentationAnalyzers.Vsix │ ├── DocumentationAnalyzers.Vsix.csproj │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── launchSettings.json │ └── source.extension.vsixmanifest ├── DocumentationAnalyzers.ruleset ├── DocumentationAnalyzers │ ├── AnalyzerCategory.cs │ ├── AnalyzerConstants.cs │ ├── DocumentationAnalyzers.csproj │ ├── ExcludeFromCodeCoverageAttribute.cs │ ├── Helpers │ │ ├── DocumentationCommentExtensions.cs │ │ ├── HelpersResources.Designer.cs │ │ ├── HelpersResources.resx │ │ ├── SpacingExtensions.cs │ │ ├── SpecializedTasks.cs │ │ ├── SymbolExtensions.cs │ │ ├── SyntaxNodeExtensionsEx.cs │ │ └── XmlCommentHelper.cs │ ├── NoCodeFixAttribute.cs │ ├── PortabilityRules │ │ ├── DOC200UseXmlDocumentationSyntax.cs │ │ ├── DOC201ItemShouldHaveDescription.cs │ │ ├── DOC202UseSectionElementsCorrectly.cs │ │ ├── DOC203UseBlockElementsCorrectly.cs │ │ ├── DOC204UseInlineElementsCorrectly.cs │ │ ├── DOC207UseSeeLangwordCorrectly.cs │ │ ├── DOC209UseSeeHrefCorrectly.cs │ │ ├── PortabilityResources.Designer.cs │ │ └── PortabilityResources.resx │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RefactoringRules │ │ ├── DOC900RenderAsMarkdown.cs │ │ ├── DOC901ConvertToDocumentationComment.cs │ │ ├── RefactoringResources.Designer.cs │ │ └── RefactoringResources.resx │ └── StyleRules │ │ ├── BlockLevelDocumentationAnalyzerBase.cs │ │ ├── DOC100PlaceTextInParagraphs.cs │ │ ├── DOC101UseChildBlocksConsistently.cs │ │ ├── DOC102UseChildBlocksConsistentlyAcrossElementsOfTheSameKind.cs │ │ ├── DOC103UseUnicodeCharacters.cs │ │ ├── DOC104UseSeeLangword.cs │ │ ├── DOC105UseParamref.cs │ │ ├── DOC106UseTypeparamref.cs │ │ ├── DOC107UseSeeCref.cs │ │ ├── DOC108AvoidEmptyParagraphs.cs │ │ ├── InlineCodeAnalyzerBase.cs │ │ ├── StyleResources.Designer.cs │ │ └── StyleResources.resx ├── stylecop.json └── version.json ├── LICENSE ├── NuGet.config ├── README.md ├── THIRD-PARTY-NOTICES.txt ├── appveyor.yml ├── build ├── build.ps1 ├── check-key.ps1 ├── keys.ps1 ├── keys │ ├── DocumentationAnalyzers.dev.snk │ ├── DocumentationAnalyzers.snk │ └── TestingKey.snk └── opencover-report.ps1 ├── codecov.yml └── docs ├── DOC100.md ├── DOC101.md ├── DOC102.md ├── DOC103.md ├── DOC104.md ├── DOC105.md ├── DOC106.md ├── DOC107.md ├── DOC108.md ├── DOC200.md ├── DOC201.md ├── DOC202.md ├── DOC203.md ├── DOC204.md ├── DOC207.md ├── DOC209.md ├── DOC900.md ├── DOC901.md ├── PortabilityRules.md ├── Refactorings.md ├── StyleRules.md └── index.html /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build output 2 | bin/ 3 | obj/ 4 | 5 | # Artifacts of the IDE and build 6 | .vs/ 7 | packages/ 8 | *.suo 9 | *.user 10 | OpenCover.Reports/ 11 | OpenCover.Symbols/ 12 | .nuget/NuGet.exe 13 | build/nuget/ 14 | *.log 15 | 16 | # Visual Studio performance tools 17 | *.psess 18 | *.vsp 19 | *.vspx 20 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetAnalyzers/DocumentationAnalyzers/5152abcc72b665c241d5539877d23873d84839ce/.mailmap -------------------------------------------------------------------------------- /.nuget/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | If you want to contribute code you can get started by looking for issues marked as 4 | [help wanted](https://github.com/DotNetAnalyzers/DocumentationAnalyzers/labels/help%20wanted). 5 | 6 | You can also help by filing issues, participating in discussions and doing code review. 7 | 8 | ## Building 9 | 10 | Visual Studio 2017 (Community Edition or higher) is required for building this repository. 11 | -------------------------------------------------------------------------------- /DOCUMENTATION.md: -------------------------------------------------------------------------------- 1 | DocumentationAnalyzers provides warnings that indicate documentation rule violations in C# code. The warnings are organized into rule areas. This section provides an explanation of each of the default DocumentationAnalyzers rules. 2 | 3 | ### Rule areas 4 | 5 | **[Style Rules (DOC100-)](docs/StyleRules.md)** 6 | 7 | Rules related to the style of documentation comments. 8 | 9 | **[Portability Rules (DOC200-)](docs/PortabilityRules.md)** 10 | 11 | Rules related to the portability of documentation comments. 12 | 13 | **[Refactorings (DOC900-)](docs/Refactorings.md)** 14 | 15 | Additional refactorings provided when the analyzer is installed. 16 | 17 | ### Additional documentation 18 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | An implementation of .NET documentation rules using the .NET Compiler Platform 6 | DocumentationAnalyzers 7 | Tunnel Vision Laboratories, LLC 8 | Copyright © Tunnel Vision Laboratories, LLC 2018 9 | en-US 10 | 11 | 12 | 13 | 9 14 | 5 15 | strict 16 | 17 | 18 | 19 | 20 | true 21 | 22 | 23 | 24 | full 25 | portable 26 | true 27 | 28 | 29 | 30 | 38 | True 39 | $(NoWarn),1573,1591,1712 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | stylecop.json 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/DocumentationAnalyzers.Metadata.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | 0.0.0 6 | $id$ 7 | Sam Harwell et. al. 8 | Sam Harwell 9 | MIT 10 | https://github.com/DotNetAnalyzers/DocumentationAnalyzers 11 | false 12 | An implementation of .NET documentation rules using Roslyn analyzers and code fixes 13 | https://github.com/DotNetAnalyzers/DocumentationAnalyzers/releases/$tag$ 14 | Copyright 2018 Tunnel Vision Laboratories, LLC 15 | Documentation DotNetAnalyzers Roslyn Diagnostic Analyzer 16 | true 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/DocumentationAnalyzers.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | 0.0.0 6 | $id$ 7 | Sam Harwell et. al. 8 | Sam Harwell 9 | MIT 10 | https://github.com/DotNetAnalyzers/DocumentationAnalyzers 11 | false 12 | An implementation of .NET documentation rules using Roslyn analyzers and code fixes 13 | https://github.com/DotNetAnalyzers/DocumentationAnalyzers/releases/$tag$ 14 | Copyright 2018 Tunnel Vision Laboratories, LLC 15 | Documentation DotNetAnalyzers Roslyn Diagnostic Analyzer 16 | true 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/Helpers/CustomFixAllProviders.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Helpers 5 | { 6 | using Microsoft.CodeAnalysis.CodeActions; 7 | using Microsoft.CodeAnalysis.CodeFixes; 8 | 9 | /// 10 | /// Contains custom implementations of . 11 | /// 12 | internal static class CustomFixAllProviders 13 | { 14 | /// 15 | /// Gets the default batch fix all provider. 16 | /// This provider batches all the individual diagnostic fixes across the scope of fix all action, 17 | /// computes fixes in parallel and then merges all the non-conflicting fixes into a single fix all code action. 18 | /// This fixer supports fixes for the following fix all scopes: 19 | /// , and . 20 | /// 21 | /// 22 | /// The batch fix all provider only batches operations (i.e. ) of type 23 | /// present within the individual diagnostic fixes. Other types of 24 | /// operations present within these fixes are ignored. 25 | /// 26 | /// 27 | /// The default batch fix all provider. 28 | /// 29 | public static FixAllProvider BatchFixer => CustomBatchFixAllProvider.Instance; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/PortabilityRules/DOC201CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.PortabilityRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using DocumentationAnalyzers.Helpers; 11 | using Microsoft.CodeAnalysis; 12 | using Microsoft.CodeAnalysis.CodeActions; 13 | using Microsoft.CodeAnalysis.CodeFixes; 14 | using Microsoft.CodeAnalysis.CSharp.Syntax; 15 | 16 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC201CodeFixProvider))] 17 | [Shared] 18 | internal class DOC201CodeFixProvider : CodeFixProvider 19 | { 20 | public override ImmutableArray FixableDiagnosticIds { get; } 21 | = ImmutableArray.Create(DOC201ItemShouldHaveDescription.DiagnosticId); 22 | 23 | public override FixAllProvider GetFixAllProvider() 24 | => CustomFixAllProviders.BatchFixer; 25 | 26 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 27 | { 28 | foreach (var diagnostic in context.Diagnostics) 29 | { 30 | if (!FixableDiagnosticIds.Contains(diagnostic.Id)) 31 | { 32 | continue; 33 | } 34 | 35 | context.RegisterCodeFix( 36 | CodeAction.Create( 37 | PortabilityResources.DOC201CodeFix, 38 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 39 | nameof(DOC201CodeFixProvider)), 40 | diagnostic); 41 | } 42 | 43 | return SpecializedTasks.CompletedTask; 44 | } 45 | 46 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 47 | { 48 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 49 | SyntaxToken token = root.FindToken(diagnostic.Location.SourceSpan.Start, findInsideTrivia: true); 50 | 51 | var xmlElement = token.Parent.FirstAncestorOrSelf(); 52 | var newXmlElement = xmlElement.WithContent(XmlSyntaxFactory.List(XmlSyntaxFactory.Element(XmlCommentHelper.DescriptionXmlTag, xmlElement.Content))); 53 | return document.WithSyntaxRoot(root.ReplaceNode(xmlElement, newXmlElement)); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/PortabilityRules/DOC202CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.PortabilityRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using DocumentationAnalyzers.Helpers; 11 | using Microsoft.CodeAnalysis; 12 | using Microsoft.CodeAnalysis.CodeActions; 13 | using Microsoft.CodeAnalysis.CodeFixes; 14 | using Microsoft.CodeAnalysis.CSharp; 15 | using Microsoft.CodeAnalysis.CSharp.Syntax; 16 | 17 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC202CodeFixProvider))] 18 | [Shared] 19 | internal class DOC202CodeFixProvider : CodeFixProvider 20 | { 21 | public override ImmutableArray FixableDiagnosticIds { get; } 22 | = ImmutableArray.Create(DOC202UseSectionElementsCorrectly.DiagnosticId); 23 | 24 | public override FixAllProvider GetFixAllProvider() 25 | => CustomFixAllProviders.BatchFixer; 26 | 27 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 28 | { 29 | foreach (var diagnostic in context.Diagnostics) 30 | { 31 | if (!FixableDiagnosticIds.Contains(diagnostic.Id)) 32 | { 33 | continue; 34 | } 35 | 36 | context.RegisterCodeFix( 37 | CodeAction.Create( 38 | PortabilityResources.DOC202CodeFix, 39 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 40 | nameof(DOC202CodeFixProvider)), 41 | diagnostic); 42 | } 43 | 44 | return SpecializedTasks.CompletedTask; 45 | } 46 | 47 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 48 | { 49 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 50 | SyntaxToken token = root.FindToken(diagnostic.Location.SourceSpan.Start, findInsideTrivia: true); 51 | 52 | var xmlNode = token.Parent.FirstAncestorOrSelf(); 53 | var oldStartToken = xmlNode.GetName().LocalName; 54 | 55 | string newIdentifier; 56 | switch (oldStartToken.ValueText) 57 | { 58 | case XmlCommentHelper.ParamXmlTag: 59 | newIdentifier = XmlCommentHelper.ParamRefXmlTag; 60 | break; 61 | 62 | case XmlCommentHelper.TypeParamXmlTag: 63 | newIdentifier = XmlCommentHelper.TypeParamRefXmlTag; 64 | break; 65 | 66 | default: 67 | // Not handled 68 | return document; 69 | } 70 | 71 | var newStartToken = SyntaxFactory.Identifier(oldStartToken.LeadingTrivia, newIdentifier, oldStartToken.TrailingTrivia); 72 | var newXmlNode = xmlNode.ReplaceToken(oldStartToken, newStartToken); 73 | 74 | if (newXmlNode is XmlElementSyntax newXmlElement) 75 | { 76 | var oldEndToken = newXmlElement.EndTag.Name.LocalName; 77 | var newEndToken = SyntaxFactory.Identifier(oldEndToken.LeadingTrivia, newIdentifier, oldEndToken.TrailingTrivia); 78 | newXmlNode = newXmlNode.ReplaceToken(oldEndToken, newEndToken); 79 | } 80 | 81 | return document.WithSyntaxRoot(root.ReplaceNode(xmlNode, newXmlNode)); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/PortabilityRules/DOC203CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.PortabilityRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using DocumentationAnalyzers.Helpers; 11 | using Microsoft.CodeAnalysis; 12 | using Microsoft.CodeAnalysis.CodeActions; 13 | using Microsoft.CodeAnalysis.CodeFixes; 14 | using Microsoft.CodeAnalysis.CSharp; 15 | using Microsoft.CodeAnalysis.CSharp.Syntax; 16 | 17 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC203CodeFixProvider))] 18 | [Shared] 19 | internal class DOC203CodeFixProvider : CodeFixProvider 20 | { 21 | public override ImmutableArray FixableDiagnosticIds { get; } 22 | = ImmutableArray.Create(DOC203UseBlockElementsCorrectly.DiagnosticId); 23 | 24 | public override FixAllProvider GetFixAllProvider() 25 | => CustomFixAllProviders.BatchFixer; 26 | 27 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 28 | { 29 | foreach (var diagnostic in context.Diagnostics) 30 | { 31 | if (!FixableDiagnosticIds.Contains(diagnostic.Id)) 32 | { 33 | continue; 34 | } 35 | 36 | context.RegisterCodeFix( 37 | CodeAction.Create( 38 | PortabilityResources.DOC203CodeFix, 39 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 40 | nameof(DOC203CodeFixProvider)), 41 | diagnostic); 42 | } 43 | 44 | return SpecializedTasks.CompletedTask; 45 | } 46 | 47 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 48 | { 49 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 50 | SyntaxToken token = root.FindToken(diagnostic.Location.SourceSpan.Start, findInsideTrivia: true); 51 | 52 | var xmlNode = token.Parent.FirstAncestorOrSelf(); 53 | var oldStartToken = xmlNode.GetName().LocalName; 54 | 55 | string newIdentifier; 56 | switch (oldStartToken.ValueText) 57 | { 58 | case XmlCommentHelper.CodeXmlTag: 59 | newIdentifier = XmlCommentHelper.CXmlTag; 60 | break; 61 | 62 | default: 63 | // Not handled 64 | return document; 65 | } 66 | 67 | var newStartToken = SyntaxFactory.Identifier(oldStartToken.LeadingTrivia, newIdentifier, oldStartToken.TrailingTrivia); 68 | var newXmlNode = xmlNode.ReplaceToken(oldStartToken, newStartToken); 69 | 70 | if (newXmlNode is XmlElementSyntax newXmlElement) 71 | { 72 | var oldEndToken = newXmlElement.EndTag.Name.LocalName; 73 | var newEndToken = SyntaxFactory.Identifier(oldEndToken.LeadingTrivia, newIdentifier, oldEndToken.TrailingTrivia); 74 | newXmlNode = newXmlNode.ReplaceToken(oldEndToken, newEndToken); 75 | } 76 | 77 | return document.WithSyntaxRoot(root.ReplaceNode(xmlNode, newXmlNode)); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/PortabilityRules/DOC204CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.PortabilityRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using DocumentationAnalyzers.Helpers; 11 | using Microsoft.CodeAnalysis; 12 | using Microsoft.CodeAnalysis.CodeActions; 13 | using Microsoft.CodeAnalysis.CodeFixes; 14 | using Microsoft.CodeAnalysis.CSharp; 15 | using Microsoft.CodeAnalysis.CSharp.Syntax; 16 | 17 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC204CodeFixProvider))] 18 | [Shared] 19 | internal class DOC204CodeFixProvider : CodeFixProvider 20 | { 21 | public override ImmutableArray FixableDiagnosticIds { get; } 22 | = ImmutableArray.Create(DOC204UseInlineElementsCorrectly.DiagnosticId); 23 | 24 | public override FixAllProvider GetFixAllProvider() 25 | => CustomFixAllProviders.BatchFixer; 26 | 27 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 28 | { 29 | foreach (var diagnostic in context.Diagnostics) 30 | { 31 | if (!FixableDiagnosticIds.Contains(diagnostic.Id)) 32 | { 33 | continue; 34 | } 35 | 36 | context.RegisterCodeFix( 37 | CodeAction.Create( 38 | PortabilityResources.DOC204CodeFix, 39 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 40 | nameof(DOC204CodeFixProvider)), 41 | diagnostic); 42 | } 43 | 44 | return SpecializedTasks.CompletedTask; 45 | } 46 | 47 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 48 | { 49 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 50 | SyntaxToken token = root.FindToken(diagnostic.Location.SourceSpan.Start, findInsideTrivia: true); 51 | 52 | var xmlNode = token.Parent.FirstAncestorOrSelf(); 53 | var oldStartToken = xmlNode.GetName().LocalName; 54 | 55 | string newIdentifier; 56 | switch (oldStartToken.ValueText) 57 | { 58 | case XmlCommentHelper.ParamRefXmlTag: 59 | newIdentifier = XmlCommentHelper.ParamXmlTag; 60 | break; 61 | 62 | case XmlCommentHelper.TypeParamRefXmlTag: 63 | newIdentifier = XmlCommentHelper.TypeParamXmlTag; 64 | break; 65 | 66 | default: 67 | // Not handled 68 | return document; 69 | } 70 | 71 | var newStartToken = SyntaxFactory.Identifier(oldStartToken.LeadingTrivia, newIdentifier, oldStartToken.TrailingTrivia); 72 | var newXmlNode = xmlNode.ReplaceToken(oldStartToken, newStartToken); 73 | 74 | if (newXmlNode is XmlElementSyntax newXmlElement) 75 | { 76 | var oldEndToken = newXmlElement.EndTag.Name.LocalName; 77 | var newEndToken = SyntaxFactory.Identifier(oldEndToken.LeadingTrivia, newIdentifier, oldEndToken.TrailingTrivia); 78 | newXmlNode = newXmlNode.ReplaceToken(oldEndToken, newEndToken); 79 | } 80 | 81 | return document.WithSyntaxRoot(root.ReplaceNode(xmlNode, newXmlNode)); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | 8 | [assembly: CLSCompliant(false)] 9 | 10 | // Setting ComVisible to false makes the types in this assembly not visible 11 | // to COM components. If you need to access a type in this assembly from 12 | // COM, set the ComVisible attribute to true on that type. 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: InternalsVisibleTo("DocumentationAnalyzers.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001004d394e527140f84e656e715fc026e74b57657f47ff20636a0d90719bd0fd86b49ccfe3feb0a486b08b994bf8d68ead40ce4a993019c701b4d52c4c86ed88491edae914154b238c8378736b87529fd91502426263242fc5b800ee7a25a8a34f838f2dd1d20a483ccdfa0f6e1f08afb0d650d90b024ab129c1b840189d27b845c8")] 16 | [assembly: InternalsVisibleTo("DocumentationAnalyzers.Test.CSharp7, PublicKey=00240000048000009400000006020000002400005253413100040000010001004d394e527140f84e656e715fc026e74b57657f47ff20636a0d90719bd0fd86b49ccfe3feb0a486b08b994bf8d68ead40ce4a993019c701b4d52c4c86ed88491edae914154b238c8378736b87529fd91502426263242fc5b800ee7a25a8a34f838f2dd1d20a483ccdfa0f6e1f08afb0d650d90b024ab129c1b840189d27b845c8")] 17 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC103CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Diagnostics; 9 | using System.Net; 10 | using System.Threading; 11 | using System.Threading.Tasks; 12 | using DocumentationAnalyzers.Helpers; 13 | using Microsoft.CodeAnalysis; 14 | using Microsoft.CodeAnalysis.CodeActions; 15 | using Microsoft.CodeAnalysis.CodeFixes; 16 | using Microsoft.CodeAnalysis.CSharp; 17 | 18 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC103CodeFixProvider))] 19 | [Shared] 20 | internal class DOC103CodeFixProvider : CodeFixProvider 21 | { 22 | private const string CS1570 = nameof(CS1570); 23 | 24 | public override ImmutableArray FixableDiagnosticIds { get; } 25 | = ImmutableArray.Create(DOC103UseUnicodeCharacters.DiagnosticId, CS1570); 26 | 27 | public override FixAllProvider GetFixAllProvider() 28 | => CustomFixAllProviders.BatchFixer; 29 | 30 | public override async Task RegisterCodeFixesAsync(CodeFixContext context) 31 | { 32 | SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); 33 | 34 | foreach (var diagnostic in context.Diagnostics) 35 | { 36 | Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)"); 37 | 38 | SyntaxToken token = root.FindToken(diagnostic.Location.SourceSpan.Start, findInsideTrivia: true); 39 | if (!token.IsKind(SyntaxKind.XmlEntityLiteralToken)) 40 | { 41 | // Could be an unrelated CS1570 error. 42 | return; 43 | } 44 | 45 | string newText = token.ValueText; 46 | if (newText == token.Text) 47 | { 48 | // The entity is not recognized. Try decoding as an HTML entity. 49 | newText = WebUtility.HtmlDecode(token.Text); 50 | } 51 | 52 | if (newText == token.Text) 53 | { 54 | // Unknown entity 55 | continue; 56 | } 57 | 58 | context.RegisterCodeFix( 59 | CodeAction.Create( 60 | StyleResources.DOC103CodeFix, 61 | cancellationToken => GetTransformedDocumentAsync(context.Document, diagnostic, newText, cancellationToken), 62 | nameof(DOC103CodeFixProvider)), 63 | diagnostic); 64 | } 65 | } 66 | 67 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, string newText, CancellationToken cancellationToken) 68 | { 69 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 70 | SyntaxToken token = root.FindToken(diagnostic.Location.SourceSpan.Start, findInsideTrivia: true); 71 | 72 | var newToken = SyntaxFactory.Token(token.LeadingTrivia, SyntaxKind.XmlTextLiteralToken, newText, newText, token.TrailingTrivia); 73 | 74 | return document.WithSyntaxRoot(root.ReplaceToken(token, newToken)); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC104CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Diagnostics; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using DocumentationAnalyzers.Helpers; 12 | using Microsoft.CodeAnalysis; 13 | using Microsoft.CodeAnalysis.CodeActions; 14 | using Microsoft.CodeAnalysis.CodeFixes; 15 | using Microsoft.CodeAnalysis.CSharp.Syntax; 16 | 17 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC104CodeFixProvider))] 18 | [Shared] 19 | internal class DOC104CodeFixProvider : CodeFixProvider 20 | { 21 | public override ImmutableArray FixableDiagnosticIds { get; } 22 | = ImmutableArray.Create(DOC104UseSeeLangword.DiagnosticId); 23 | 24 | public override FixAllProvider GetFixAllProvider() 25 | => CustomFixAllProviders.BatchFixer; 26 | 27 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 28 | { 29 | foreach (var diagnostic in context.Diagnostics) 30 | { 31 | Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)"); 32 | 33 | context.RegisterCodeFix( 34 | CodeAction.Create( 35 | StyleResources.DOC104CodeFix, 36 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 37 | nameof(DOC104CodeFixProvider)), 38 | diagnostic); 39 | } 40 | 41 | return SpecializedTasks.CompletedTask; 42 | } 43 | 44 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 45 | { 46 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 47 | var xmlElement = (XmlElementSyntax)root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true); 48 | 49 | var newXmlElement = XmlSyntaxFactory.EmptyElement(XmlCommentHelper.SeeXmlTag) 50 | .AddAttributes(XmlSyntaxFactory.TextAttribute("langword", xmlElement.Content.ToFullString())) 51 | .WithTriviaFrom(xmlElement); 52 | 53 | return document.WithSyntaxRoot(root.ReplaceNode(xmlElement, newXmlElement)); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC105CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Diagnostics; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using DocumentationAnalyzers.Helpers; 12 | using Microsoft.CodeAnalysis; 13 | using Microsoft.CodeAnalysis.CodeActions; 14 | using Microsoft.CodeAnalysis.CodeFixes; 15 | using Microsoft.CodeAnalysis.CSharp.Syntax; 16 | 17 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC105CodeFixProvider))] 18 | [Shared] 19 | internal class DOC105CodeFixProvider : CodeFixProvider 20 | { 21 | public override ImmutableArray FixableDiagnosticIds { get; } 22 | = ImmutableArray.Create(DOC105UseParamref.DiagnosticId); 23 | 24 | public override FixAllProvider GetFixAllProvider() 25 | => CustomFixAllProviders.BatchFixer; 26 | 27 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 28 | { 29 | foreach (var diagnostic in context.Diagnostics) 30 | { 31 | Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)"); 32 | 33 | context.RegisterCodeFix( 34 | CodeAction.Create( 35 | StyleResources.DOC105CodeFix, 36 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 37 | nameof(DOC105CodeFixProvider)), 38 | diagnostic); 39 | } 40 | 41 | return SpecializedTasks.CompletedTask; 42 | } 43 | 44 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 45 | { 46 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 47 | var xmlElement = (XmlElementSyntax)root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true); 48 | 49 | var newXmlElement = XmlSyntaxFactory.ParamRefElement(xmlElement.Content.ToFullString()).WithTriviaFrom(xmlElement); 50 | 51 | return document.WithSyntaxRoot(root.ReplaceNode(xmlElement, newXmlElement)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC106CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Diagnostics; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using DocumentationAnalyzers.Helpers; 12 | using Microsoft.CodeAnalysis; 13 | using Microsoft.CodeAnalysis.CodeActions; 14 | using Microsoft.CodeAnalysis.CodeFixes; 15 | using Microsoft.CodeAnalysis.CSharp.Syntax; 16 | 17 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC106CodeFixProvider))] 18 | [Shared] 19 | internal class DOC106CodeFixProvider : CodeFixProvider 20 | { 21 | public override ImmutableArray FixableDiagnosticIds { get; } 22 | = ImmutableArray.Create(DOC106UseTypeparamref.DiagnosticId); 23 | 24 | public override FixAllProvider GetFixAllProvider() 25 | => CustomFixAllProviders.BatchFixer; 26 | 27 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 28 | { 29 | foreach (var diagnostic in context.Diagnostics) 30 | { 31 | Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)"); 32 | 33 | context.RegisterCodeFix( 34 | CodeAction.Create( 35 | StyleResources.DOC106CodeFix, 36 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 37 | nameof(DOC106CodeFixProvider)), 38 | diagnostic); 39 | } 40 | 41 | return SpecializedTasks.CompletedTask; 42 | } 43 | 44 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 45 | { 46 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 47 | var xmlElement = (XmlElementSyntax)root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true); 48 | 49 | var newXmlElement = XmlSyntaxFactory.TypeParamRefElement(xmlElement.Content.ToFullString()).WithTriviaFrom(xmlElement); 50 | 51 | return document.WithSyntaxRoot(root.ReplaceNode(xmlElement, newXmlElement)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC107CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Diagnostics; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using DocumentationAnalyzers.Helpers; 12 | using Microsoft.CodeAnalysis; 13 | using Microsoft.CodeAnalysis.CodeActions; 14 | using Microsoft.CodeAnalysis.CodeFixes; 15 | using Microsoft.CodeAnalysis.CSharp; 16 | using Microsoft.CodeAnalysis.CSharp.Syntax; 17 | 18 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC107CodeFixProvider))] 19 | [Shared] 20 | internal class DOC107CodeFixProvider : CodeFixProvider 21 | { 22 | public override ImmutableArray FixableDiagnosticIds { get; } 23 | = ImmutableArray.Create(DOC107UseSeeCref.DiagnosticId); 24 | 25 | public override FixAllProvider GetFixAllProvider() 26 | => CustomFixAllProviders.BatchFixer; 27 | 28 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 29 | { 30 | foreach (var diagnostic in context.Diagnostics) 31 | { 32 | Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)"); 33 | 34 | context.RegisterCodeFix( 35 | CodeAction.Create( 36 | StyleResources.DOC107CodeFix, 37 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 38 | nameof(DOC107CodeFixProvider)), 39 | diagnostic); 40 | } 41 | 42 | return SpecializedTasks.CompletedTask; 43 | } 44 | 45 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 46 | { 47 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 48 | var xmlElement = (XmlElementSyntax)root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true); 49 | 50 | var newXmlElement = XmlSyntaxFactory.EmptyElement(XmlCommentHelper.SeeXmlTag) 51 | .AddAttributes(XmlSyntaxFactory.TextAttribute( 52 | "cref", 53 | SyntaxFactory.Token(SyntaxTriviaList.Empty, SyntaxKind.XmlTextLiteralToken, xmlElement.Content.ToFullString(), xmlElement.Content.ToFullString(), SyntaxTriviaList.Empty))) 54 | .WithTriviaFrom(xmlElement); 55 | 56 | return document.WithSyntaxRoot(root.ReplaceNode(xmlElement, newXmlElement)); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC108CodeFixProvider.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using System.Composition; 8 | using System.Diagnostics; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using DocumentationAnalyzers.Helpers; 12 | using Microsoft.CodeAnalysis; 13 | using Microsoft.CodeAnalysis.CodeActions; 14 | using Microsoft.CodeAnalysis.CodeFixes; 15 | using Microsoft.CodeAnalysis.CSharp.Syntax; 16 | 17 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC108CodeFixProvider))] 18 | [Shared] 19 | internal class DOC108CodeFixProvider : CodeFixProvider 20 | { 21 | public override ImmutableArray FixableDiagnosticIds { get; } 22 | = ImmutableArray.Create(DOC108AvoidEmptyParagraphs.DiagnosticId); 23 | 24 | public override FixAllProvider GetFixAllProvider() 25 | => CustomFixAllProviders.BatchFixer; 26 | 27 | public override Task RegisterCodeFixesAsync(CodeFixContext context) 28 | { 29 | foreach (var diagnostic in context.Diagnostics) 30 | { 31 | Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)"); 32 | 33 | context.RegisterCodeFix( 34 | CodeAction.Create( 35 | StyleResources.DOC108CodeFix, 36 | token => GetTransformedDocumentAsync(context.Document, diagnostic, token), 37 | nameof(DOC108CodeFixProvider)), 38 | diagnostic); 39 | } 40 | 41 | return SpecializedTasks.CompletedTask; 42 | } 43 | 44 | private static async Task GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) 45 | { 46 | SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); 47 | var xmlEmptyElement = (XmlEmptyElementSyntax)root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true); 48 | return document.WithSyntaxRoot(root.RemoveNode(xmlEmptyElement, SyntaxRemoveOptions.KeepExteriorTrivia)); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Internal.ruleset: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Status.Generator/CodeFixStatus.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Status.Generator 5 | { 6 | /// 7 | /// This enum is used to indicate whether or not a code fix is implemented. 8 | /// 9 | public enum CodeFixStatus 10 | { 11 | /// 12 | /// This value indicates, that a code fix is implemented. 13 | /// 14 | Implemented, 15 | 16 | /// 17 | /// This value indicates, that a code fix is not implemented and 18 | /// will not be implemented because it either can't be implemented 19 | /// or a code fix would not be able to fix it rationally. 20 | /// 21 | NotImplemented, 22 | 23 | /// 24 | /// This value indicates, that a code fix is not implemented because 25 | /// no one implemented it yet, or it is not yet decided if a code fix 26 | /// is going to be implemented in the future. 27 | /// 28 | NotYetImplemented, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Status.Generator/DocumentationAnalyzers.Status.Generator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | net472 6 | Exe 7 | 8 | 9 | true 10 | 11 | 12 | 13 | ..\DocumentationAnalyzers.Internal.ruleset 14 | 15 | 16 | 17 | true 18 | ..\..\build\keys\TestingKey.snk 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Status.Generator/FixAllStatus.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Status.Generator 5 | { 6 | /// 7 | /// This enum captures the status of the implementation of a fix all provider. 8 | /// 9 | public enum FixAllStatus 10 | { 11 | /// 12 | /// No fix all provider is implemented for the given code fix. 13 | /// 14 | None, 15 | 16 | /// 17 | /// The fix all provider for this code fix uses a custom optimized implementation. 18 | /// 19 | CustomImplementation, 20 | 21 | /// 22 | /// The fix all capability is provided by the default batch fixer. 23 | /// This implementation might have various problems e.g. bad performance or it might not fix all problems at once. 24 | /// 25 | BatchFixer, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Status.Generator/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Status.Generator 5 | { 6 | using System; 7 | using System.IO; 8 | using System.Linq; 9 | using LibGit2Sharp; 10 | using Microsoft.Build.Locator; 11 | using Newtonsoft.Json; 12 | 13 | /// 14 | /// The starting point of this application. 15 | /// 16 | internal class Program 17 | { 18 | /// 19 | /// The starting point of this application. 20 | /// 21 | /// The command line parameters. 22 | /// Zero if the tool completes successfully; otherwise, a non-zero error code. 23 | internal static int Main(string[] args) 24 | { 25 | if (args.Length < 1) 26 | { 27 | Console.WriteLine("Path to sln file required."); 28 | return 1; 29 | } 30 | 31 | if (!File.Exists(args[0])) 32 | { 33 | Console.WriteLine($"Could not find solution file: {Path.GetFullPath(args[0])}"); 34 | return 1; 35 | } 36 | 37 | MSBuildLocator.RegisterDefaults(); 38 | SolutionReader reader = SolutionReader.CreateAsync(args[0]).Result; 39 | 40 | var diagnostics = reader.GetDiagnosticsAsync().Result; 41 | 42 | diagnostics = diagnostics.Sort((a, b) => a.Id.CompareTo(b.Id)); 43 | 44 | Commit commit; 45 | string commitId; 46 | 47 | using (Repository repository = new Repository(Path.GetDirectoryName(args[0]))) 48 | { 49 | commitId = repository.Head.Tip.Sha; 50 | commit = repository.Head.Tip; 51 | 52 | var output = new 53 | { 54 | diagnostics, 55 | git = new 56 | { 57 | commit.Sha, 58 | commit.Message, 59 | commit.Author, 60 | commit.Committer, 61 | Parents = commit.Parents.Select(x => x.Sha), 62 | }, 63 | }; 64 | 65 | Console.WriteLine(JsonConvert.SerializeObject(output, Formatting.Indented)); 66 | } 67 | 68 | return 0; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Status.Generator/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "DocumentationAnalyzers.Status.Generator": { 4 | "commandName": "Project", 5 | "commandLineArgs": "..\\..\\..\\..\\..\\DocumentationAnalyzers.sln", 6 | "environmentVariables": { 7 | "Configuration": "$(Configuration)" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Status.Generator/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/AnalyzerConfigurationTestsCSharp7.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7 5 | { 6 | public class AnalyzerConfigurationTestsCSharp7 : AnalyzerConfigurationTests 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/DocumentationAnalyzers.Test.CSharp7.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | net46 6 | true 7 | true 8 | 9 | 10 | 11 | ..\DocumentationAnalyzers.Internal.ruleset 12 | 13 | 14 | 15 | true 16 | ..\..\build\keys\TestingKey.snk 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/PortabilityRules/DOC200CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.PortabilityRules 5 | { 6 | using DocumentationAnalyzers.Test.PortabilityRules; 7 | 8 | public class DOC200CSharp7UnitTests : DOC200UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/PortabilityRules/DOC201CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.PortabilityRules 5 | { 6 | using DocumentationAnalyzers.Test.PortabilityRules; 7 | 8 | public class DOC201CSharp7UnitTests : DOC201UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/PortabilityRules/DOC202CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.PortabilityRules 5 | { 6 | using DocumentationAnalyzers.Test.PortabilityRules; 7 | 8 | public class DOC202CSharp7UnitTests : DOC202UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/PortabilityRules/DOC203CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.PortabilityRules 5 | { 6 | using DocumentationAnalyzers.Test.PortabilityRules; 7 | 8 | public class DOC203CSharp7UnitTests : DOC203UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/PortabilityRules/DOC204CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.PortabilityRules 5 | { 6 | using DocumentationAnalyzers.Test.PortabilityRules; 7 | 8 | public class DOC204CSharp7UnitTests : DOC204UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/PortabilityRules/DOC207CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.PortabilityRules 5 | { 6 | using DocumentationAnalyzers.Test.PortabilityRules; 7 | 8 | public class DOC207CSharp7UnitTests : DOC207UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/PortabilityRules/DOC209CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.PortabilityRules 5 | { 6 | using DocumentationAnalyzers.Test.PortabilityRules; 7 | 8 | public class DOC209CSharp7UnitTests : DOC209UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/RefactoringRules/DOC900CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.RefactoringRules 5 | { 6 | using DocumentationAnalyzers.Test.RefactoringRules; 7 | 8 | public class DOC900CSharp7UnitTests : DOC900UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/RefactoringRules/DOC901CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.RefactoringRules 5 | { 6 | using DocumentationAnalyzers.Test.RefactoringRules; 7 | 8 | public class DOC901CSharp7UnitTests : DOC901UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/StyleRules/DOC100CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.StyleRules 5 | { 6 | using DocumentationAnalyzers.Test.StyleRules; 7 | 8 | public class DOC100CSharp7UnitTests : DOC100UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/StyleRules/DOC101CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.StyleRules 5 | { 6 | using DocumentationAnalyzers.Test.StyleRules; 7 | 8 | public class DOC101CSharp7UnitTests : DOC101UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/StyleRules/DOC102CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.StyleRules 5 | { 6 | using DocumentationAnalyzers.Test.StyleRules; 7 | 8 | public class DOC102CSharp7UnitTests : DOC102UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/StyleRules/DOC103CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.StyleRules 5 | { 6 | using DocumentationAnalyzers.Test.StyleRules; 7 | 8 | public class DOC103CSharp7UnitTests : DOC103UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/StyleRules/DOC104CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.StyleRules 5 | { 6 | using DocumentationAnalyzers.Test.StyleRules; 7 | 8 | public class DOC104CSharp7UnitTests : DOC104UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/StyleRules/DOC105CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.StyleRules 5 | { 6 | using DocumentationAnalyzers.Test.StyleRules; 7 | 8 | public class DOC105CSharp7UnitTests : DOC105UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/StyleRules/DOC106CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.StyleRules 5 | { 6 | using DocumentationAnalyzers.Test.StyleRules; 7 | 8 | public class DOC106CSharp7UnitTests : DOC106UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test.CSharp7/StyleRules/DOC107CSharp7UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.CSharp7.StyleRules 5 | { 6 | using DocumentationAnalyzers.Test.StyleRules; 7 | 8 | public class DOC107CSharp7UnitTests : DOC107UnitTests 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/AnalyzerConfigurationTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using Microsoft.CodeAnalysis; 12 | using Microsoft.CodeAnalysis.CodeFixes; 13 | using Microsoft.CodeAnalysis.CSharp; 14 | using Microsoft.CodeAnalysis.Diagnostics; 15 | using Microsoft.CodeAnalysis.Testing; 16 | using Microsoft.CodeAnalysis.Testing.Verifiers; 17 | using Xunit; 18 | 19 | public class AnalyzerConfigurationTests 20 | { 21 | public static IEnumerable AllAnalyzers 22 | { 23 | get 24 | { 25 | foreach (var type in typeof(AnalyzerCategory).Assembly.DefinedTypes) 26 | { 27 | if (type.GetCustomAttributes(typeof(DiagnosticAnalyzerAttribute), true).Any()) 28 | { 29 | yield return new object[] { type }; 30 | } 31 | } 32 | } 33 | } 34 | 35 | [Theory] 36 | [MemberData(nameof(AllAnalyzers))] 37 | public async Task TestEmptySourceAsync(Type analyzerType) 38 | { 39 | await new CSharpTest(analyzerType) 40 | { 41 | TestCode = string.Empty, 42 | }.RunAsync(CancellationToken.None).ConfigureAwait(false); 43 | } 44 | 45 | [Theory] 46 | [MemberData(nameof(AllAnalyzers))] 47 | public void TestHelpLink(Type analyzerType) 48 | { 49 | var analyzer = (DiagnosticAnalyzer)Activator.CreateInstance(analyzerType); 50 | foreach (var diagnostic in analyzer.SupportedDiagnostics) 51 | { 52 | if (diagnostic.DefaultSeverity == DiagnosticSeverity.Hidden && diagnostic.CustomTags.Contains(WellKnownDiagnosticTags.NotConfigurable)) 53 | { 54 | // This diagnostic will never appear in the UI 55 | continue; 56 | } 57 | 58 | string expected = $"https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/{diagnostic.Id}.md"; 59 | Assert.Equal(expected, diagnostic.HelpLinkUri); 60 | } 61 | } 62 | 63 | private class CSharpTest : CodeFixTest 64 | { 65 | private readonly Type _analyzerType; 66 | 67 | public CSharpTest(Type analyzerType) 68 | { 69 | _analyzerType = analyzerType; 70 | } 71 | 72 | public override string Language => LanguageNames.CSharp; 73 | 74 | public override Type SyntaxKindType => typeof(SyntaxKind); 75 | 76 | protected override string DefaultFileExt => "cs"; 77 | 78 | protected override CompilationOptions CreateCompilationOptions() 79 | => new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true); 80 | 81 | protected override ParseOptions CreateParseOptions() 82 | => new CSharpParseOptions(LanguageVersion.CSharp6); 83 | 84 | protected override IEnumerable GetCodeFixProviders() 85 | => new CodeFixProvider[0]; 86 | 87 | protected override IEnumerable GetDiagnosticAnalyzers() 88 | => new[] { (DiagnosticAnalyzer)Activator.CreateInstance(_analyzerType) }; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/AttributeTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using Xunit; 7 | 8 | public class AttributeTests 9 | { 10 | [Fact] 11 | public void TestNoCodeFixAttributeReason() 12 | { 13 | string reason = "Reason"; 14 | var attribute = new NoCodeFixAttribute(reason); 15 | Assert.Same(reason, attribute.Reason); 16 | } 17 | 18 | [Fact] 19 | public void TestWorkItemAttribute() 20 | { 21 | int id = 1; 22 | string issueUri = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/issues/1"; 23 | var attribute = new WorkItemAttribute(id, issueUri); 24 | Assert.Equal(id, attribute.Id); 25 | Assert.Same(issueUri, attribute.Location); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/DocumentationAnalyzers.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | net452 6 | true 7 | true 8 | 9 | 10 | 11 | ..\DocumentationAnalyzers.Internal.ruleset 12 | 13 | 14 | 15 | true 16 | ..\..\build\keys\TestingKey.snk 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/ExportCodeFixProviderAttributeNameTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Reflection; 10 | using DocumentationAnalyzers.Helpers; 11 | using Microsoft.CodeAnalysis; 12 | using Microsoft.CodeAnalysis.CodeFixes; 13 | using Xunit; 14 | 15 | public class ExportCodeFixProviderAttributeNameTest 16 | { 17 | public static IEnumerable CodeFixProviderTypeData 18 | { 19 | get 20 | { 21 | var codeFixProviders = typeof(CustomBatchFixAllProvider) 22 | .Assembly 23 | .GetTypes() 24 | .Where(t => typeof(CodeFixProvider).IsAssignableFrom(t)); 25 | 26 | return codeFixProviders.Select(x => new[] { x }); 27 | } 28 | } 29 | 30 | [Theory] 31 | [MemberData(nameof(CodeFixProviderTypeData))] 32 | public void TestExportCodeFixProviderAttribute(Type codeFixProvider) 33 | { 34 | var exportCodeFixProviderAttribute = codeFixProvider.GetCustomAttributes(false).FirstOrDefault(); 35 | var noCodeFixAttribute = codeFixProvider.GetCustomAttributes(false).FirstOrDefault(); 36 | 37 | if (noCodeFixAttribute != null) 38 | { 39 | Assert.Null(exportCodeFixProviderAttribute); 40 | 41 | return; 42 | } 43 | 44 | Assert.NotNull(exportCodeFixProviderAttribute); 45 | Assert.Equal(codeFixProvider.Name, exportCodeFixProviderAttribute.Name); 46 | Assert.Single(exportCodeFixProviderAttribute.Languages); 47 | Assert.Equal(LanguageNames.CSharp, exportCodeFixProviderAttribute.Languages[0]); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/PortabilityRules/DOC201UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.PortabilityRules 5 | { 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | using Verify = DocumentationAnalyzers.Test.CSharpCodeFixVerifier; 9 | 10 | public class DOC201UnitTests 11 | { 12 | [Fact] 13 | public async Task TestListItemsWithoutDescriptionAsync() 14 | { 15 | var testCode = @" 16 | /// 17 | /// 18 | /// <[|item|]>Item 1 19 | /// <[|item|]>Item 2 20 | /// 21 | /// 22 | class TestClass { } 23 | "; 24 | var fixedCode = @" 25 | /// 26 | /// 27 | /// Item 1 28 | /// Item 2 29 | /// 30 | /// 31 | class TestClass { } 32 | "; 33 | 34 | await Verify.VerifyCodeFixAsync(testCode, fixedCode); 35 | } 36 | 37 | [Fact] 38 | public async Task TestMultilineListItemsWithoutDescriptionAsync() 39 | { 40 | var testCode = @" 41 | /// 42 | /// 43 | /// <[|item|]> 44 | /// Item 1 45 | /// 46 | /// <[|item|]> 47 | /// Item 2 48 | /// 49 | /// 50 | /// 51 | class TestClass { } 52 | "; 53 | var fixedCode = @" 54 | /// 55 | /// 56 | /// 57 | /// Item 1 58 | /// 59 | /// 60 | /// Item 2 61 | /// 62 | /// 63 | /// 64 | class TestClass { } 65 | "; 66 | 67 | await Verify.VerifyCodeFixAsync(testCode, fixedCode); 68 | } 69 | 70 | [Fact] 71 | public async Task TestListItemsWithEmptyDescriptionAsync() 72 | { 73 | var testCode = @" 74 | /// 75 | /// 76 | /// 77 | /// 78 | /// 79 | /// 80 | class TestClass { } 81 | "; 82 | 83 | await Verify.VerifyAnalyzerAsync(testCode); 84 | } 85 | 86 | [Fact] 87 | public async Task TestListItemsWithTermAsync() 88 | { 89 | var testCode = @" 90 | /// 91 | /// 92 | /// Item 1 93 | /// Item 2Description 94 | /// 95 | /// 96 | class TestClass { } 97 | "; 98 | 99 | await Verify.VerifyAnalyzerAsync(testCode); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/PortabilityRules/DOC202UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.PortabilityRules 5 | { 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | using Verify = DocumentationAnalyzers.Test.CSharpCodeFixVerifier; 9 | 10 | public class DOC202UnitTests 11 | { 12 | [Fact] 13 | public async Task TestElementsUsedCorrectlyAsync() 14 | { 15 | var testCode = @" 16 | class TestClass 17 | { 18 | /// 19 | /// Pass in a value. 20 | /// 21 | /// The type of value 22 | /// The value 23 | void Method(int value) 24 | { 25 | } 26 | } 27 | "; 28 | 29 | await Verify.VerifyAnalyzerAsync(testCode); 30 | } 31 | 32 | [Fact] 33 | public async Task TestParamUsedAsParamRefAsync() 34 | { 35 | var testCode = @" 36 | class TestClass 37 | { 38 | /// 39 | /// Pass in a <$$param name=""value""/>. 40 | /// 41 | void Method(int value) 42 | { 43 | } 44 | } 45 | "; 46 | var fixedCode = @" 47 | class TestClass 48 | { 49 | /// 50 | /// Pass in a . 51 | /// 52 | void Method(int value) 53 | { 54 | } 55 | } 56 | "; 57 | 58 | await Verify.VerifyCodeFixAsync(testCode, fixedCode); 59 | } 60 | 61 | [Fact] 62 | public async Task TestTypeParamUsedAsTypeParamRefAsync() 63 | { 64 | var testCode = @" 65 | class TestClass 66 | { 67 | /// 68 | /// Pass in a <$$typeparam name=""T""/>. 69 | /// 70 | void Method() 71 | { 72 | } 73 | } 74 | "; 75 | var fixedCode = @" 76 | class TestClass 77 | { 78 | /// 79 | /// Pass in a . 80 | /// 81 | void Method() 82 | { 83 | } 84 | } 85 | "; 86 | 87 | await Verify.VerifyCodeFixAsync(testCode, fixedCode); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/PortabilityRules/DOC203UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.PortabilityRules 5 | { 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | using Verify = DocumentationAnalyzers.Test.CSharpCodeFixVerifier; 9 | 10 | public class DOC203UnitTests 11 | { 12 | [Fact] 13 | public async Task TestCodeUsedAsExampleAsync() 14 | { 15 | var testCode = @" 16 | class TestClass 17 | { 18 | /// 19 | /// 20 | /// this is some code... 21 | /// 22 | /// 23 | void Method() 24 | { 25 | } 26 | } 27 | "; 28 | 29 | await Verify.VerifyAnalyzerAsync(testCode); 30 | } 31 | 32 | [Fact] 33 | public async Task TestCodeUsedAsInlineWithinParagraphAsync() 34 | { 35 | var testCode = @" 36 | class TestClass 37 | { 38 | /// 39 | /// Executes some <$$code>code. 40 | /// 41 | void Method() 42 | { 43 | } 44 | } 45 | "; 46 | var fixedCode = @" 47 | class TestClass 48 | { 49 | /// 50 | /// Executes some code. 51 | /// 52 | void Method() 53 | { 54 | } 55 | } 56 | "; 57 | 58 | await Verify.VerifyCodeFixAsync(testCode, fixedCode); 59 | } 60 | 61 | [Fact] 62 | public async Task TestCodeUsedAsInlineAsync() 63 | { 64 | var testCode = @" 65 | class TestClass 66 | { 67 | /// 68 | /// Executes some <$$code>code. 69 | /// 70 | void Method() 71 | { 72 | } 73 | } 74 | "; 75 | var fixedCode = @" 76 | class TestClass 77 | { 78 | /// 79 | /// Executes some code. 80 | /// 81 | void Method() 82 | { 83 | } 84 | } 85 | "; 86 | 87 | await Verify.VerifyCodeFixAsync(testCode, fixedCode); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/PortabilityRules/DOC204UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.PortabilityRules 5 | { 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | using Verify = DocumentationAnalyzers.Test.CSharpCodeFixVerifier; 9 | 10 | public class DOC204UnitTests 11 | { 12 | [Fact] 13 | public async Task TestElementsUsedCorrectlyAsync() 14 | { 15 | var testCode = @" 16 | class TestClass 17 | { 18 | /// 19 | /// Pass in a of type . 20 | /// 21 | void Method(int value) 22 | { 23 | } 24 | } 25 | "; 26 | 27 | await Verify.VerifyAnalyzerAsync(testCode); 28 | } 29 | 30 | [Fact] 31 | public async Task TestParamRefUsedAsParamAsync() 32 | { 33 | var testCode = @" 34 | class TestClass 35 | { 36 | /// 37 | /// Pass in a value. 38 | /// 39 | /// <$$paramref name=""value"">The value 40 | void Method(int value) 41 | { 42 | } 43 | } 44 | "; 45 | var fixedCode = @" 46 | class TestClass 47 | { 48 | /// 49 | /// Pass in a value. 50 | /// 51 | /// The value 52 | void Method(int value) 53 | { 54 | } 55 | } 56 | "; 57 | 58 | await Verify.VerifyCodeFixAsync(testCode, fixedCode); 59 | } 60 | 61 | [Fact] 62 | public async Task TestTypeParamUsedAsTypeParamRefAsync() 63 | { 64 | var testCode = @" 65 | class TestClass 66 | { 67 | /// 68 | /// Pass in a value. 69 | /// 70 | /// <$$typeparamref name=""T"">The type of value 71 | void Method() 72 | { 73 | } 74 | } 75 | "; 76 | var fixedCode = @" 77 | class TestClass 78 | { 79 | /// 80 | /// Pass in a value. 81 | /// 82 | /// The type of value 83 | void Method() 84 | { 85 | } 86 | } 87 | "; 88 | 89 | await Verify.VerifyCodeFixAsync(testCode, fixedCode); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/PortabilityRules/DOC207UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.PortabilityRules 5 | { 6 | using System.Collections.Generic; 7 | using System.Threading.Tasks; 8 | using Microsoft.CodeAnalysis.CSharp; 9 | using Xunit; 10 | using Verify = DocumentationAnalyzers.Test.CSharpCodeFixVerifier; 11 | 12 | public class DOC207UnitTests 13 | { 14 | public static IEnumerable Keywords 15 | { 16 | get 17 | { 18 | foreach (var keywordKind in SyntaxFacts.GetKeywordKinds()) 19 | { 20 | yield return new[] { SyntaxFacts.GetText(keywordKind) }; 21 | } 22 | } 23 | } 24 | 25 | [Theory] 26 | [MemberData(nameof(Keywords))] 27 | public async Task TestRecognizedKeywordsAsync(string keyword) 28 | { 29 | var testCode = $@" 30 | /// 31 | /// 32 | /// 33 | /// 34 | class TestClass 35 | {{ 36 | }} 37 | "; 38 | 39 | await Verify.VerifyAnalyzerAsync(testCode); 40 | } 41 | 42 | [Fact] 43 | public async Task TestSpacesNotAllowedAsync() 44 | { 45 | var testCode = @" 46 | /// 47 | /// 48 | /// 49 | /// 50 | /// 51 | /// 52 | class TestClass 53 | { 54 | } 55 | "; 56 | 57 | await Verify.VerifyAnalyzerAsync(testCode); 58 | } 59 | 60 | [Fact] 61 | public async Task TestEscapesAllowedAsync() 62 | { 63 | var testCode = @" 64 | /// 65 | /// 66 | /// 67 | class TestClass 68 | { 69 | } 70 | "; 71 | 72 | await Verify.VerifyAnalyzerAsync(testCode); 73 | } 74 | 75 | [Fact] 76 | public async Task TestEmptyAndFullElementsValidatedAsync() 77 | { 78 | var testCode = @" 79 | /// 80 | /// 81 | /// 82 | /// 83 | class TestClass 84 | { 85 | } 86 | "; 87 | 88 | await Verify.VerifyAnalyzerAsync(testCode); 89 | } 90 | 91 | [Fact] 92 | public async Task TestOtherAttributesIgnoredAsync() 93 | { 94 | var testCode = @" 95 | /// 96 | /// 97 | /// 98 | /// 99 | /// 100 | /// 101 | class TestClass 102 | { 103 | } 104 | "; 105 | 106 | await Verify.VerifyAnalyzerAsync(testCode); 107 | } 108 | 109 | [Fact] 110 | public async Task TestOtherElementsIgnoredAsync() 111 | { 112 | var testCode = @" 113 | /// 114 | /// 115 | /// 116 | /// 117 | class TestClass 118 | { 119 | } 120 | "; 121 | 122 | await Verify.VerifyAnalyzerAsync(testCode); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/PortabilityRules/DOC209UnitTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test.PortabilityRules 5 | { 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | using Verify = DocumentationAnalyzers.Test.CSharpCodeFixVerifier; 9 | 10 | public class DOC209UnitTests 11 | { 12 | [Fact] 13 | public async Task TestAbsoluteUriAsync() 14 | { 15 | var testCode = $@" 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | /// 22 | class TestClass 23 | {{ 24 | }} 25 | "; 26 | 27 | await Verify.VerifyAnalyzerAsync(testCode); 28 | } 29 | 30 | [Fact] 31 | public async Task TestRelativeUriAsync() 32 | { 33 | var testCode = $@" 34 | /// 35 | /// 36 | /// 37 | /// 38 | /// 39 | /// 40 | class TestClass 41 | {{ 42 | }} 43 | "; 44 | 45 | await Verify.VerifyAnalyzerAsync(testCode); 46 | } 47 | 48 | [Fact] 49 | public async Task TestEscapesAllowedAsync() 50 | { 51 | var testCode = @" 52 | /// 53 | /// 54 | /// 55 | class TestClass 56 | { 57 | } 58 | "; 59 | 60 | await Verify.VerifyAnalyzerAsync(testCode); 61 | } 62 | 63 | [Fact] 64 | public async Task TestEmptyAndFullElementsValidatedAsync() 65 | { 66 | var testCode = @" 67 | /// 68 | /// 69 | /// 70 | /// 71 | /// 72 | /// 73 | class TestClass 74 | { 75 | } 76 | "; 77 | 78 | await Verify.VerifyAnalyzerAsync(testCode); 79 | } 80 | 81 | [Fact] 82 | public async Task TestOtherAttributesIgnoredAsync() 83 | { 84 | var testCode = @" 85 | /// 86 | /// 87 | /// 88 | /// 89 | /// 90 | /// 91 | class TestClass 92 | { 93 | } 94 | "; 95 | 96 | await Verify.VerifyAnalyzerAsync(testCode); 97 | } 98 | 99 | [Fact] 100 | public async Task TestOtherElementsIgnoredAsync() 101 | { 102 | var testCode = @" 103 | /// 104 | /// 105 | /// 106 | /// 107 | class TestClass 108 | { 109 | } 110 | "; 111 | 112 | await Verify.VerifyAnalyzerAsync(testCode); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | 8 | [assembly: CLSCompliant(false)] 9 | 10 | // Setting ComVisible to false makes the types in this assembly not visible 11 | // to COM components. If you need to access a type in this assembly from 12 | // COM, set the ComVisible attribute to true on that type. 13 | [assembly: ComVisible(false)] 14 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/PublicApiTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System; 7 | using System.Text; 8 | using DocumentationAnalyzers.Helpers; 9 | using Xunit; 10 | 11 | /// 12 | /// Unit tests related to the public API surface of DocumentationAnalyzers.dll. 13 | /// 14 | public class PublicApiTests 15 | { 16 | /// 17 | /// This test ensures all types in DocumentationAnalyzers.dll are marked internal. 18 | /// 19 | [Fact] 20 | public void TestAllAnalyzerTypesAreInternal() 21 | { 22 | var publicTypes = new StringBuilder(); 23 | foreach (Type type in typeof(AnalyzerCategory).Assembly.ExportedTypes) 24 | { 25 | if (publicTypes.Length > 0) 26 | { 27 | publicTypes.Append(", "); 28 | } 29 | 30 | publicTypes.Append(type.Name); 31 | } 32 | 33 | Assert.Equal(string.Empty, publicTypes.ToString()); 34 | } 35 | 36 | /// 37 | /// This test ensures all types in DocumentationAnalyzers.CodeFixes.dll are marked internal. 38 | /// 39 | [Fact] 40 | public void TestAllCodeFixTypesAreInternal() 41 | { 42 | var publicTypes = new StringBuilder(); 43 | foreach (Type type in typeof(CustomBatchFixAllProvider).Assembly.ExportedTypes) 44 | { 45 | if (publicTypes.Length > 0) 46 | { 47 | publicTypes.Append(", "); 48 | } 49 | 50 | publicTypes.Append(type.Name); 51 | } 52 | 53 | Assert.Equal(string.Empty, publicTypes.ToString()); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/SequentialTestCollection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using Xunit; 7 | 8 | /// 9 | /// Defines a collection for tests which cannot run in parallel with other tests. 10 | /// 11 | [CollectionDefinition(nameof(SequentialTestCollection), DisableParallelization = true)] 12 | internal sealed class SequentialTestCollection 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/CSharpAnalyzerVerifier`1+Test.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Runtime.CompilerServices; 7 | using Microsoft.CodeAnalysis.CSharp.Testing; 8 | using Microsoft.CodeAnalysis.Diagnostics; 9 | using Microsoft.CodeAnalysis.Testing.Verifiers; 10 | 11 | public static partial class CSharpAnalyzerVerifier 12 | where TAnalyzer : DiagnosticAnalyzer, new() 13 | { 14 | public class Test : CSharpAnalyzerTest 15 | { 16 | public Test() 17 | { 18 | RuntimeHelpers.RunClassConstructor(typeof(CSharpVerifierHelper).TypeHandle); 19 | 20 | SolutionTransforms.Add((solution, projectId) => 21 | { 22 | var compilationOptions = solution.GetProject(projectId).CompilationOptions; 23 | compilationOptions = compilationOptions.WithSpecificDiagnosticOptions( 24 | compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings)); 25 | solution = solution.WithProjectCompilationOptions(projectId, compilationOptions); 26 | 27 | return solution; 28 | }); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/CSharpAnalyzerVerifier`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.CSharp.Testing; 10 | using Microsoft.CodeAnalysis.Diagnostics; 11 | using Microsoft.CodeAnalysis.Testing; 12 | using Microsoft.CodeAnalysis.Testing.Verifiers; 13 | 14 | public static partial class CSharpAnalyzerVerifier 15 | where TAnalyzer : DiagnosticAnalyzer, new() 16 | { 17 | /// 18 | public static DiagnosticResult Diagnostic() 19 | => CSharpAnalyzerVerifier.Diagnostic(); 20 | 21 | /// 22 | public static DiagnosticResult Diagnostic(string diagnosticId) 23 | => CSharpAnalyzerVerifier.Diagnostic(diagnosticId); 24 | 25 | /// 26 | public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) 27 | => CSharpAnalyzerVerifier.Diagnostic(descriptor); 28 | 29 | /// 30 | public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) 31 | { 32 | var test = new Test 33 | { 34 | TestCode = source, 35 | }; 36 | 37 | test.ExpectedDiagnostics.AddRange(expected); 38 | await test.RunAsync(CancellationToken.None); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/CSharpCodeFixVerifier`2+Test.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Runtime.CompilerServices; 7 | using Microsoft.CodeAnalysis.CodeFixes; 8 | using Microsoft.CodeAnalysis.CSharp.Testing; 9 | using Microsoft.CodeAnalysis.Diagnostics; 10 | using Microsoft.CodeAnalysis.Testing.Verifiers; 11 | 12 | public static partial class CSharpCodeFixVerifier 13 | where TAnalyzer : DiagnosticAnalyzer, new() 14 | where TCodeFix : CodeFixProvider, new() 15 | { 16 | public class Test : CSharpCodeFixTest 17 | { 18 | public Test() 19 | { 20 | RuntimeHelpers.RunClassConstructor(typeof(CSharpVerifierHelper).TypeHandle); 21 | 22 | SolutionTransforms.Add((solution, projectId) => 23 | { 24 | var compilationOptions = solution.GetProject(projectId).CompilationOptions; 25 | compilationOptions = compilationOptions.WithSpecificDiagnosticOptions( 26 | compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings)); 27 | solution = solution.WithProjectCompilationOptions(projectId, compilationOptions); 28 | 29 | return solution; 30 | }); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.CodeFixes; 10 | using Microsoft.CodeAnalysis.CSharp.Testing; 11 | using Microsoft.CodeAnalysis.Diagnostics; 12 | using Microsoft.CodeAnalysis.Testing; 13 | using Microsoft.CodeAnalysis.Testing.Verifiers; 14 | 15 | public static partial class CSharpCodeFixVerifier 16 | where TAnalyzer : DiagnosticAnalyzer, new() 17 | where TCodeFix : CodeFixProvider, new() 18 | { 19 | /// 20 | public static DiagnosticResult Diagnostic() 21 | => CSharpCodeFixVerifier.Diagnostic(); 22 | 23 | /// 24 | public static DiagnosticResult Diagnostic(string diagnosticId) 25 | => CSharpCodeFixVerifier.Diagnostic(diagnosticId); 26 | 27 | /// 28 | public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) 29 | => CSharpCodeFixVerifier.Diagnostic(descriptor); 30 | 31 | /// 32 | public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) 33 | { 34 | var test = new Test 35 | { 36 | TestCode = source, 37 | }; 38 | 39 | test.ExpectedDiagnostics.AddRange(expected); 40 | await test.RunAsync(CancellationToken.None); 41 | } 42 | 43 | /// 44 | public static async Task VerifyCodeFixAsync(string source, string fixedSource) 45 | => await VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource); 46 | 47 | /// 48 | public static async Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource) 49 | => await VerifyCodeFixAsync(source, new[] { expected }, fixedSource); 50 | 51 | /// 52 | public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource) 53 | { 54 | var test = new Test 55 | { 56 | TestCode = source, 57 | FixedCode = fixedSource, 58 | }; 59 | 60 | test.ExpectedDiagnostics.AddRange(expected); 61 | await test.RunAsync(CancellationToken.None); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1+Test.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Runtime.CompilerServices; 7 | using Microsoft.CodeAnalysis.CodeRefactorings; 8 | using Microsoft.CodeAnalysis.CSharp.Testing; 9 | using Microsoft.CodeAnalysis.Testing.Verifiers; 10 | 11 | public static partial class CSharpCodeRefactoringVerifier 12 | where TCodeRefactoring : CodeRefactoringProvider, new() 13 | { 14 | public class Test : CSharpCodeRefactoringTest 15 | { 16 | public Test() 17 | { 18 | RuntimeHelpers.RunClassConstructor(typeof(CSharpVerifierHelper).TypeHandle); 19 | 20 | SolutionTransforms.Add((solution, projectId) => 21 | { 22 | var compilationOptions = solution.GetProject(projectId).CompilationOptions; 23 | compilationOptions = compilationOptions.WithSpecificDiagnosticOptions( 24 | compilationOptions.SpecificDiagnosticOptions.SetItems(CSharpVerifierHelper.NullableWarnings)); 25 | solution = solution.WithProjectCompilationOptions(projectId, compilationOptions); 26 | 27 | return solution; 28 | }); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.CodeAnalysis.CodeRefactorings; 9 | using Microsoft.CodeAnalysis.Testing; 10 | 11 | public static partial class CSharpCodeRefactoringVerifier 12 | where TCodeRefactoring : CodeRefactoringProvider, new() 13 | { 14 | /// 15 | public static async Task VerifyRefactoringAsync(string source, string fixedSource) 16 | { 17 | await VerifyRefactoringAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource); 18 | } 19 | 20 | /// 21 | public static async Task VerifyRefactoringAsync(string source, DiagnosticResult expected, string fixedSource) 22 | { 23 | await VerifyRefactoringAsync(source, new[] { expected }, fixedSource); 24 | } 25 | 26 | /// 27 | public static async Task VerifyRefactoringAsync(string source, DiagnosticResult[] expected, string fixedSource) 28 | { 29 | var test = new Test 30 | { 31 | TestCode = source, 32 | FixedCode = fixedSource, 33 | }; 34 | 35 | test.ExpectedDiagnostics.AddRange(expected); 36 | await test.RunAsync(CancellationToken.None); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/CSharpVerifierHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System; 7 | using System.Collections.Immutable; 8 | using System.Net; 9 | using Microsoft.CodeAnalysis; 10 | using Microsoft.CodeAnalysis.CSharp; 11 | 12 | internal static class CSharpVerifierHelper 13 | { 14 | static CSharpVerifierHelper() 15 | { 16 | // If we have outdated defaults from the host unit test application targeting an older .NET Framework, use 17 | // more reasonable TLS protocol version for outgoing connections. 18 | if (ServicePointManager.SecurityProtocol == (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls)) 19 | { 20 | ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 21 | } 22 | } 23 | 24 | /// 25 | /// Gets the configuration for diagnostics set by nullable. 26 | /// 27 | /// 28 | /// By default, the compiler reports diagnostics for nullable reference types at 29 | /// , and the analyzer test framework defaults to only validating 30 | /// diagnostics at . This map contains all compiler diagnostic IDs 31 | /// related to nullability mapped to , which is then used to enable all 32 | /// of these warnings for default validation during analyzer and code fix tests. 33 | /// 34 | /// 35 | /// The configuration for diagnostics set by nullable. 36 | /// 37 | internal static ImmutableDictionary NullableWarnings { get; } = GetNullableWarningsFromCompiler(); 38 | 39 | private static ImmutableDictionary GetNullableWarningsFromCompiler() 40 | { 41 | string[] args = { "/warnaserror:nullable" }; 42 | var commandLineArguments = CSharpCommandLineParser.Default.Parse(args, baseDirectory: Environment.CurrentDirectory, sdkDirectory: Environment.CurrentDirectory); 43 | var nullableWarnings = commandLineArguments.CompilationOptions.SpecificDiagnosticOptions; 44 | 45 | // Workaround for https://github.com/dotnet/roslyn/issues/41610 46 | nullableWarnings = nullableWarnings 47 | .SetItem("CS8632", ReportDiagnostic.Error) 48 | .SetItem("CS8669", ReportDiagnostic.Error); 49 | 50 | return nullableWarnings; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1+Test.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Runtime.CompilerServices; 7 | using Microsoft.CodeAnalysis.Diagnostics; 8 | using Microsoft.CodeAnalysis.Testing.Verifiers; 9 | using Microsoft.CodeAnalysis.VisualBasic.Testing; 10 | 11 | public static partial class VisualBasicAnalyzerVerifier 12 | where TAnalyzer : DiagnosticAnalyzer, new() 13 | { 14 | public class Test : VisualBasicAnalyzerTest 15 | { 16 | public Test() 17 | { 18 | RuntimeHelpers.RunClassConstructor(typeof(CSharpVerifierHelper).TypeHandle); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.Diagnostics; 10 | using Microsoft.CodeAnalysis.Testing; 11 | using Microsoft.CodeAnalysis.Testing.Verifiers; 12 | using Microsoft.CodeAnalysis.VisualBasic.Testing; 13 | 14 | public static partial class VisualBasicAnalyzerVerifier 15 | where TAnalyzer : DiagnosticAnalyzer, new() 16 | { 17 | /// 18 | public static DiagnosticResult Diagnostic() 19 | => VisualBasicAnalyzerVerifier.Diagnostic(); 20 | 21 | /// 22 | public static DiagnosticResult Diagnostic(string diagnosticId) 23 | => VisualBasicAnalyzerVerifier.Diagnostic(diagnosticId); 24 | 25 | /// 26 | public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) 27 | => VisualBasicAnalyzerVerifier.Diagnostic(descriptor); 28 | 29 | /// 30 | public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) 31 | { 32 | var test = new Test 33 | { 34 | TestCode = source, 35 | }; 36 | 37 | test.ExpectedDiagnostics.AddRange(expected); 38 | await test.RunAsync(CancellationToken.None); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2+Test.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Runtime.CompilerServices; 7 | using Microsoft.CodeAnalysis.CodeFixes; 8 | using Microsoft.CodeAnalysis.Diagnostics; 9 | using Microsoft.CodeAnalysis.Testing.Verifiers; 10 | using Microsoft.CodeAnalysis.VisualBasic.Testing; 11 | 12 | public static partial class VisualBasicCodeFixVerifier 13 | where TAnalyzer : DiagnosticAnalyzer, new() 14 | where TCodeFix : CodeFixProvider, new() 15 | { 16 | public class Test : VisualBasicCodeFixTest 17 | { 18 | public Test() 19 | { 20 | RuntimeHelpers.RunClassConstructor(typeof(CSharpVerifierHelper).TypeHandle); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.CodeFixes; 10 | using Microsoft.CodeAnalysis.Diagnostics; 11 | using Microsoft.CodeAnalysis.Testing; 12 | using Microsoft.CodeAnalysis.Testing.Verifiers; 13 | using Microsoft.CodeAnalysis.VisualBasic.Testing; 14 | 15 | public static partial class VisualBasicCodeFixVerifier 16 | where TAnalyzer : DiagnosticAnalyzer, new() 17 | where TCodeFix : CodeFixProvider, new() 18 | { 19 | /// 20 | public static DiagnosticResult Diagnostic() 21 | => VisualBasicCodeFixVerifier.Diagnostic(); 22 | 23 | /// 24 | public static DiagnosticResult Diagnostic(string diagnosticId) 25 | => VisualBasicCodeFixVerifier.Diagnostic(diagnosticId); 26 | 27 | /// 28 | public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) 29 | => VisualBasicCodeFixVerifier.Diagnostic(descriptor); 30 | 31 | /// 32 | public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) 33 | { 34 | var test = new Test 35 | { 36 | TestCode = source, 37 | }; 38 | 39 | test.ExpectedDiagnostics.AddRange(expected); 40 | await test.RunAsync(CancellationToken.None); 41 | } 42 | 43 | /// 44 | public static async Task VerifyCodeFixAsync(string source, string fixedSource) 45 | => await VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource); 46 | 47 | /// 48 | public static async Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource) 49 | => await VerifyCodeFixAsync(source, new[] { expected }, fixedSource); 50 | 51 | /// 52 | public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource) 53 | { 54 | var test = new Test 55 | { 56 | TestCode = source, 57 | FixedCode = fixedSource, 58 | }; 59 | 60 | test.ExpectedDiagnostics.AddRange(expected); 61 | await test.RunAsync(CancellationToken.None); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/VisualBasicCodeRefactoringVerifier`1+Test.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Runtime.CompilerServices; 7 | using Microsoft.CodeAnalysis.CodeRefactorings; 8 | using Microsoft.CodeAnalysis.Testing.Verifiers; 9 | using Microsoft.CodeAnalysis.VisualBasic.Testing; 10 | 11 | public static partial class VisualBasicCodeRefactoringVerifier 12 | where TCodeRefactoring : CodeRefactoringProvider, new() 13 | { 14 | public class Test : VisualBasicCodeRefactoringTest 15 | { 16 | public Test() 17 | { 18 | RuntimeHelpers.RunClassConstructor(typeof(CSharpVerifierHelper).TypeHandle); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/Verifiers/VisualBasicCodeRefactoringVerifier`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Microsoft.CodeAnalysis.CodeRefactorings; 9 | using Microsoft.CodeAnalysis.Testing; 10 | 11 | public static partial class VisualBasicCodeRefactoringVerifier 12 | where TCodeRefactoring : CodeRefactoringProvider, new() 13 | { 14 | /// 15 | public static async Task VerifyRefactoringAsync(string source, string fixedSource) 16 | { 17 | await VerifyRefactoringAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource); 18 | } 19 | 20 | /// 21 | public static async Task VerifyRefactoringAsync(string source, DiagnosticResult expected, string fixedSource) 22 | { 23 | await VerifyRefactoringAsync(source, new[] { expected }, fixedSource); 24 | } 25 | 26 | /// 27 | public static async Task VerifyRefactoringAsync(string source, DiagnosticResult[] expected, string fixedSource) 28 | { 29 | var test = new Test 30 | { 31 | TestCode = source, 32 | FixedCode = fixedSource, 33 | }; 34 | 35 | test.ExpectedDiagnostics.AddRange(expected); 36 | await test.RunAsync(CancellationToken.None); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Test/WorkItemAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Test 5 | { 6 | using System; 7 | 8 | /// 9 | /// Used to tag test methods or types which are created for a given work item. 10 | /// 11 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] 12 | public sealed class WorkItemAttribute : Attribute 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// The ID of the issue in the original tracker where the work item was first reported. This 18 | /// could be a GitHub issue or pull request number, or the number of a Microsoft-internal bug. 19 | /// The URI where the work item can be viewed. This is a link to work item 20 | /// in the original source. 21 | public WorkItemAttribute(int id, string issueUri) 22 | { 23 | Id = id; 24 | Location = issueUri; 25 | } 26 | 27 | public int Id 28 | { 29 | get; 30 | } 31 | 32 | public string Location 33 | { 34 | get; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Vsix/DocumentationAnalyzers.Vsix.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | net452 7 | DocumentationAnalyzers 8 | DocumentationAnalyzers.Vsix 9 | 10 | 11 | 12 | true 13 | false 14 | false 15 | false 16 | true 17 | false 18 | Roslyn 19 | 20 | 21 | 22 | 23 | False 24 | 25 | 26 | 27 | ..\DocumentationAnalyzers.Internal.ruleset 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | <_ReferenceCopyLocalBinaries Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)' != '.pdb'" /> 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Vsix/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | using Microsoft.VisualStudio.Shell; 5 | 6 | [assembly: ProvideCodeBase(CodeBase = "CommonMark.dll")] 7 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Vsix/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Visual Studio Extension": { 4 | "executablePath": "$(DevEnvDir)devenv.exe", 5 | "commandLineArgs": "/rootsuffix $(VSSDKTargetPlatformRegRootSuffix) /log" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers.Vsix/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Documentation Analyzers 6 | An implementation of .NET documentation rules using Roslyn analyzers and code fixes 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/AnalyzerCategory.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers 5 | { 6 | /// 7 | /// Class defining the analyzer category constants. 8 | /// 9 | internal static class AnalyzerCategory 10 | { 11 | /// 12 | /// Category definition for style rules. 13 | /// 14 | public const string StyleRules = nameof(DocumentationAnalyzers) + "." + nameof(StyleRules); 15 | 16 | /// 17 | /// Category definition for portability rules. 18 | /// 19 | public const string PortabilityRules = nameof(DocumentationAnalyzers) + "." + nameof(PortabilityRules); 20 | 21 | /// 22 | /// Category definition for refactorings. 23 | /// 24 | public const string Refactorings = nameof(DocumentationAnalyzers) + "." + nameof(Refactorings); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/AnalyzerConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers 5 | { 6 | using System.Diagnostics.CodeAnalysis; 7 | using Microsoft.CodeAnalysis; 8 | 9 | internal static class AnalyzerConstants 10 | { 11 | static AnalyzerConstants() 12 | { 13 | #if DEBUG 14 | // In DEBUG builds, the tests are enabled to simplify development and testing. 15 | DisabledNoTests = true; 16 | #else 17 | DisabledNoTests = false; 18 | #endif 19 | } 20 | 21 | /// 22 | /// Gets a reference value which can be passed to 23 | /// 24 | /// to disable a diagnostic which is currently untested. 25 | /// 26 | /// 27 | /// A reference value which can be passed to 28 | /// 29 | /// to disable a diagnostic which is currently untested. 30 | /// 31 | [ExcludeFromCodeCoverage] 32 | [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:Property summary documentation should match accessors.", Justification = "This property behaves more like an opaque value than a Boolean.")] 33 | internal static bool DisabledNoTests { get; } 34 | 35 | /// 36 | /// Gets a reference value which can be passed to 37 | /// 38 | /// to indicate that the diagnostic should be enabled by default. 39 | /// 40 | /// 41 | /// A reference value which can be passed to 42 | /// 43 | /// to indicate that the diagnostic should be enabled by default. 44 | /// 45 | [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:Property summary documentation should match accessors.", Justification = "This property behaves more like an opaque value than a Boolean.")] 46 | internal static bool EnabledByDefault => true; 47 | 48 | /// 49 | /// Gets a reference value which can be passed to 50 | /// 51 | /// to indicate that the diagnostic should be disabled by default. 52 | /// 53 | /// 54 | /// A reference value which can be passed to 55 | /// 56 | /// to indicate that the diagnostic should be disabled by default. 57 | /// 58 | [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:Property summary documentation should match accessors.", Justification = "This property behaves more like an opaque value than a Boolean.")] 59 | internal static bool DisabledByDefault => false; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/DocumentationAnalyzers.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | netstandard1.1;net452 6 | 7 | 8 | 9 | 10 | 11 | portable-net45+win8 12 | 13 | 14 | 15 | 16 | 17 | ..\DocumentationAnalyzers.ruleset 18 | 19 | 20 | 21 | true 22 | ..\..\build\keys\DocumentationAnalyzers.snk 23 | ..\..\build\keys\DocumentationAnalyzers.dev.snk 24 | 25 | 26 | 27 | $(DefineConstants);DEVELOPMENT_KEY 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/ExcludeFromCodeCoverageAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | #if NETSTANDARD1_1 5 | 6 | namespace System.Diagnostics.CodeAnalysis 7 | { 8 | [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)] 9 | internal sealed class ExcludeFromCodeCoverageAttribute : Attribute 10 | { 11 | } 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/Helpers/SpacingExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Helpers 5 | { 6 | using System.Linq; 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp; 9 | 10 | internal static class SpacingExtensions 11 | { 12 | public static bool IsMissingOrDefault(this SyntaxToken token) 13 | { 14 | return token.IsKind(SyntaxKind.None) 15 | || token.IsMissing; 16 | } 17 | 18 | public static SyntaxToken WithoutLeadingWhitespace(this SyntaxToken token, bool removeEndOfLineTrivia = false) 19 | { 20 | if (!token.HasLeadingTrivia) 21 | { 22 | return token; 23 | } 24 | 25 | return token.WithLeadingTrivia(token.LeadingTrivia.WithoutWhitespace(removeEndOfLineTrivia)); 26 | } 27 | 28 | public static SyntaxTriviaList WithoutWhitespace(this SyntaxTriviaList syntaxTriviaList, bool removeEndOfLineTrivia = false) 29 | { 30 | if (syntaxTriviaList.Count == 0) 31 | { 32 | return syntaxTriviaList; 33 | } 34 | 35 | var trivia = syntaxTriviaList.Where(i => !i.IsKind(SyntaxKind.WhitespaceTrivia)); 36 | if (removeEndOfLineTrivia) 37 | { 38 | trivia = trivia.Where(i => !i.IsKind(SyntaxKind.EndOfLineTrivia)); 39 | } 40 | 41 | return SyntaxFactory.TriviaList(trivia); 42 | } 43 | 44 | /// 45 | /// Removes the leading and trailing trivia associated with a syntax token. 46 | /// 47 | /// The syntax token to remove trivia from. 48 | /// A copy of the input syntax token with leading and trailing trivia removed. 49 | public static SyntaxToken WithoutTrivia(this SyntaxToken token) 50 | { 51 | return token.WithLeadingTrivia(default(SyntaxTriviaList)).WithTrailingTrivia(default(SyntaxTriviaList)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/Helpers/SpecializedTasks.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Helpers 5 | { 6 | using System.Threading.Tasks; 7 | 8 | internal static class SpecializedTasks 9 | { 10 | internal static Task CompletedTask { get; } = Task.FromResult(default(VoidResult)); 11 | 12 | private struct VoidResult 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/Helpers/SymbolExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Helpers 5 | { 6 | using System; 7 | using System.Linq; 8 | using Microsoft.CodeAnalysis; 9 | 10 | internal static class SymbolExtensions 11 | { 12 | /// 13 | /// Determines if a symbol has a parameter with a given name. 14 | /// 15 | /// The symbol. 16 | /// The name of the parameter. 17 | /// The comparer to use for symbol names. 18 | /// if a parameter with the name is accessible in the 19 | /// context of the specified ; otherwise, . 20 | public static bool HasAnyParameter(this ISymbol symbol, string name, StringComparer comparer) 21 | { 22 | if (symbol is IMethodSymbol methodSymbol) 23 | { 24 | return methodSymbol.Parameters.Any(parameter => comparer.Equals(parameter.Name, name)); 25 | } 26 | 27 | return false; 28 | } 29 | 30 | /// 31 | /// Determines if a symbol has a type parameter with a given name. 32 | /// 33 | /// The symbol. 34 | /// The name of the type parameter. 35 | /// The comparer to use for symbol names. 36 | /// if a type parameter with the name is accessible in 37 | /// the context of the specified ; otherwise, . 38 | public static bool HasAnyTypeParameter(this ISymbol symbol, string name, StringComparer comparer) 39 | { 40 | for (var currentSymbol = symbol; currentSymbol != null; currentSymbol = currentSymbol.ContainingSymbol) 41 | { 42 | switch (currentSymbol) 43 | { 44 | case INamedTypeSymbol namedType: 45 | if (namedType.TypeParameters.Any(parameter => comparer.Equals(parameter.Name, name))) 46 | { 47 | return true; 48 | } 49 | 50 | break; 51 | 52 | case IMethodSymbol method: 53 | if (method.TypeParameters.Any(parameter => comparer.Equals(parameter.Name, name))) 54 | { 55 | return true; 56 | } 57 | 58 | break; 59 | } 60 | } 61 | 62 | return false; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/Helpers/SyntaxNodeExtensionsEx.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.Helpers 5 | { 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp; 8 | 9 | internal static class SyntaxNodeExtensionsEx 10 | { 11 | public static bool IsSymbolDeclaration(this SyntaxNode node) 12 | { 13 | switch (node.Kind()) 14 | { 15 | case SyntaxKind.ClassDeclaration: 16 | case SyntaxKind.ConstructorDeclaration: 17 | case SyntaxKind.ConversionOperatorDeclaration: 18 | case SyntaxKind.DelegateDeclaration: 19 | case SyntaxKind.DestructorDeclaration: 20 | case SyntaxKind.EnumDeclaration: 21 | case SyntaxKind.EnumMemberDeclaration: 22 | case SyntaxKind.EventDeclaration: 23 | case SyntaxKind.EventFieldDeclaration: 24 | case SyntaxKind.FieldDeclaration: 25 | case SyntaxKind.IndexerDeclaration: 26 | case SyntaxKind.InterfaceDeclaration: 27 | case SyntaxKind.MethodDeclaration: 28 | case SyntaxKind.NamespaceDeclaration: 29 | case SyntaxKind.OperatorDeclaration: 30 | case SyntaxKind.PropertyDeclaration: 31 | case SyntaxKind.StructDeclaration: 32 | return true; 33 | 34 | default: 35 | return false; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/NoCodeFixAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers 5 | { 6 | using System; 7 | using Microsoft.CodeAnalysis.Diagnostics; 8 | 9 | /// 10 | /// This attribute is applied to s for which no code fix is currently planned. 11 | /// 12 | /// 13 | /// There are several reasons an analyzer does not have a code fix, including but not limited to the 14 | /// following: 15 | /// 16 | /// Visual Studio provides a built-in code fix. 17 | /// A code fix could not provide a useful solution. 18 | /// 19 | /// The should be provided. 20 | /// 21 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] 22 | internal sealed class NoCodeFixAttribute : System.Attribute 23 | { 24 | /// 25 | /// Initializes a new instance of the class. 26 | /// 27 | /// The reason why the does not have a code fix. 28 | public NoCodeFixAttribute(string reason) 29 | { 30 | Reason = reason; 31 | } 32 | 33 | /// 34 | /// Gets the reason why the does not have a code fix. 35 | /// 36 | /// 37 | /// The reason why the does not have a code fix. 38 | /// 39 | public string Reason 40 | { 41 | get; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/PortabilityRules/DOC200UseXmlDocumentationSyntax.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.PortabilityRules 5 | { 6 | using System.Collections.Immutable; 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp; 9 | using Microsoft.CodeAnalysis.CSharp.Syntax; 10 | using Microsoft.CodeAnalysis.Diagnostics; 11 | 12 | /// 13 | /// Use XML documentation syntax. 14 | /// 15 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 16 | internal class DOC200UseXmlDocumentationSyntax : DiagnosticAnalyzer 17 | { 18 | /// 19 | /// The ID for diagnostics produced by the analyzer. 20 | /// 21 | public const string DiagnosticId = "DOC200"; 22 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC200.md"; 23 | 24 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(PortabilityResources.DOC200Title), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 25 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(PortabilityResources.DOC200MessageFormat), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 26 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(PortabilityResources.DOC200Description), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 27 | 28 | private static readonly DiagnosticDescriptor Descriptor = 29 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.PortabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 30 | 31 | /// 32 | public override ImmutableArray SupportedDiagnostics { get; } 33 | = ImmutableArray.Create(Descriptor); 34 | 35 | public override void Initialize(AnalysisContext context) 36 | { 37 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 38 | context.EnableConcurrentExecution(); 39 | 40 | context.RegisterSyntaxNodeAction(HandleXmlElementSyntax, SyntaxKind.XmlElement); 41 | } 42 | 43 | private static void HandleXmlElementSyntax(SyntaxNodeAnalysisContext context) 44 | { 45 | var xmlElementSyntax = (XmlElementSyntax)context.Node; 46 | var name = xmlElementSyntax.StartTag?.Name; 47 | if (name is null || name.Prefix != null) 48 | { 49 | return; 50 | } 51 | 52 | switch (name.LocalName.ValueText) 53 | { 54 | case "p": 55 | case "pre": 56 | case "tt": 57 | case "ol": 58 | case "ul": 59 | break; 60 | 61 | default: 62 | return; 63 | } 64 | 65 | context.ReportDiagnostic(Diagnostic.Create(Descriptor, name.LocalName.GetLocation())); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/PortabilityRules/DOC202UseSectionElementsCorrectly.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.PortabilityRules 5 | { 6 | using System.Collections.Immutable; 7 | using DocumentationAnalyzers.Helpers; 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.CSharp; 10 | using Microsoft.CodeAnalysis.CSharp.Syntax; 11 | using Microsoft.CodeAnalysis.Diagnostics; 12 | 13 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 14 | internal class DOC202UseSectionElementsCorrectly : DiagnosticAnalyzer 15 | { 16 | /// 17 | /// The ID for diagnostics produced by the analyzer. 18 | /// 19 | public const string DiagnosticId = "DOC202"; 20 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC202.md"; 21 | 22 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(PortabilityResources.DOC202Title), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 23 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(PortabilityResources.DOC202MessageFormat), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 24 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(PortabilityResources.DOC202Description), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 25 | 26 | private static readonly DiagnosticDescriptor Descriptor = 27 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.PortabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 28 | 29 | /// 30 | public override ImmutableArray SupportedDiagnostics { get; } 31 | = ImmutableArray.Create(Descriptor); 32 | 33 | public override void Initialize(AnalysisContext context) 34 | { 35 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 36 | context.EnableConcurrentExecution(); 37 | 38 | context.RegisterSyntaxNodeAction(HandleXmlNodeSyntax, SyntaxKind.XmlElement, SyntaxKind.XmlEmptyElement); 39 | } 40 | 41 | private static void HandleXmlNodeSyntax(SyntaxNodeAnalysisContext context) 42 | { 43 | var xmlNodeSyntax = (XmlNodeSyntax)context.Node; 44 | if (xmlNodeSyntax.Parent.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia) 45 | || xmlNodeSyntax.Parent.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia)) 46 | { 47 | // Element is used as a section element 48 | return; 49 | } 50 | 51 | var name = xmlNodeSyntax.GetName(); 52 | if (name is null || name.Prefix != null) 53 | { 54 | return; 55 | } 56 | 57 | switch (name.LocalName.ValueText) 58 | { 59 | case XmlCommentHelper.ParamXmlTag: 60 | case XmlCommentHelper.TypeParamXmlTag: 61 | break; 62 | 63 | default: 64 | return; 65 | } 66 | 67 | context.ReportDiagnostic(Diagnostic.Create(Descriptor, name.LocalName.GetLocation())); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/PortabilityRules/DOC204UseInlineElementsCorrectly.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.PortabilityRules 5 | { 6 | using System.Collections.Immutable; 7 | using DocumentationAnalyzers.Helpers; 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.CSharp; 10 | using Microsoft.CodeAnalysis.CSharp.Syntax; 11 | using Microsoft.CodeAnalysis.Diagnostics; 12 | 13 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 14 | internal class DOC204UseInlineElementsCorrectly : DiagnosticAnalyzer 15 | { 16 | /// 17 | /// The ID for diagnostics produced by the analyzer. 18 | /// 19 | public const string DiagnosticId = "DOC204"; 20 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC204.md"; 21 | 22 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(PortabilityResources.DOC204Title), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 23 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(PortabilityResources.DOC204MessageFormat), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 24 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(PortabilityResources.DOC204Description), PortabilityResources.ResourceManager, typeof(PortabilityResources)); 25 | 26 | private static readonly DiagnosticDescriptor Descriptor = 27 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.PortabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 28 | 29 | /// 30 | public override ImmutableArray SupportedDiagnostics { get; } 31 | = ImmutableArray.Create(Descriptor); 32 | 33 | public override void Initialize(AnalysisContext context) 34 | { 35 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 36 | context.EnableConcurrentExecution(); 37 | 38 | context.RegisterSyntaxNodeAction(HandleXmlNodeSyntax, SyntaxKind.XmlElement, SyntaxKind.XmlEmptyElement); 39 | } 40 | 41 | private static void HandleXmlNodeSyntax(SyntaxNodeAnalysisContext context) 42 | { 43 | var xmlNodeSyntax = (XmlNodeSyntax)context.Node; 44 | if (!xmlNodeSyntax.Parent.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia) 45 | && !xmlNodeSyntax.Parent.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia)) 46 | { 47 | // Element is not used as a section element 48 | return; 49 | } 50 | 51 | var name = xmlNodeSyntax.GetName(); 52 | if (name is null || name.Prefix != null) 53 | { 54 | return; 55 | } 56 | 57 | switch (name.LocalName.ValueText) 58 | { 59 | case XmlCommentHelper.ParamRefXmlTag: 60 | case XmlCommentHelper.TypeParamRefXmlTag: 61 | break; 62 | 63 | default: 64 | return; 65 | } 66 | 67 | context.ReportDiagnostic(Diagnostic.Create(Descriptor, name.LocalName.GetLocation())); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | 8 | // General Information about an assembly is controlled through the following 9 | // set of attributes. Change these attribute values to modify the information 10 | // associated with an assembly. 11 | [assembly: CLSCompliant(false)] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | #if DEVELOPMENT_KEY 19 | [assembly: InternalsVisibleTo("DocumentationAnalyzers.CodeFixes, PublicKey=0024000004800000940000000602000000240000525341310004000001000100653fc78bb91f5f8741576d365ee395903ae2afe63f50c1fd5486729abb8fdd2815a95867090fc2e22d17a90c3fe35ec57ad06277427128d628ccd7b7c42fb9369bba28b2b7ca642b9d6231b5f0d984abbd65a780145e5efc9265fe0f4df9468e0e87fb4eb3f6125bac24aad003d97c1fe25ab65000ddbf7aabd744179169c1a2")] 20 | #else 21 | [assembly: InternalsVisibleTo("DocumentationAnalyzers.CodeFixes, PublicKey=00240000048000009400000006020000002400005253413100040000010001002164ae5e4cbf74e61559320713d2ada25842139fddf8665b1733e838ea1020d3df0569bb6b56e473173c3e9310f7600fb500fb93a56477eb94c0851c0196e9ea170b7b06d105c8ec15a1108e871c5daf738f8bcbb2a41d61a54a698c322d2fa0cf1cbc8a737c016d60f5e2a9a00bd59d73015bc681f54747ea1c73e1dbe1f4c7")] 22 | #endif 23 | [assembly: InternalsVisibleTo("DocumentationAnalyzers.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001004d394e527140f84e656e715fc026e74b57657f47ff20636a0d90719bd0fd86b49ccfe3feb0a486b08b994bf8d68ead40ce4a993019c701b4d52c4c86ed88491edae914154b238c8378736b87529fd91502426263242fc5b800ee7a25a8a34f838f2dd1d20a483ccdfa0f6e1f08afb0d650d90b024ab129c1b840189d27b845c8")] 24 | [assembly: InternalsVisibleTo("DocumentationAnalyzers.Test.CSharp7, PublicKey=00240000048000009400000006020000002400005253413100040000010001004d394e527140f84e656e715fc026e74b57657f47ff20636a0d90719bd0fd86b49ccfe3feb0a486b08b994bf8d68ead40ce4a993019c701b4d52c4c86ed88491edae914154b238c8378736b87529fd91502426263242fc5b800ee7a25a8a34f838f2dd1d20a483ccdfa0f6e1f08afb0d650d90b024ab129c1b840189d27b845c8")] 25 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/StyleRules/DOC100PlaceTextInParagraphs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using DocumentationAnalyzers.Helpers; 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.CSharp.Syntax; 10 | using Microsoft.CodeAnalysis.Diagnostics; 11 | 12 | /// 13 | /// Place text in paragraphs. 14 | /// 15 | /// 16 | /// A violation of this rule occurs when a <remarks> or <note> documentation element contains 17 | /// content which is not wrapped in a block-level element. 18 | /// 19 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 20 | internal class DOC100PlaceTextInParagraphs : BlockLevelDocumentationAnalyzerBase 21 | { 22 | /// 23 | /// The ID for diagnostics produced by the analyzer. 24 | /// 25 | public const string DiagnosticId = "DOC100"; 26 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC100.md"; 27 | 28 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(StyleResources.DOC100Title), StyleResources.ResourceManager, typeof(StyleResources)); 29 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(StyleResources.DOC100MessageFormat), StyleResources.ResourceManager, typeof(StyleResources)); 30 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(StyleResources.DOC100Description), StyleResources.ResourceManager, typeof(StyleResources)); 31 | 32 | private static readonly DiagnosticDescriptor Descriptor = 33 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.StyleRules, DiagnosticSeverity.Info, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 34 | 35 | private static readonly ImmutableArray SupportedDiagnosticsValue = 36 | ImmutableArray.Create(Descriptor); 37 | 38 | /// 39 | public override ImmutableArray SupportedDiagnostics 40 | { 41 | get 42 | { 43 | return SupportedDiagnosticsValue; 44 | } 45 | } 46 | 47 | /// 48 | protected override bool ElementRequiresBlockContent(XmlElementSyntax element, SemanticModel semanticModel) 49 | { 50 | var name = element.StartTag?.Name; 51 | if (name == null || name.LocalName.IsMissing || name.LocalName == default) 52 | { 53 | // unrecognized 54 | return false; 55 | } 56 | 57 | if (name.Prefix != null) 58 | { 59 | // not a standard element 60 | return false; 61 | } 62 | 63 | switch (name.LocalName.ValueText) 64 | { 65 | case XmlCommentHelper.RemarksXmlTag: 66 | case XmlCommentHelper.NoteXmlTag: 67 | return true; 68 | 69 | default: 70 | return false; 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/StyleRules/DOC103UseUnicodeCharacters.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp; 9 | using Microsoft.CodeAnalysis.CSharp.Syntax; 10 | using Microsoft.CodeAnalysis.Diagnostics; 11 | 12 | /// 13 | /// Use Unicode characters. 14 | /// 15 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 16 | internal class DOC103UseUnicodeCharacters : DiagnosticAnalyzer 17 | { 18 | /// 19 | /// The ID for diagnostics produced by the analyzer. 20 | /// 21 | public const string DiagnosticId = "DOC103"; 22 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC103.md"; 23 | 24 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(StyleResources.DOC103Title), StyleResources.ResourceManager, typeof(StyleResources)); 25 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(StyleResources.DOC103MessageFormat), StyleResources.ResourceManager, typeof(StyleResources)); 26 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(StyleResources.DOC103Description), StyleResources.ResourceManager, typeof(StyleResources)); 27 | 28 | private static readonly DiagnosticDescriptor Descriptor = 29 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.StyleRules, DiagnosticSeverity.Info, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 30 | 31 | /// 32 | public override ImmutableArray SupportedDiagnostics { get; } 33 | = ImmutableArray.Create(Descriptor); 34 | 35 | public override void Initialize(AnalysisContext context) 36 | { 37 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 38 | context.EnableConcurrentExecution(); 39 | 40 | context.RegisterSyntaxNodeAction(HandleXmlElementSyntax, SyntaxKind.XmlText); 41 | } 42 | 43 | private static void HandleXmlElementSyntax(SyntaxNodeAnalysisContext context) 44 | { 45 | var xmlText = (XmlTextSyntax)context.Node; 46 | foreach (var token in xmlText.TextTokens) 47 | { 48 | if (!token.IsKind(SyntaxKind.XmlEntityLiteralToken)) 49 | { 50 | continue; 51 | } 52 | 53 | switch (token.ValueText) 54 | { 55 | // Characters which are often XML-escaped unnecessarily 56 | case "'": 57 | case "\"": 58 | context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation())); 59 | break; 60 | 61 | default: 62 | continue; 63 | } 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/StyleRules/DOC104UseSeeLangword.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp.Syntax; 9 | using Microsoft.CodeAnalysis.Diagnostics; 10 | 11 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 12 | internal class DOC104UseSeeLangword : InlineCodeAnalyzerBase 13 | { 14 | /// 15 | /// The ID for diagnostics produced by the analyzer. 16 | /// 17 | public const string DiagnosticId = "DOC104"; 18 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC104.md"; 19 | 20 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(StyleResources.DOC104Title), StyleResources.ResourceManager, typeof(StyleResources)); 21 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(StyleResources.DOC104MessageFormat), StyleResources.ResourceManager, typeof(StyleResources)); 22 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(StyleResources.DOC104Description), StyleResources.ResourceManager, typeof(StyleResources)); 23 | 24 | private static readonly DiagnosticDescriptor Descriptor = 25 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.StyleRules, DiagnosticSeverity.Info, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 26 | 27 | /// 28 | public override ImmutableArray SupportedDiagnostics { get; } 29 | = ImmutableArray.Create(Descriptor); 30 | 31 | protected override void HandleInlineCodeElement(ref SyntaxNodeAnalysisContext context, XmlElementSyntax xmlElement) 32 | { 33 | // This rule will only apply if the content is a single XmlTextSyntax containing a single 34 | // XmlTextLiteralToken token 35 | if (xmlElement.Content.Count != 1) 36 | { 37 | return; 38 | } 39 | 40 | if (!(xmlElement.Content[0] is XmlTextSyntax xmlText)) 41 | { 42 | return; 43 | } 44 | 45 | if (xmlText.TextTokens.Count != 1) 46 | { 47 | return; 48 | } 49 | 50 | switch (xmlText.TextTokens[0].ValueText) 51 | { 52 | case "null": 53 | case "static": 54 | case "virtual": 55 | case "true": 56 | case "false": 57 | case "abstract": 58 | case "sealed": 59 | case "async": 60 | case "await": 61 | break; 62 | 63 | default: 64 | return; 65 | } 66 | 67 | context.ReportDiagnostic(Diagnostic.Create(Descriptor, xmlElement.GetLocation())); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/StyleRules/DOC105UseParamref.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System; 7 | using System.Collections.Immutable; 8 | using DocumentationAnalyzers.Helpers; 9 | using Microsoft.CodeAnalysis; 10 | using Microsoft.CodeAnalysis.CSharp.Syntax; 11 | using Microsoft.CodeAnalysis.Diagnostics; 12 | 13 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 14 | internal class DOC105UseParamref : InlineCodeAnalyzerBase 15 | { 16 | /// 17 | /// The ID for diagnostics produced by the analyzer. 18 | /// 19 | public const string DiagnosticId = "DOC105"; 20 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC105.md"; 21 | 22 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(StyleResources.DOC105Title), StyleResources.ResourceManager, typeof(StyleResources)); 23 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(StyleResources.DOC105MessageFormat), StyleResources.ResourceManager, typeof(StyleResources)); 24 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(StyleResources.DOC105Description), StyleResources.ResourceManager, typeof(StyleResources)); 25 | 26 | private static readonly DiagnosticDescriptor Descriptor = 27 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.StyleRules, DiagnosticSeverity.Info, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 28 | 29 | /// 30 | public override ImmutableArray SupportedDiagnostics { get; } 31 | = ImmutableArray.Create(Descriptor); 32 | 33 | protected override void HandleInlineCodeElement(ref SyntaxNodeAnalysisContext context, XmlElementSyntax xmlElement) 34 | { 35 | // This rule will only apply if the content is a single XmlTextSyntax containing a single 36 | // XmlTextLiteralToken token 37 | if (xmlElement.Content.Count != 1) 38 | { 39 | return; 40 | } 41 | 42 | if (!(xmlElement.Content[0] is XmlTextSyntax xmlText)) 43 | { 44 | return; 45 | } 46 | 47 | if (xmlText.TextTokens.Count != 1) 48 | { 49 | return; 50 | } 51 | 52 | var semanticModel = context.SemanticModel; 53 | var documentedSymbol = semanticModel.GetDeclaredSymbol(xmlElement.FirstAncestorOrSelf(SyntaxNodeExtensionsEx.IsSymbolDeclaration), context.CancellationToken); 54 | if (!documentedSymbol.HasAnyParameter(xmlText.TextTokens[0].ValueText, StringComparer.Ordinal)) 55 | { 56 | return; 57 | } 58 | 59 | context.ReportDiagnostic(Diagnostic.Create(Descriptor, xmlElement.GetLocation())); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/StyleRules/DOC106UseTypeparamref.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System; 7 | using System.Collections.Immutable; 8 | using DocumentationAnalyzers.Helpers; 9 | using Microsoft.CodeAnalysis; 10 | using Microsoft.CodeAnalysis.CSharp.Syntax; 11 | using Microsoft.CodeAnalysis.Diagnostics; 12 | 13 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 14 | internal class DOC106UseTypeparamref : InlineCodeAnalyzerBase 15 | { 16 | /// 17 | /// The ID for diagnostics produced by the analyzer. 18 | /// 19 | public const string DiagnosticId = "DOC106"; 20 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC106.md"; 21 | 22 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(StyleResources.DOC106Title), StyleResources.ResourceManager, typeof(StyleResources)); 23 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(StyleResources.DOC106MessageFormat), StyleResources.ResourceManager, typeof(StyleResources)); 24 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(StyleResources.DOC106Description), StyleResources.ResourceManager, typeof(StyleResources)); 25 | 26 | private static readonly DiagnosticDescriptor Descriptor = 27 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.StyleRules, DiagnosticSeverity.Info, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 28 | 29 | /// 30 | public override ImmutableArray SupportedDiagnostics { get; } 31 | = ImmutableArray.Create(Descriptor); 32 | 33 | protected override void HandleInlineCodeElement(ref SyntaxNodeAnalysisContext context, XmlElementSyntax xmlElement) 34 | { 35 | // This rule will only apply if the content is a single XmlTextSyntax containing a single 36 | // XmlTextLiteralToken token 37 | if (xmlElement.Content.Count != 1) 38 | { 39 | return; 40 | } 41 | 42 | if (!(xmlElement.Content[0] is XmlTextSyntax xmlText)) 43 | { 44 | return; 45 | } 46 | 47 | if (xmlText.TextTokens.Count != 1) 48 | { 49 | return; 50 | } 51 | 52 | var semanticModel = context.SemanticModel; 53 | var documentedSymbol = semanticModel.GetDeclaredSymbol(xmlElement.FirstAncestorOrSelf(SyntaxNodeExtensionsEx.IsSymbolDeclaration), context.CancellationToken); 54 | if (!documentedSymbol.HasAnyTypeParameter(xmlText.TextTokens[0].ValueText, StringComparer.Ordinal)) 55 | { 56 | return; 57 | } 58 | 59 | context.ReportDiagnostic(Diagnostic.Create(Descriptor, xmlElement.GetLocation())); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/StyleRules/DOC108AvoidEmptyParagraphs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using System.Collections.Immutable; 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp; 9 | using Microsoft.CodeAnalysis.CSharp.Syntax; 10 | using Microsoft.CodeAnalysis.Diagnostics; 11 | 12 | /// 13 | /// Avoid empty paragraphs. 14 | /// 15 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 16 | internal class DOC108AvoidEmptyParagraphs : DiagnosticAnalyzer 17 | { 18 | /// 19 | /// The ID for diagnostics produced by the analyzer. 20 | /// 21 | public const string DiagnosticId = "DOC108"; 22 | private const string HelpLink = "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/blob/master/docs/DOC108.md"; 23 | 24 | private static readonly LocalizableString Title = new LocalizableResourceString(nameof(StyleResources.DOC108Title), StyleResources.ResourceManager, typeof(StyleResources)); 25 | private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(StyleResources.DOC108MessageFormat), StyleResources.ResourceManager, typeof(StyleResources)); 26 | private static readonly LocalizableString Description = new LocalizableResourceString(nameof(StyleResources.DOC108Description), StyleResources.ResourceManager, typeof(StyleResources)); 27 | 28 | private static readonly DiagnosticDescriptor Descriptor = 29 | new(DiagnosticId, Title, MessageFormat, AnalyzerCategory.PortabilityRules, DiagnosticSeverity.Info, AnalyzerConstants.EnabledByDefault, Description, HelpLink); 30 | 31 | /// 32 | public override ImmutableArray SupportedDiagnostics { get; } 33 | = ImmutableArray.Create(Descriptor); 34 | 35 | public override void Initialize(AnalysisContext context) 36 | { 37 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 38 | context.EnableConcurrentExecution(); 39 | 40 | context.RegisterSyntaxNodeAction(HandleXmlEmptyElementSyntax, SyntaxKind.XmlEmptyElement); 41 | } 42 | 43 | private static void HandleXmlEmptyElementSyntax(SyntaxNodeAnalysisContext context) 44 | { 45 | var xmlEmptyElement = (XmlEmptyElementSyntax)context.Node; 46 | var name = xmlEmptyElement.Name; 47 | if (name.Prefix != null) 48 | { 49 | return; 50 | } 51 | 52 | switch (name.LocalName.ValueText) 53 | { 54 | case "para": 55 | case "p": 56 | break; 57 | 58 | default: 59 | return; 60 | } 61 | 62 | context.ReportDiagnostic(Diagnostic.Create(Descriptor, xmlEmptyElement.GetLocation())); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/DocumentationAnalyzers/StyleRules/InlineCodeAnalyzerBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the MIT license. See LICENSE in the project root for license information. 3 | 4 | namespace DocumentationAnalyzers.StyleRules 5 | { 6 | using DocumentationAnalyzers.Helpers; 7 | using Microsoft.CodeAnalysis.CSharp; 8 | using Microsoft.CodeAnalysis.CSharp.Syntax; 9 | using Microsoft.CodeAnalysis.Diagnostics; 10 | 11 | /// 12 | /// This is the base class for diagnostic analyzers which report diagnostics for use of <c> which a 13 | /// more appropriate inline element is available. 14 | /// 15 | internal abstract class InlineCodeAnalyzerBase : DiagnosticAnalyzer 16 | { 17 | /// 18 | public override void Initialize(AnalysisContext context) 19 | { 20 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 21 | context.EnableConcurrentExecution(); 22 | 23 | context.RegisterSyntaxNodeAction(HandleXmlElementSyntax, SyntaxKind.XmlElement); 24 | } 25 | 26 | protected abstract void HandleInlineCodeElement(ref SyntaxNodeAnalysisContext context, XmlElementSyntax xmlElement); 27 | 28 | private void HandleXmlElementSyntax(SyntaxNodeAnalysisContext context) 29 | { 30 | var xmlElement = (XmlElementSyntax)context.Node; 31 | var name = xmlElement.StartTag.Name; 32 | if (name.Prefix != null) 33 | { 34 | return; 35 | } 36 | 37 | if (name.LocalName.ValueText != XmlCommentHelper.CXmlTag) 38 | { 39 | return; 40 | } 41 | 42 | HandleInlineCodeElement(ref context, xmlElement); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/stylecop.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", 3 | "settings": { 4 | "documentationRules": { 5 | "companyName": "Tunnel Vision Laboratories, LLC", 6 | "copyrightText": "Copyright (c) {companyName}. All Rights Reserved.\r\nLicensed under the MIT license. See LICENSE in the project root for license information.", 7 | "xmlHeader": false, 8 | "fileNamingConvention": "metadata" 9 | }, 10 | "layoutRules": { 11 | "newlineAtEndOfFile": "require" 12 | }, 13 | "namingRules": { 14 | "tupleElementNameCasing": "camelCase" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DocumentationAnalyzers/version.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", 3 | "version": "1.0.0-beta.{height}", 4 | "assemblyVersion": { 5 | "precision": "revision" 6 | }, 7 | "publicReleaseRefSpec": [ 8 | "^refs/heads/master$" 9 | ], 10 | "nugetPackageVersion": { 11 | "semVer": 2 12 | }, 13 | "cloudBuild": { 14 | "buildNumber": { 15 | "enabled": true 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Tunnel Vision Laboratories, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NuGet.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Documentation Analyzers for the .NET Compiler Platform 2 | 3 | [![NuGet](https://img.shields.io/nuget/v/DotNetAnalyzers.DocumentationAnalyzers.svg)](https://www.nuget.org/packages/DotNetAnalyzers.DocumentationAnalyzers) [![NuGet Beta](https://img.shields.io/nuget/vpre/DotNetAnalyzers.DocumentationAnalyzers.svg)](https://www.nuget.org/packages/DotNetAnalyzers.DocumentationAnalyzers) 4 | 5 | [![Join the chat at https://gitter.im/DotNetAnalyzers/DocumentationAnalyzers](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/DotNetAnalyzers/DocumentationAnalyzers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 6 | 7 | [![Build status](https://ci.appveyor.com/api/projects/status/8jw2lq431kgg44jl/branch/master?svg=true)](https://ci.appveyor.com/project/sharwell/Documentationanalyzers/branch/master) 8 | 9 | [![codecov.io](http://codecov.io/github/DotNetAnalyzers/DocumentationAnalyzers/coverage.svg?branch=master)](http://codecov.io/github/DotNetAnalyzers/DocumentationAnalyzers?branch=master) 10 | 11 | This repository contains an implementation of .NET documentation rules using the .NET Compiler Platform. Where possible, code fixes are also provided to simplify the process of correcting violations. 12 | 13 | ## Using DocumentationAnalyzers 14 | 15 | The preferable way to use the analyzers is to add the nuget package [DotNetAnalyzers.DocumentationAnalyzers](http://www.nuget.org/packages/DotNetAnalyzers.DocumentationAnalyzers/) 16 | to the project where you want to enforce documentation rules. 17 | 18 | The severity of individual rules may be configured using [rule set files](https://docs.microsoft.com/en-us/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules) 19 | in Visual Studio 2015 or newer. For Visual Studio 2019 version 16.3 and newer, the severity of individual rules may be configured using **.editorconfig**. 20 | 21 | For documentation and reasoning on the rules themselves, see the [DOCUMENTATION.md](DOCUMENTATION.md). 22 | 23 | ## Installation 24 | 25 | DocumentationAnalyzers can be installed using the NuGet command line or the NuGet Package Manager in Visual Studio 2015. 26 | 27 | **Install using the command line:** 28 | 29 | ```ps 30 | Install-Package DotNetAnalyzers.DocumentationAnalyzers 31 | ``` 32 | 33 | > ⚠ Prereleases of the **DotNetAnalyzers.DocumentationAnalyzers** package use Semantic Versioning 2, which requires NuGet 4.3.0 (Visual Studio 2017 version 15.3) or newer. Users with clients that do not support Semantic Versioning 2 may install prereleases using the **DotNetAnalyzers.DocumentationAnalyzers.Unstable** package instead. 34 | 35 | ## Team Considerations 36 | 37 | If you use older versions of Visual Studio in addition to Visual Studio 2015 or Visual Studio 2017, you may still install these analyzers. They will be automatically disabled when you open the project back up in Visual Studio 2013 or earlier. 38 | 39 | ## Contributing 40 | 41 | See [CONTRIBUTING.md](CONTRIBUTING.md) 42 | 43 | ## Current status 44 | 45 | An up-to-date list of which documentation rules are implemented and which have code fixes can be found [here](https://dotnetanalyzers.github.io/DocumentationAnalyzers/). 46 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | image: Visual Studio 2019 3 | init: 4 | - git config --global core.autocrlf true 5 | configuration: 6 | - Debug 7 | - Release 8 | before_build: 9 | - nuget restore 10 | skip_tags: true 11 | build: 12 | project: DocumentationAnalyzers.sln 13 | verbosity: minimal 14 | test_script: 15 | - cd build 16 | - ps: | 17 | if ($env:Configuration -eq 'Debug') { 18 | .\opencover-report.ps1 -Debug -NoBuild -NoReport -AppVeyor 19 | if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } 20 | $packageConfig = [xml](Get-Content ..\.nuget\packages.config) 21 | $codecov_version = $packageConfig.SelectSingleNode('/packages/package[@id="Codecov"]').version 22 | $codecov = "..\packages\Codecov.$codecov_version\tools\codecov.exe" 23 | &$codecov -f '..\build\OpenCover.Reports\OpenCover.DocumentationAnalyzers.xml' 24 | } else { 25 | .\opencover-report.ps1 -NoBuild -NoReport -AppVeyor 26 | if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } 27 | } 28 | - cd .. 29 | - .\DocumentationAnalyzers\DocumentationAnalyzers.Status.Generator\bin\%Configuration%\net472\DocumentationAnalyzers.Status.Generator.exe .\DocumentationAnalyzers.sln > DocumentationAnalyzers.Status.json 30 | cache: 31 | - packages -> **\packages.config 32 | - C:\Users\appveyor\.nuget\packages -> appveyor.yml 33 | 34 | # 'Release' is hard-coded to ensure VSIX and NuGet artifacts are only published for release configuration builds 35 | artifacts: 36 | - path: 'DocumentationAnalyzers\DocumentationAnalyzers.Vsix\bin\Release\net452\*.vsix' 37 | - path: 'DocumentationAnalyzers\DocumentationAnalyzers.CodeFixes\bin\Release\*.nupkg' 38 | - path: 'DocumentationAnalyzers.Status.json' 39 | -------------------------------------------------------------------------------- /build/check-key.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | [string]$Assembly, 3 | [string]$ExpectedKey, 4 | [string]$Build = $null 5 | ) 6 | 7 | function Get-PublicKeyToken() { 8 | param([string]$assembly = $null) 9 | if ($assembly) { 10 | $bytes = $null 11 | $bytes = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($assembly).GetName().GetPublicKeyToken() 12 | if ($bytes) { 13 | $key = "" 14 | for ($i=0; $i -lt $bytes.Length; $i++) { 15 | $key += "{0:x2}" -f $bytes[$i] 16 | } 17 | 18 | $key 19 | } 20 | } 21 | } 22 | 23 | if (-not $Build) { 24 | $Build = $Assembly 25 | } 26 | 27 | $actual = Get-PublicKeyToken -assembly $Assembly 28 | if ($actual -ne $ExpectedKey) { 29 | $host.ui.WriteErrorLine("Invalid publicKeyToken for '$Build'; expected '$ExpectedKey' but found '$actual'") 30 | exit 1 31 | } 32 | -------------------------------------------------------------------------------- /build/keys.ps1: -------------------------------------------------------------------------------- 1 | # Note: these values may only change during major release 2 | 3 | If ($Version.Contains('-')) { 4 | 5 | # Use the development keys 6 | $Keys = @{ 7 | 'netstandard1.1' = '2bc5e20c3ad68793' 8 | 'net452' = '2bc5e20c3ad68793' 9 | } 10 | 11 | } Else { 12 | 13 | # Use the final release keys 14 | $Keys = @{ 15 | 'netstandard1.1' = 'c80e32baaec95a4f' 16 | 'net452' = 'c80e32baaec95a4f' 17 | } 18 | 19 | } 20 | 21 | function Resolve-FullPath() { 22 | param([string]$Path) 23 | [System.IO.Path]::GetFullPath((Join-Path (pwd) $Path)) 24 | } 25 | -------------------------------------------------------------------------------- /build/keys/DocumentationAnalyzers.dev.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetAnalyzers/DocumentationAnalyzers/5152abcc72b665c241d5539877d23873d84839ce/build/keys/DocumentationAnalyzers.dev.snk -------------------------------------------------------------------------------- /build/keys/DocumentationAnalyzers.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetAnalyzers/DocumentationAnalyzers/5152abcc72b665c241d5539877d23873d84839ce/build/keys/DocumentationAnalyzers.snk -------------------------------------------------------------------------------- /build/keys/TestingKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DotNetAnalyzers/DocumentationAnalyzers/5152abcc72b665c241d5539877d23873d84839ce/build/keys/TestingKey.snk -------------------------------------------------------------------------------- /build/opencover-report.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [switch]$Debug, 3 | [switch]$NoBuild, 4 | [switch]$NoReport, 5 | [switch]$AppVeyor 6 | ) 7 | 8 | If (-not $NoBuild) { 9 | # Run a build to ensure everything is up-to-date 10 | If ($Debug) { 11 | .\build.ps1 -Debug -Incremental 12 | } Else { 13 | .\build.ps1 -Incremental 14 | } 15 | 16 | If (-not $?) { 17 | $host.UI.WriteErrorLine('Build failed; coverage analysis aborted.') 18 | Exit $LASTEXITCODE 19 | } 20 | } 21 | 22 | If ($Debug) { 23 | $Configuration = 'Debug' 24 | } Else { 25 | $Configuration = 'Release' 26 | } 27 | 28 | $packageConfig = [xml](Get-Content ..\.nuget\packages.config) 29 | $opencover_version = $packageConfig.SelectSingleNode('/packages/package[@id="OpenCover"]').version 30 | $reportgenerator_version = $packageConfig.SelectSingleNode('/packages/package[@id="ReportGenerator"]').version 31 | $xunitrunner_version = $packageConfig.SelectSingleNode('/packages/package[@id="xunit.runner.console"]').version 32 | 33 | $packages_folder = '..\packages' 34 | $opencover_console = "$packages_folder\OpenCover.$opencover_version\tools\OpenCover.Console.exe" 35 | $xunit_runner_console_net452 = "$packages_folder\xunit.runner.console.$xunitrunner_version\tools\net452\xunit.console.x86.exe" 36 | $xunit_runner_console_net46 = "$packages_folder\xunit.runner.console.$xunitrunner_version\tools\net46\xunit.console.x86.exe" 37 | $report_generator = "$packages_folder\ReportGenerator.$reportgenerator_version\tools\ReportGenerator.exe" 38 | $report_folder = '.\OpenCover.Reports' 39 | $target_dll = "..\DocumentationAnalyzers\DocumentationAnalyzers.Test\bin\$Configuration\net452\DocumentationAnalyzers.Test.dll" 40 | $target_dll_csharp7 = "..\DocumentationAnalyzers\DocumentationAnalyzers.Test.CSharp7\bin\$Configuration\net46\DocumentationAnalyzers.Test.CSharp7.dll" 41 | 42 | If (Test-Path $report_folder) { 43 | Remove-Item -Recurse -Force $report_folder 44 | } 45 | 46 | mkdir $report_folder | Out-Null 47 | 48 | $register_mode = 'user' 49 | If ($AppVeyor) { 50 | $AppVeyorArg = '-appveyor' 51 | $register_mode = 'Path32' 52 | } 53 | 54 | &$opencover_console ` 55 | -register:$register_mode ` 56 | -returntargetcode ` 57 | -hideskipped:All ` 58 | -filter:"+[Documentation*]*" ` 59 | -excludebyattribute:*.ExcludeFromCodeCoverage* ` 60 | -excludebyfile:*\*Designer.cs ` 61 | -output:"$report_folder\OpenCover.DocumentationAnalyzers.xml" ` 62 | -target:"$xunit_runner_console_net452" ` 63 | -targetargs:"$target_dll -noshadow $AppVeyorArg" 64 | 65 | If ($AppVeyor -and -not $?) { 66 | $host.UI.WriteErrorLine('Build failed; coverage analysis aborted.') 67 | Exit $LASTEXITCODE 68 | } 69 | 70 | &$opencover_console ` 71 | -register:$register_mode ` 72 | -returntargetcode ` 73 | -hideskipped:All ` 74 | -filter:"+[Documentation*]*" ` 75 | -excludebyattribute:*.ExcludeFromCodeCoverage* ` 76 | -excludebyfile:*\*Designer.cs ` 77 | -output:"$report_folder\OpenCover.DocumentationAnalyzers.xml" ` 78 | -mergebyhash -mergeoutput ` 79 | -target:"$xunit_runner_console_net46" ` 80 | -targetargs:"$target_dll_csharp7 -noshadow $AppVeyorArg" 81 | 82 | If ($AppVeyor -and -not $?) { 83 | $host.UI.WriteErrorLine('Build failed; coverage analysis aborted.') 84 | Exit $LASTEXITCODE 85 | } 86 | 87 | If (-not $NoReport) { 88 | &$report_generator -targetdir:$report_folder -reports:$report_folder\OpenCover.*.xml 89 | $host.UI.WriteLine("Open $report_folder\index.htm to see code coverage results.") 90 | } 91 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | # https://docs.codecov.io/docs/codecov-yaml 2 | # https://github.com/codecov/support/wiki/Codecov-Yaml 3 | 4 | coverage: 5 | status: 6 | project: 7 | default: false 8 | patch: 9 | default: false 10 | fixes: 11 | - "build/DocumentationAnalyzers/::DocumentationAnalyzers/" 12 | 13 | comment: 14 | layout: "diff" 15 | 16 | flags: 17 | production: 18 | paths: 19 | - DocumentationAnalyzers/DocumentationAnalyzers/ 20 | - DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/ 21 | test: 22 | paths: 23 | - DocumentationAnalyzers/DocumentationAnalyzers.Test/ 24 | -------------------------------------------------------------------------------- /docs/DOC100.md: -------------------------------------------------------------------------------- 1 | # DOC100 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC100PlaceTextInParagraphs
CheckIdDOC100
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | A `` or `` documentation element contains content which is not wrapped in a block-level element. 21 | 22 | ## Rule description 23 | 24 | A violation of this rule occurs when a `` or `` documentation element contains content which is not 25 | wrapped in a block-level element. 26 | 27 | ```csharp 28 | /// Summary text. 29 | /// 30 | /// Remarks text. 31 | /// 32 | public void SomeOperation() 33 | { 34 | } 35 | ``` 36 | 37 | ## How to fix violations 38 | 39 | To fix a violation of this rule, place the content in a block-level element, such as a `` element. 40 | 41 | ```csharp 42 | /// Summary text. 43 | /// 44 | /// Remarks text. 45 | /// 46 | public void SomeOperation() 47 | { 48 | } 49 | ``` 50 | 51 | ## How to suppress violations 52 | 53 | ```csharp 54 | #pragma warning disable DOC100 // Place text in paragraphs 55 | /// 56 | /// Summary text. 57 | /// 58 | /// 59 | /// Inline remarks. 60 | /// 61 | public void SomeOperation() 62 | #pragma warning restore DOC100 // Place text in paragraphs 63 | { 64 | } 65 | ``` 66 | -------------------------------------------------------------------------------- /docs/DOC101.md: -------------------------------------------------------------------------------- 1 | # DOC101 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC101UseChildBlocksConsistently
CheckIdDOC101
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | A documentation element contains some children which are block-level elements, but other children which are not. 21 | 22 | ## Rule description 23 | 24 | A violation of this rule occurs when a documentation element contains some children which are block-level elements, but 25 | other children which are not. 26 | 27 | ```csharp 28 | /// Summary text. 29 | /// 30 | /// Parameter documentation. 31 | /// Parameter documentation continued. 32 | /// 33 | public void SomeOperation(int x) 34 | { 35 | } 36 | ``` 37 | 38 | ## How to fix violations 39 | 40 | To fix a violation of this rule, place the content in a block-level element, such as a `` element. 41 | 42 | ```csharp 43 | /// Summary text. 44 | /// 45 | /// Parameter documentation. 46 | /// Parameter documentation continued. 47 | /// 48 | public void SomeOperation(int x) 49 | { 50 | } 51 | ``` 52 | 53 | ## How to suppress violations 54 | 55 | ```csharp 56 | #pragma warning disable DOC101 // Use child blocks consistently 57 | /// Summary text. 58 | /// 59 | /// Inline content. 60 | /// Block content. 61 | /// 62 | public void SomeOperation(int x) 63 | #pragma warning restore DOC101 // Use child blocks consistently 64 | { 65 | } 66 | ``` 67 | -------------------------------------------------------------------------------- /docs/DOC102.md: -------------------------------------------------------------------------------- 1 | # DOC102 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC102UseChildBlocksConsistentlyAcrossElementsOfTheSameKind
CheckIdDOC102
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | The documentation for the element contains inline text, but the documentation for a sibling element of the same kind 21 | uses block-level elements. 22 | 23 | ## Rule description 24 | 25 | A violation of this rule occurs when a documentation contains sibling elements of the same kind, where some siblings use 26 | block-level content, but others do not. In the following example, one `param` element uses inline content, while another 27 | `param` element uses block content. 28 | 29 | ```csharp 30 | /// 31 | /// Summary text. 32 | /// 33 | /// Inline content. 34 | /// 35 | /// Block content. 36 | /// 37 | public void SomeOperation(int x, int y) 38 | { 39 | } 40 | ``` 41 | 42 | ## How to fix violations 43 | 44 | To fix a violation of this rule, place the content in a block-level element, such as a `` element. 45 | 46 | ```csharp 47 | /// 48 | /// Summary text. 49 | /// 50 | /// 51 | /// Block content. 52 | /// 53 | /// 54 | /// Block content. 55 | /// 56 | public void SomeOperation(int x, int y) 57 | { 58 | } 59 | ``` 60 | 61 | ## How to suppress violations 62 | 63 | ```csharp 64 | #pragma warning disable DOC102 // Use child blocks consistently across elements of the same kind 65 | /// 66 | /// Summary text. 67 | /// 68 | /// Inline content. 69 | /// 70 | /// Block content. 71 | /// 72 | public void SomeOperation(int x, int y) 73 | #pragma warning restore DOC102 // Use child blocks consistently across elements of the same kind 74 | { 75 | } 76 | ``` 77 | -------------------------------------------------------------------------------- /docs/DOC103.md: -------------------------------------------------------------------------------- 1 | # DOC103 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC103UseUnicodeCharacters
CheckIdDOC103
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | The documentation contains an unnecessary or unrecognized HTML character entity. 21 | 22 | ## Rule description 23 | 24 | A violation of this rule occurs when documentation an unnecessarily-escaped character, making the documentation more 25 | difficult to read than necessary. The code fix for this diagnostic also helps correct HTML character entity references 26 | (e.g. `&rarr`), which are not supported by the XML documentation compiler. 27 | 28 | ```csharp 29 | /// 30 | /// A city's graph from A→B. 31 | /// 32 | public class SomeType 33 | { 34 | } 35 | ``` 36 | 37 | ## How to fix violations 38 | 39 | To fix a violation of this rule, replace the XML- or HTML-escape sequence with the intended character. 40 | 41 | ```csharp 42 | /// 43 | /// A city's graph from A→B. 44 | /// 45 | public class SomeType 46 | { 47 | } 48 | ``` 49 | 50 | ## How to suppress violations 51 | 52 | ```csharp 53 | #pragma warning disable DOC103 // Use Unicode characters 54 | /// 55 | /// A city's graph from A→B. 56 | /// 57 | public class SomeType 58 | #pragma warning restore DOC103 // Use Unicode characters 59 | { 60 | } 61 | ``` 62 | -------------------------------------------------------------------------------- /docs/DOC104.md: -------------------------------------------------------------------------------- 1 | # DOC104 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC104UseSeeLangword
CheckIdDOC104
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | The documentation contains a language keyword reference using `keyword` that can be converted to the preferred 21 | form ``. 22 | 23 | ## Rule description 24 | 25 | A violation of this rule occurs when documentation contains a language keyword reference written in inline code that can 26 | be written in a preferred form using `see langword`. 27 | 28 | ```csharp 29 | /// 30 | /// This type is sealed. 31 | /// 32 | public sealed class SomeType 33 | { 34 | } 35 | ``` 36 | 37 | ## How to fix violations 38 | 39 | To fix a violation of this rule, replace the inline code with the equivalent `see langword` syntax. 40 | 41 | ```csharp 42 | /// 43 | /// This type is . 44 | /// 45 | public sealed class SomeType 46 | { 47 | } 48 | ``` 49 | 50 | ## How to suppress violations 51 | 52 | ```csharp 53 | #pragma warning disable DOC104 // Use 'see langword' 54 | /// 55 | /// This type is sealed. 56 | /// 57 | public sealed class SomeType 58 | #pragma warning restore DOC104 // Use 'see langword' 59 | { 60 | } 61 | ``` 62 | -------------------------------------------------------------------------------- /docs/DOC105.md: -------------------------------------------------------------------------------- 1 | # DOC105 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC105UseParamref
CheckIdDOC105
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | The documentation contains a parameter reference using `name` that can be converted to the preferred form 21 | ``. 22 | 23 | ## Rule description 24 | 25 | A violation of this rule occurs when documentation contains a parameter reference written in inline code that can be 26 | written in a preferred form using `paramref`. 27 | 28 | ```csharp 29 | /// 30 | /// Pass in a value. 31 | /// 32 | public void Method(int value) 33 | { 34 | } 35 | ``` 36 | 37 | ## How to fix violations 38 | 39 | To fix a violation of this rule, replace the inline code with the equivalent `paramref` syntax. 40 | 41 | ```csharp 42 | /// 43 | /// Pass in a . 44 | /// 45 | public void Method(int value) 46 | { 47 | } 48 | ``` 49 | 50 | ## How to suppress violations 51 | 52 | ```csharp 53 | #pragma warning disable DOC105 // Use 'paramref' 54 | /// 55 | /// Pass in a value. 56 | /// 57 | public void Method(int value) 58 | #pragma warning restore DOC104 // Use 'paramref' 59 | { 60 | } 61 | ``` 62 | -------------------------------------------------------------------------------- /docs/DOC106.md: -------------------------------------------------------------------------------- 1 | # DOC106 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC106UseTypeparamref
CheckIdDOC106
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | The documentation contains a type parameter reference using `T` that can be converted to the preferred form 21 | ``. 22 | 23 | ## Rule description 24 | 25 | A violation of this rule occurs when documentation contains a type parameter reference written in inline code that can 26 | be written in a preferred form using `typeparamref`. 27 | 28 | ```csharp 29 | /// 30 | /// Pass in a T. 31 | /// 32 | public void Method() 33 | { 34 | } 35 | ``` 36 | 37 | ## How to fix violations 38 | 39 | To fix a violation of this rule, replace the inline code with the equivalent `typeparamref` syntax. 40 | 41 | ```csharp 42 | /// 43 | /// Pass in a . 44 | /// 45 | public void Method() 46 | { 47 | } 48 | ``` 49 | 50 | ## How to suppress violations 51 | 52 | ```csharp 53 | #pragma warning disable DOC106 // Use 'typeparamref' 54 | /// 55 | /// Pass in a T. 56 | /// 57 | public void Method() 58 | #pragma warning restore DOC106 // Use 'typeparamref' 59 | { 60 | } 61 | ``` 62 | -------------------------------------------------------------------------------- /docs/DOC107.md: -------------------------------------------------------------------------------- 1 | # DOC107 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC107UseSeeCref
CheckIdDOC107
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | The documentation contains a code element reference using `name` that can be converted to the preferred form 21 | ``. 22 | 23 | ## Rule description 24 | 25 | A violation of this rule occurs when documentation contains a code element reference written in inline code that can 26 | be written in a preferred form using `see cref`. 27 | 28 | ```csharp 29 | int SomeValue { get; } 30 | 31 | /// 32 | /// Depends on SomeValue. 33 | /// 34 | public void Method() 35 | { 36 | } 37 | ``` 38 | 39 | ## How to fix violations 40 | 41 | To fix a violation of this rule, replace the inline code with the equivalent `see cref` syntax. 42 | 43 | ```csharp 44 | int SomeValue { get; } 45 | 46 | /// 47 | /// Depends on . 48 | /// 49 | public void Method() 50 | { 51 | } 52 | ``` 53 | 54 | ## How to suppress violations 55 | 56 | ```csharp 57 | int SomeValue { get; } 58 | 59 | #pragma warning disable DOC107 // Use 'see cref' 60 | /// 61 | /// Depends on SomeValue. 62 | /// 63 | public void Method() 64 | #pragma warning restore DOC107 // Use 'see cref' 65 | { 66 | } 67 | ``` 68 | -------------------------------------------------------------------------------- /docs/DOC108.md: -------------------------------------------------------------------------------- 1 | # DOC108 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC108AvoidEmptyParagraphs
CheckIdDOC108
CategoryStyle Rules
17 | 18 | ## Cause 19 | 20 | The documentation contains an empty paragraph element (`` or `

`) used as a paragraph separator. 21 | 22 | ## Rule description 23 | 24 | A violation of this rule occurs when a `` or `

` is used as a paragraph separator. Rather than place an empty 25 | paragraph element between paragraphs, the text content of paragraphs should be contained in the `` element. 26 | 27 | ```csharp 28 | ///

Summary text. 29 | /// 30 | /// Remarks text. 31 | /// 32 | /// Second paragraph of remarks, which is not placed inside the <para> element. 33 | /// 34 | public void SomeOperation() 35 | { 36 | } 37 | ``` 38 | 39 | ## How to fix violations 40 | 41 | To fix a violation of this rule, update the comment so the `` element wraps the documentation text which follows 42 | it: 43 | 44 | ```csharp 45 | /// Summary text. 46 | /// 47 | /// Remarks text. 48 | /// Second paragraph of remarks, which is now placed inside the <para> element. 49 | /// 50 | public void SomeOperation() 51 | { 52 | } 53 | ``` 54 | 55 | ## How to suppress violations 56 | 57 | Do not suppress violations of this rule. If the preferred documentation style does not align with the rule decription, 58 | it is best to disable the rule. 59 | -------------------------------------------------------------------------------- /docs/DOC200.md: -------------------------------------------------------------------------------- 1 | # DOC200 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
TypeNameDOC200UseXmlDocumentationSyntax
CheckIdDOC200
CategoryPortability Rules
17 | 18 | ## Cause 19 | 20 | The documentation for the element contains an HTML element equivalent to a known XML documentation element. 21 | 22 | ## Rule description 23 | 24 | A violation of this rule occurs when an XML documentation comment contains an HTML element instead of the corresponding 25 | XML documentation comment syntax. 26 | 27 | ## How to fix violations 28 | 29 | To fix a violation of this rule, use the expected XML documentation element instead of the HTML element. 30 | 31 | | HTML Element | XML Element | 32 | | --- | --- | 33 | | `

` | `` | 34 | | `` | `` | 35 | | `

` | `` |
36 | | `
    ` | `` | 37 | | `
      ` | `` | 38 | 39 | ## How to suppress violations 40 | 41 | ```csharp 42 | #pragma warning disable DOC200 // Use XML documentation syntax 43 | /// 44 | /// Summary text with inline code. 45 | /// 46 | public void SomeOperation() 47 | #pragma warning restore DOC200 // Use XML documentation syntax 48 | { 49 | } 50 | ``` 51 | -------------------------------------------------------------------------------- /docs/DOC201.md: -------------------------------------------------------------------------------- 1 | # DOC201 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
      TypeNameDOC201ItemShouldHaveDescription
      CheckIdDOC201
      CategoryPortability Rules
      17 | 18 | ## Cause 19 | 20 | The documentation for an `` within a `` did not include the required `` and/or `` 21 | elements. 22 | 23 | ## Rule description 24 | 25 | According to the C# language specification, the `` element within a documentation comment must have its content 26 | wrapped in a `` element. Not all documentation processing tools support omitting the `` 27 | element, so it should be included for consistent behavior. 28 | 29 | ```csharp 30 | /// 31 | /// 32 | /// This item has text not wrapped in a description element. 33 | /// 34 | /// 35 | public void SomeOperation() 36 | { 37 | } 38 | ``` 39 | 40 | See [dotnet/csharplang#1765](https://github.com/dotnet/csharplang/issues/1765) for a language proposal to natively 41 | support lists with the `` element removed. 42 | 43 | ## How to fix violations 44 | 45 | To fix a violation of this rule, wrap the content of the `` element in a `` element. 46 | 47 | ```csharp 48 | /// 49 | /// 50 | /// This item has text wrapped in a description element. 51 | /// 52 | /// 53 | public void SomeOperation() 54 | { 55 | } 56 | ``` 57 | 58 | ## How to suppress violations 59 | 60 | This rule can be disabled rather than suppressed for projects whose documentation processing tools support `` 61 | elements which are not wrapped in a `` element. In other cases, the warning can be suppressed as follows: 62 | 63 | ```csharp 64 | #pragma warning disable DOC201 // Item should have description 65 | /// 66 | /// 67 | /// This item has text not wrapped in a description element. 68 | /// 69 | /// 70 | public void SomeOperation() 71 | #pragma warning restore DOC201 // Item should have description 72 | { 73 | } 74 | ``` 75 | -------------------------------------------------------------------------------- /docs/DOC202.md: -------------------------------------------------------------------------------- 1 | # DOC202 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
      TypeNameDOC202UseSectionElementsCorrectly
      CheckIdDOC202
      CategoryPortability Rules
      17 | 18 | ## Cause 19 | 20 | The documentation contains a section element where a block or inline element was expected. 21 | 22 | ## Rule description 23 | 24 | *TODO* 25 | 26 | ```csharp 27 | /// 28 | /// Summary text. 29 | /// 30 | /// Here is an example: 31 | /// 32 | /// Console.WriteLine(); 33 | /// 34 | /// 35 | /// 36 | public void SomeOperation() 37 | { 38 | } 39 | ``` 40 | 41 | ## How to fix violations 42 | 43 | To fix a violation of this rule, move the section element outside the block or inline element context, or replace the 44 | section element with an appropriate block or inline element. 45 | 46 | ### Option: Move the section element outside the block element 47 | 48 | ```csharp 49 | /// 50 | /// Summary text. 51 | /// 52 | /// 53 | /// Here is an example: 54 | /// 55 | /// Console.WriteLine(); 56 | /// 57 | /// 58 | public void SomeOperation() 59 | { 60 | } 61 | ``` 62 | 63 | ### Option: Use an appropriate block element instead of the section element 64 | 65 | ```csharp 66 | /// 67 | /// Summary text. 68 | /// Here is an example: 69 | /// 70 | /// Console.WriteLine(); 71 | /// 72 | /// 73 | public void SomeOperation() 74 | { 75 | } 76 | ``` 77 | 78 | ## How to suppress violations 79 | 80 | *TODO* 81 | -------------------------------------------------------------------------------- /docs/DOC203.md: -------------------------------------------------------------------------------- 1 | # DOC203 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
      TypeNameDOC203UseBlockElementsCorrectly
      CheckIdDOC203
      CategoryPortability Rules
      17 | 18 | ## Cause 19 | 20 | The documentation contains a block element where a section or inline element was expected. 21 | 22 | ## Rule description 23 | 24 | *TODO* 25 | 26 | ## How to fix violations 27 | 28 | To fix a violation of this rule, move the block element inside a section or outside a containing inline element, or 29 | replace the block element with an appropriate section or inline element. 30 | 31 | ## How to suppress violations 32 | 33 | *TODO* 34 | -------------------------------------------------------------------------------- /docs/DOC204.md: -------------------------------------------------------------------------------- 1 | # DOC204 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
      TypeNameDOC204UseInlineElementsCorrectly
      CheckIdDOC204
      CategoryPortability Rules
      17 | 18 | ## Cause 19 | 20 | The documentation contains an inline element where a section or block element was expected. 21 | 22 | ## Rule description 23 | 24 | *TODO* 25 | 26 | ## How to fix violations 27 | 28 | *TODO* 29 | 30 | ## How to suppress violations 31 | 32 | *TODO* 33 | -------------------------------------------------------------------------------- /docs/DOC207.md: -------------------------------------------------------------------------------- 1 | # DOC207 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
      TypeNameDOC207UseSeeLangwordCorrectly
      CheckIdDOC207
      CategoryPortability Rules
      17 | 18 | ## Cause 19 | 20 | The documentation contains a `` element with an unrecognized keyword. 21 | 22 | ## Rule description 23 | 24 | A violation of this rule occurs when documentation contains a `see langword` element but the reference is not recognized 25 | as a language keyword. 26 | 27 | ```csharp 28 | /// 29 | /// This variable is . 30 | /// 31 | public int correct; 32 | ``` 33 | 34 | ## How to fix violations 35 | 36 | To fix a violation of this rule, replace the `see langword` syntax with the equivalent inline code. 37 | 38 | ```csharp 39 | /// 40 | /// This variable is correct. 41 | /// 42 | public int correct; 43 | ``` 44 | 45 | ## How to suppress violations 46 | 47 | ```csharp 48 | #pragma warning disable DOC207 // Use 'see langword' correctly 49 | /// 50 | /// This variable is . 51 | /// 52 | public int correct; 53 | #pragma warning restore DOC207 // Use 'see langword' correctly 54 | ``` 55 | -------------------------------------------------------------------------------- /docs/DOC209.md: -------------------------------------------------------------------------------- 1 | # DOC209 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
      TypeNameDOC209UseSeeHrefCorrectly
      CheckIdDOC209
      CategoryPortability Rules
      17 | 18 | ## Cause 19 | 20 | The documentation contains a `` or `` element with an unrecognized URI. 21 | 22 | ## Rule description 23 | 24 | *TODO* 25 | 26 | ## How to fix violations 27 | 28 | *TODO* 29 | 30 | ## How to suppress violations 31 | 32 | *TODO* 33 | -------------------------------------------------------------------------------- /docs/DOC900.md: -------------------------------------------------------------------------------- 1 | # DOC900 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
      TypeNameDOC900RenderAsMarkdown
      CheckIdDOC900
      CategoryRefactorings
      17 | 18 | ## Description 19 | 20 | This refactoring assists users in converting Markdown syntax within documentation comments to XML syntax recognized by 21 | the compiler and other tools. 22 | -------------------------------------------------------------------------------- /docs/DOC901.md: -------------------------------------------------------------------------------- 1 | # DOC901 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
      TypeNameDOC901ConvertToDocumentationComment
      CheckIdDOC901
      CategoryRefactorings
      17 | 18 | ## Description 19 | 20 | This refactoring assists users in converting line and block comments preceding a type or member to a documentation 21 | comment for the member. 22 | -------------------------------------------------------------------------------- /docs/PortabilityRules.md: -------------------------------------------------------------------------------- 1 | ### Portability Rules (DOC200-) 2 | 3 | Rules related to the portability of documentation comments. 4 | 5 | Identifier | Name | Description 6 | -----------|------|------------- 7 | [DOC200](DOC200.md) | UseXmlDocumentationSyntax | The documentation for the element an HTML element equivalent to a known XML documentation element. 8 | [DOC201](DOC201.md) | ItemShouldHaveDescription | The documentation for an `` within a `` did not include the required `` and/or `` elements. 9 | [DOC202](DOC202.md) | UseSectionElementsCorrectly | The documentation contains a section element where a block or inline element was expected. 10 | [DOC203](DOC203.md) | UseBlockElementsCorrectly | The documentation contains a block element where a section or inline element was expected. 11 | [DOC204](DOC204.md) | UseInlineElementsCorrectly | The documentation contains an inline element where a section or block element was expected. 12 | [DOC207](DOC207.md) | UseSeeLangwordCorrectly | The documentation contains a `` element with an unrecognized keyword. 13 | [DOC209](DOC209.md) | UseSeeHrefCorrectly | The documentation contains a `` element with an unrecognized URI. 14 | -------------------------------------------------------------------------------- /docs/Refactorings.md: -------------------------------------------------------------------------------- 1 | ### Refactorings (DOC900-) 2 | 3 | Additional refactorings provided when the analyzer is installed. 4 | 5 | Identifier | Name | Description 6 | -----------|------|------------- 7 | [DOC900](DOC900.md) | RenderAsMarkdown | Render documentation as Markdown. 8 | [DOC901](DOC901.md) | ConvertToDocumentationComment | Convert a line or block comment to a documentation comment. 9 | -------------------------------------------------------------------------------- /docs/StyleRules.md: -------------------------------------------------------------------------------- 1 | ### Style Rules (DOC100-) 2 | 3 | Rules related to the style of documentation comments. 4 | 5 | Identifier | Name | Description 6 | -----------|------|------------- 7 | [DOC100](DOC100.md) | PlaceTextInParagraphs | A `` or `` documentation element contains content which is not wrapped in a block-level element. 8 | [DOC101](DOC101.md) | UseChildBlocksConsistently | The documentation for the element contains some text which is wrapped in block-level elements, and other text which is written inline. 9 | [DOC102](DOC102.md) | UseChildBlocksConsistentlyAcrossElementsOfTheSameKind | The documentation for the element contains inline text, but the documentation for a sibling element of the same kind uses block-level elements. 10 | [DOC103](DOC103.md) | UseUnicodeCharacters | The documentation contains an unnecessary or unrecognized HTML character entity. 11 | [DOC104](DOC104.md) | UseSeeLangword | The documentation contains a language keyword reference using `keyword` that can be converted to the preferred form ``. 12 | [DOC105](DOC105.md) | UseParamref | The documentation contains a parameter reference using `name` that can be converted to the preferred form ``. 13 | [DOC106](DOC106.md) | UseTypeparamref | The documentation contains a type parameter reference using `T` that can be converted to the preferred form ``. 14 | [DOC107](DOC107.md) | UseSeeCref | The documentation contains a code element reference using `name` that can be converted to the preferred form ``. 15 | [DOC108](DOC108.md) | AvoidEmptyParagraphs | The documentation contains an empty paragraph element (`` or `

      `) used as a paragraph separator. 16 | --------------------------------------------------------------------------------