Skip to content

Commit

Permalink
Merge 48227e6 into ef1f91c
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell authored Apr 6, 2023
2 parents ef1f91c + 48227e6 commit e33fe40
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 39 deletions.
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />

<!-- Uncomment this to test unpublished builds from the AppVeyor feed. -->
<!--<add key="appveyor-stylecop" value="https://ci.appveyor.com/nuget/stylecopanalyzers" />-->
Expand Down
3 changes: 2 additions & 1 deletion StyleCop.Analyzers/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<WarningLevel>99</WarningLevel>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
Expand Down Expand Up @@ -47,7 +48,7 @@
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" PrivateAssets="all" />
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.46" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.5-beta1.23205.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.0.1" PrivateAssets="all" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace StyleCop.Analyzers.CodeGeneration
{
using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

Expand All @@ -13,7 +12,7 @@ public static TSyntax WithLeadingBlankLine<TSyntax>(this TSyntax syntax)
where TSyntax : SyntaxNode
{
return syntax.WithLeadingTrivia(SyntaxFactory.TriviaList(
SyntaxFactory.PreprocessingMessage(Environment.NewLine)));
SyntaxFactory.PreprocessingMessage(XmlSyntaxFactory.CrLf)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace StyleCop.Analyzers.CodeGeneration
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;

[Generator]
internal sealed class OperationLightupGenerator : IIncrementalGenerator
Expand Down Expand Up @@ -740,20 +739,20 @@ private void GenerateOperationWrapperHelper(in SourceProductionContext context,
SyntaxFactory.Trivia(SyntaxFactory.DocumentationComment(
SyntaxFactory.XmlText(" "),
SyntaxFactory.XmlSummaryElement(
SyntaxFactory.XmlNewLine(Environment.NewLine),
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation),
SyntaxFactory.XmlText(" Gets the type that is wrapped by the given wrapper."),
SyntaxFactory.XmlNewLine(Environment.NewLine),
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation),
SyntaxFactory.XmlText(" ")),
SyntaxFactory.XmlNewLine(Environment.NewLine),
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation),
SyntaxFactory.XmlText(" "),
SyntaxFactory.XmlParamElement(
"wrapperType",
SyntaxFactory.XmlText("Type of the wrapper for which the wrapped type should be retrieved.")),
SyntaxFactory.XmlNewLine(Environment.NewLine),
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation),
SyntaxFactory.XmlText(" "),
SyntaxFactory.XmlReturnsElement(
SyntaxFactory.XmlText("The wrapped type, or null if there is no info.")),
SyntaxFactory.XmlNewLine(Environment.NewLine).WithoutTrailingTrivia()))));
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation).WithoutTrailingTrivia()))));

var wrapperHelperClass = SyntaxFactory.ClassDeclaration(
attributeLists: default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace StyleCop.Analyzers.CodeGeneration
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
Expand All @@ -18,7 +17,6 @@ namespace StyleCop.Analyzers.CodeGeneration
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;

[Generator]
internal sealed class SyntaxLightupGenerator : IIncrementalGenerator
Expand Down Expand Up @@ -1198,20 +1196,20 @@ private void GenerateSyntaxWrapperHelper(in SourceProductionContext context, Imm
SyntaxFactory.Trivia(SyntaxFactory.DocumentationComment(
SyntaxFactory.XmlText(" "),
SyntaxFactory.XmlSummaryElement(
SyntaxFactory.XmlNewLine(Environment.NewLine),
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation),
SyntaxFactory.XmlText(" Gets the type that is wrapped by the given wrapper."),
SyntaxFactory.XmlNewLine(Environment.NewLine),
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation),
SyntaxFactory.XmlText(" ")),
SyntaxFactory.XmlNewLine(Environment.NewLine),
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation),
SyntaxFactory.XmlText(" "),
SyntaxFactory.XmlParamElement(
"wrapperType",
SyntaxFactory.XmlText("Type of the wrapper for which the wrapped type should be retrieved.")),
SyntaxFactory.XmlNewLine(Environment.NewLine),
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation),
SyntaxFactory.XmlText(" "),
SyntaxFactory.XmlReturnsElement(
SyntaxFactory.XmlText("The wrapped type, or null if there is no info.")),
SyntaxFactory.XmlNewLine(Environment.NewLine).WithoutTrailingTrivia()))));
SyntaxFactory.XmlText(XmlSyntaxFactory.XmlCarriageReturnLineFeedWithContinuation).WithoutTrailingTrivia()))));

