Skip to content

Commit

Permalink
Merge b00056d into d1c94ed
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell authored Sep 28, 2023
2 parents d1c94ed + b00056d commit 106ccde
Show file tree
Hide file tree
Showing 17 changed files with 1,716 additions and 22 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
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 @@ -921,7 +921,7 @@ public DocumentData(XDocument document)
continue;
}

if (!operationKinds.TryGetValue(node.Attribute("Name").Value, out var kinds))
if (!operationKinds.TryGetValue(node.RequiredAttribute("Name").Value, out var kinds))
{
kinds = ImmutableArray<(string name, int value, string? extraDescription)>.Empty;
}
Expand All @@ -937,7 +937,7 @@ public DocumentData(XDocument document)
continue;
}

if (!operationKinds.TryGetValue(node.Attribute("Name").Value, out var kinds))
if (!operationKinds.TryGetValue(node.RequiredAttribute("Name").Value, out var kinds))
{
kinds = ImmutableArray<(string name, int value, string? extraDescription)>.Empty;
}
Expand Down Expand Up @@ -987,11 +987,11 @@ public DocumentData(XDocument document)
continue;
}

int parsedValue = ParsePrefixHexValue(entry.Attribute("Value").Value);
nodeBuilder.Add((entry.Attribute("Name").Value, parsedValue, entry.Attribute("ExtraDescription")?.Value));
int parsedValue = ParsePrefixHexValue(entry.RequiredAttribute("Value").Value);
nodeBuilder.Add((entry.RequiredAttribute("Name").Value, parsedValue, entry.Attribute("ExtraDescription")?.Value));
}

builder.Add(node.Attribute("Name").Value, nodeBuilder.ToImmutable());
builder.Add(node.RequiredAttribute("Name").Value, nodeBuilder.ToImmutable());
continue;
}
}
Expand All @@ -1008,7 +1008,7 @@ public DocumentData(XDocument document)
operationKind++;
}

