Skip to content

Commit

Permalink
Merged from master
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornhellander committed Dec 19, 2023
2 parents baebf75 + 0fc865d commit ce89120
Show file tree
Hide file tree
Showing 2,033 changed files with 15,013 additions and 8,442 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ OpenCover.Symbols/
.nuget/NuGet.exe
build/nuget/
*.log
StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/

# Visual Studio performance tools
*.psess
Expand Down
4 changes: 2 additions & 2 deletions .nuget/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Codecov" version="1.9.0" />
<package id="CodecovUploader" version="0.7.1" />
<package id="OpenCover" version="4.6.519" />
<package id="ReportGenerator" version="2.3.5.0" targetFramework="net452" />
<package id="ReportGenerator" version="5.2.0" />
<package id="xunit.runner.console" version="2.4.1" />
</packages>
10 changes: 7 additions & 3 deletions StyleCop.Analyzers/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<NoWarn>$(NoWarn),1573,1591,1712</NoWarn>
</PropertyGroup>

<PropertyGroup>
<SharedMicrosoftCodeAnalysisAnalyzersVersion>3.11.0-beta1.23472.1</SharedMicrosoftCodeAnalysisAnalyzersVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="2.2.13" PrivateAssets="all" />
</ItemGroup>
Expand All @@ -48,12 +52,12 @@
<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.5-beta1.23223.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.0.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="3.3.5-beta1.23223.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
</ItemGroup>

<!-- C# Compiler -->
Expand All @@ -63,7 +67,7 @@

<!-- Public API -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="2.9.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace StyleCop.Analyzers.DocumentationRules
using System;
using System.Collections.Immutable;
using System.Composition;
using System.Globalization;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
Expand All @@ -20,6 +20,7 @@ namespace StyleCop.Analyzers.DocumentationRules
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Formatting;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Lightup;

/// <summary>
/// Implements a code fix for <see cref="SA1642ConstructorSummaryDocumentationMustBeginWithStandardText"/>
Expand Down Expand Up @@ -83,7 +84,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)

internal static ImmutableArray<string> GenerateStandardText(Document document, BaseMethodDeclarationSyntax methodDeclaration, BaseTypeDeclarationSyntax typeDeclaration, CancellationToken cancellationToken)
{
bool isStruct = typeDeclaration.IsKind(SyntaxKind.StructDeclaration);
bool isStruct = typeDeclaration.IsKind(SyntaxKind.StructDeclaration) || typeDeclaration.IsKind(SyntaxKindEx.RecordStructDeclaration);
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(methodDeclaration.SyntaxTree, cancellationToken);
var culture = settings.DocumentationRules.DocumentationCultureInfo;
var resourceManager = DocumentationResources.ResourceManager;
Expand Down Expand Up @@ -147,7 +148,19 @@ private static TypeParameterListSyntax GetTypeParameterList(BaseTypeDeclarationS
return classDeclaration.TypeParameterList;
}

return (typeDeclaration as StructDeclarationSyntax)?.TypeParameterList;
if (typeDeclaration is StructDeclarationSyntax structDeclaration)
{
return structDeclaration.TypeParameterList;
}

if (RecordDeclarationSyntaxWrapper.IsInstance(typeDeclaration))
{
var recordDeclaration = (RecordDeclarationSyntaxWrapper)typeDeclaration;
return recordDeclaration.TypeParameterList;
}

Debug.Assert(false, $"Unhandled type {typeDeclaration.Kind()}");
return null;
}