var wrapperHelperClass = SyntaxFactory.ClassDeclaration(
attributeLists: default,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.CodeGeneration
{
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

internal static class XmlSyntaxFactory
{
public const string CrLf = "\r\n";

public static SyntaxToken XmlCarriageReturnLineFeedWithContinuation { get; } = SyntaxFactory.XmlTextNewLine(CrLf, continueXmlDocumentationComment: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<OutputType>Exe</OutputType>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>

<!-- Automatically generate the necessary assembly binding redirects -->
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private string ExpandDocumentation(Compilation compilation, DocumentationComment
{
var sb = new StringBuilder();

sb.AppendLine("<member>");
sb.Append("<member>\n");

foreach (XmlNodeSyntax xmlNode in documentCommentTrivia.Content)
{
Expand All @@ -177,11 +177,11 @@ private string ExpandDocumentation(Compilation compilation, DocumentationComment
}
else
{
sb.AppendLine(xmlNode.ToString());
sb.Append(xmlNode.ToString()).Append('\n');
}
}

sb.AppendLine("</member>");
sb.Append("</member>\n");

return sb.ToString();
}
Expand Down Expand Up @@ -209,7 +209,7 @@ private void ExpandIncludeTag(Compilation compilation, StringBuilder sb, XmlNode

foreach (var x in expandedInclude)
{
sb.AppendLine(x.ToString());
sb.Append(x.ToString()).Append('\n');
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions StyleCop.Analyzers/StyleCop.Analyzers/Helpers/FileHeaderHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal static FileHeader ParseFileHeader(SyntaxNode root)
fileHeaderStart = Math.Min(trivia.FullSpan.Start, fileHeaderStart);
fileHeaderEnd = trivia.FullSpan.End;

sb.AppendLine(commentString.Substring(2).Trim());
sb.Append(commentString.Substring(2).Trim()).Append('\n');
break;
case SyntaxKind.MultiLineCommentTrivia:
// only process a MultiLineCommentTrivia if no SingleLineCommentTrivia have been processed
Expand All @@ -79,7 +79,7 @@ internal static FileHeader ParseFileHeader(SyntaxNode root)
foreach (var part in triviaStringParts)
{
var trimmedPart = part.TrimStart(' ', '*');
sb.AppendLine(trimmedPart);
sb.Append(trimmedPart).Append('\n');
}

fileHeaderStart = trivia.FullSpan.Start;
Expand All @@ -106,9 +106,9 @@ internal static FileHeader ParseFileHeader(SyntaxNode root)

if (sb.Length > 0)
{
// remove the final newline
var eolLength = Environment.NewLine.Length;
sb.Remove(sb.Length - eolLength, eolLength);
// remove the final newline, which is always in '\n' form
const int EolLength = 1;
sb.Remove(sb.Length - EolLength, EolLength);
}

return new FileHeader(StringBuilderPool.ReturnAndFree(sb), fileHeaderStart, fileHeaderEnd);
Expand Down Expand Up @@ -179,7 +179,7 @@ private static string ProcessSingleLineCommentsHeader(SyntaxTriviaList triviaLis
fileHeaderEnd = int.MinValue;

// wrap the XML from the file header in a single root element to make XML parsing work.
sb.AppendLine("<root>");
sb.Append("<root>\n");

int i;
for (i = startIndex; !done && (i < triviaList.Count); i++)
Expand All @@ -206,7 +206,7 @@ private static string ProcessSingleLineCommentsHeader(SyntaxTriviaList triviaLis
fileHeaderStart = Math.Min(trivia.FullSpan.Start, fileHeaderStart);
fileHeaderEnd = trivia.FullSpan.End;

sb.AppendLine(commentString.Substring(2));
sb.Append(commentString.Substring(2)).Append('\n');
break;

case SyntaxKind.EndOfLineTrivia:
Expand All @@ -220,7 +220,7 @@ private static string ProcessSingleLineCommentsHeader(SyntaxTriviaList triviaLis
}
}

sb.AppendLine("</root>");
sb.Append("</root>\n");
return StringBuilderPool.ReturnAndFree(sb);
}

Expand All @@ -229,7 +229,7 @@ private static string ProcessMultiLineCommentsHeader(SyntaxTrivia multiLineComme
var sb = StringBuilderPool.Allocate();

// wrap the XML from the file header in a single root element to make XML parsing work.
sb.AppendLine("<root>");
sb.Append("<root>\n");

fileHeaderStart = multiLineComment.FullSpan.Start;
fileHeaderEnd = multiLineComment.FullSpan.End;
Expand All @@ -242,10 +242,10 @@ private static string ProcessMultiLineCommentsHeader(SyntaxTrivia multiLineComme

foreach (var commentLine in commentLines)
{
sb.AppendLine(commentLine.TrimStart(' ', '*'));
sb.Append(commentLine.TrimStart(' ', '*')).Append('\n');
}

sb.AppendLine("</root>");
sb.Append("</root>\n");
return StringBuilderPool.ReturnAndFree(sb);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ internal class ObjectPool<T>
private T firstItem;

internal ObjectPool(Func<T> factory)
#pragma warning disable RS1035 // Do not use APIs banned for analyzers (false positive: https://github.com/dotnet/roslyn-analyzers/issues/6571)
: this(factory, Environment.ProcessorCount * 2)
#pragma warning restore RS1035 // Do not use APIs banned for analyzers
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class SA0001XmlCommentAnalysisDisabled : DiagnosticAnalyzer
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(SpecialResources.SA0001Description), SpecialResources.ResourceManager, typeof(SpecialResources));

private static readonly DiagnosticDescriptor Descriptor =
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink, customTags: new string[] { "CompilationEnd" });

private static readonly Action<CompilationStartAnalysisContext> CompilationStartAction = HandleCompilationStart;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.SpecialRules
{
using System;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using LightJson.Serialization;
using Microsoft.CodeAnalysis;
Expand All @@ -31,7 +30,7 @@ internal class SA0002InvalidSettingsFile : DiagnosticAnalyzer

private static readonly DiagnosticDescriptor Descriptor =
#pragma warning disable RS1033 // Define diagnostic description correctly (Description ends with formatted exception text)
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink, customTags: new[] { "CompilationEnd" });
#pragma warning restore RS1033 // Define diagnostic description correctly

private static readonly Action<CompilationAnalysisContext> CompilationAction = HandleCompilation;
Expand Down Expand Up @@ -63,11 +62,7 @@ private static void HandleCompilation(CompilationAnalysisContext context)
}
catch (Exception ex) when (ex is JsonParseException || ex is InvalidSettingsException)
{
string details = ex.Message;
string completeDescription = string.Format(Description.ToString(CultureInfo.CurrentCulture), details);

var completeDescriptor = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, completeDescription, HelpLink);
context.ReportDiagnostic(Diagnostic.Create(completeDescriptor, Location.None));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, Location.None, ex.Message));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions StyleCop.Analyzers/StyleCopTester/StyleCopTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net46</TargetFrameworks>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>

<!-- Automatically generate the necessary assembly binding redirects -->
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down

0 comments on commit e33fe40

Please sign in to comment.