var nodeName = node.Attribute("Name").Value;
var nodeName = node.RequiredAttribute("Name").Value;
var kindName = nodeName.Substring("I".Length, nodeName.Length - "I".Length - "Operation".Length);
builder.Add(nodeName, ImmutableArray.Create((kindName, operationKind, (string?)null)));
}
Expand All @@ -1021,12 +1021,12 @@ private static ImmutableHashSet<int> GetSkippedOperationKinds(XDocument document
var builder = ImmutableHashSet.CreateBuilder<int>();
foreach (var skippedKind in document.XPathSelectElements("/Tree/UnusedOperationKinds/Entry"))
{
builder.Add(ParsePrefixHexValue(skippedKind.Attribute("Value").Value));
builder.Add(ParsePrefixHexValue(skippedKind.RequiredAttribute("Value").Value));
}

foreach (var explicitKind in document.XPathSelectElements("/Tree/*/OperationKind/Entry"))
{
builder.Add(ParsePrefixHexValue(explicitKind.Attribute("Value").Value));
builder.Add(ParsePrefixHexValue(explicitKind.RequiredAttribute("Value").Value));
}

return builder.ToImmutable();
Expand All @@ -1052,7 +1052,7 @@ public InterfaceData(DocumentData documentData, XElement node, ImmutableArray<(s
this.documentData = documentData;

this.OperationKinds = operationKinds;
this.InterfaceName = node.Attribute("Name").Value;
this.InterfaceName = node.RequiredAttribute("Name").Value;

if (node.Attribute("Namespace") is { } namespaceNode)
{
Expand Down Expand Up @@ -1127,9 +1127,9 @@ private sealed class PropertyData
{
public PropertyData(XElement node)
{
this.Name = node.Attribute("Name").Value;
this.Name = node.RequiredAttribute("Name").Value;
this.AccessorName = this.Name + "Accessor";
this.Type = node.Attribute("Type").Value;
this.Type = node.RequiredAttribute("Type").Value;

this.IsNew = node.Attribute("New")?.Value == "true";
this.IsPublicProperty = node.Attribute("Internal")?.Value != "true";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,12 @@ private sealed class SyntaxData
public SyntaxData(CompilationData compilationData, XDocument document)
{
var nodesBuilder = ImmutableArray.CreateBuilder<NodeData>();
foreach (var element in document.XPathSelectElement("/Tree[@Root='SyntaxNode']").XPathSelectElements("PredefinedNode|AbstractNode|Node"))
if (document.XPathSelectElement("/Tree[@Root='SyntaxNode']") is { } tree)
{
nodesBuilder.Add(new NodeData(compilationData, element));
foreach (var element in tree.XPathSelectElements("PredefinedNode|AbstractNode|Node"))
{
nodesBuilder.Add(new NodeData(compilationData, element));
}
}

this.Nodes = nodesBuilder.ToImmutable();
Expand Down Expand Up @@ -1303,7 +1306,7 @@ public NodeData(CompilationData compilationData, XElement element)
_ => throw new NotSupportedException($"Unknown element name '{element.Name}'"),
};

this.Name = element.Attribute("Name").Value;
this.Name = element.RequiredAttribute("Name").Value;

this.ExistingType = compilationData.ExistingTypes.GetValueOrDefault($"Microsoft.CodeAnalysis.CSharp.Syntax.{this.Name}")
?? compilationData.ExistingTypes.GetValueOrDefault($"Microsoft.CodeAnalysis.CSharp.{this.Name}")
Expand All @@ -1317,7 +1320,7 @@ public NodeData(CompilationData compilationData, XElement element)
this.WrapperName = this.Name + "Wrapper";
}

this.BaseName = element.Attribute("Base").Value;
this.BaseName = element.RequiredAttribute("Base").Value;
this.Fields = element.XPathSelectElements("descendant::Field").Select(field => new FieldData(this, field)).ToImmutableArray();
}

Expand Down Expand Up @@ -1347,9 +1350,9 @@ public FieldData(NodeData nodeData, XElement element)
{
this.nodeData = nodeData;

this.Name = element.Attribute("Name").Value;
this.Name = element.RequiredAttribute("Name").Value;

var type = element.Attribute("Type").Value;
var type = element.RequiredAttribute("Type").Value;
this.Type = type switch
{
"SyntaxList<SyntaxToken>" => nameof(SyntaxTokenList),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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 System;
using System.Xml.Linq;

internal static class XElementExtensions
{
public static XAttribute RequiredAttribute(this XElement element, XName name)
=> element.Attribute(name) ?? throw new InvalidOperationException($"Expected attribute '{name}'");
}
}
6 changes: 6 additions & 0 deletions StyleCop.Analyzers/StyleCop.Analyzers.Internal.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<Rule Id="RS1001" Action="None" /> <!-- Missing diagnostic analyzer attribute -->
<Rule Id="RS1004" Action="None" /> <!-- Recommend adding language support to diagnostic analyzer -->
<Rule Id="RS1029" Action="None" /> <!-- Do not use reserved diagnostic IDs -->
<Rule Id="RS1038" Action="None" /> <!-- Compiler extensions should be implemented in assemblies with compiler-provided references -->
<Rule Id="RS2008" Action="None" /> <!-- Enable analyzer release tracking -->
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.PublicApiAnalyzers" RuleNamespace="Microsoft.CodeAnalysis.PublicApiAnalyzers">
<Rule Id="RS0016" Action="None" /> <!-- Add public types and members to the declared API -->
<Rule Id="RS0026" Action="None" /> <!-- Do not add multiple public overloads with optional parameters -->
<Rule Id="RS0037" Action="None" /> <!-- Enable tracking of nullability of reference types in the declared API -->
</Rules>
</RuleSet>
Loading

0 comments on commit 106ccde

Please sign in to comment.