private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, XmlElementSyntax node, CancellationToken cancellationToken)
Expand Down Expand Up @@ -202,21 +215,10 @@ private static bool IsMultiLine(XmlElementSyntax node)
private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, XmlEmptyElementSyntax node)
{
var typeDeclaration = node.FirstAncestorOrSelf<BaseTypeDeclarationSyntax>();

TypeParameterListSyntax typeParameterList;
if (typeDeclaration is ClassDeclarationSyntax classDeclaration)
{
typeParameterList = classDeclaration.TypeParameterList;
}
else
{
typeParameterList = (typeDeclaration as StructDeclarationSyntax)?.TypeParameterList;
}
var typeParameterList = GetTypeParameterList(typeDeclaration);

var newRoot = root.ReplaceNode(node, BuildSeeElement(typeDeclaration.Identifier, typeParameterList));

var newDocument = document.WithSyntaxRoot(newRoot);

return Task.FromResult(newDocument);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
[assembly: InternalsVisibleTo("StyleCop.Analyzers.Test.CSharp9, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]
[assembly: InternalsVisibleTo("StyleCop.Analyzers.Test.CSharp10, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]
[assembly: InternalsVisibleTo("StyleCop.Analyzers.Test.CSharp11, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]
[assembly: InternalsVisibleTo("StyleCop.Analyzers.Test.CSharp12, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]
[assembly: InternalsVisibleTo("StyleCopTester, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c36d40d996fcc95fb6a89754728616758f459026e31478ce93633b3e27a4af416f103aa3d7a9e7998f829f8715cc1240d30724fd662042550fa71357b19562622424267e9e4640c403edbe64709a9ca5918128a9b9020b0db6e770d0dd1eac888869c23a835b74bde00e171984b1d1c24636cf030f0b23106e73035a2be145a6")]
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ private static bool IsEnumWithDefaultMember(INamedTypeSymbol namedTypeSymbol, ou
/// <returns>A new member access expression.</returns>
private static SyntaxNode ConstructMemberAccessSyntax(TypeSyntax typeSyntax, string memberName)
{
// NOTE: This creates the correct source code when applied, but these are not necessarily the syntax
// nodes that the compiler would create from that source code. For example, the type syntax can
// contain QualifiedName nodes, whereas the compiler would have created SimpleMemberAccessExpression instead.
// This means that the validation that happens in the tests need to be turned off for some tests.
// We could have transformed the nodes to match, but we keep the code simple instead.
return SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
typeSyntax,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,48 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen

private static BinaryExpressionSyntax TransformExpression(BinaryExpressionSyntax binaryExpression)
{
// NOTE: This code also changes the syntax node kind, besides the operator token. The modified source code would
// have been the same without this, but we do this to make tests pass with the default CodeActionValidationMode.
var newLeft = binaryExpression.Right.WithTriviaFrom(binaryExpression.Left);
var newRight = binaryExpression.Left.WithTriviaFrom(binaryExpression.Right);
return binaryExpression.WithLeft(newLeft).WithRight(newRight).WithOperatorToken(GetCorrectOperatorToken(binaryExpression.OperatorToken));
GetReplacementInfo(binaryExpression.OperatorToken, out var newOperatorToken, out var newNodeKind);
return SyntaxFactory.BinaryExpression(newNodeKind, newLeft, newOperatorToken, newRight);
}

private static SyntaxToken GetCorrectOperatorToken(SyntaxToken operatorToken)
private static void GetReplacementInfo(SyntaxToken operatorToken, out SyntaxToken newToken, out SyntaxKind newNodeKind)
{
switch (operatorToken.Kind())
{
case SyntaxKind.EqualsEqualsToken:
case SyntaxKind.ExclamationEqualsToken:
return operatorToken;
newToken = operatorToken;
newNodeKind = operatorToken.Parent.Kind();
break;

case SyntaxKind.GreaterThanToken:
return SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.LessThanToken, operatorToken.TrailingTrivia);
newToken = SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.LessThanToken, operatorToken.TrailingTrivia);
newNodeKind = SyntaxKind.LessThanExpression;
break;

case SyntaxKind.GreaterThanEqualsToken:
return SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.LessThanEqualsToken, operatorToken.TrailingTrivia);
newToken = SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.LessThanEqualsToken, operatorToken.TrailingTrivia);
newNodeKind = SyntaxKind.LessThanOrEqualExpression;
break;

case SyntaxKind.LessThanToken:
return SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.GreaterThanToken, operatorToken.TrailingTrivia);
newToken = SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.GreaterThanToken, operatorToken.TrailingTrivia);
newNodeKind = SyntaxKind.GreaterThanExpression;
break;

case SyntaxKind.LessThanEqualsToken:
return SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.GreaterThanEqualsToken, operatorToken.TrailingTrivia);
newToken = SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.GreaterThanEqualsToken, operatorToken.TrailingTrivia);
newNodeKind = SyntaxKind.GreaterThanOrEqualExpression;
break;

default:
return SyntaxFactory.Token(SyntaxKind.None);
newToken = SyntaxFactory.Token(SyntaxKind.None);
newNodeKind = (SyntaxKind)operatorToken.Parent.RawKind;
break;
}
}

Expand Down
Loading

0 comments on commit ce89120

Please sign in to comment.