Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<VersionPrefix>8.0.0-preview</VersionPrefix>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);CA1707</NoWarn>
<WarningsNotAsErrors>CS8766</WarningsNotAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>Marek Magdziak</Authors>
Expand All @@ -19,9 +20,10 @@
<!-- https://github.com/clairernovotny/DeterministicBuilds -->
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">True</ContinuousIntegrationBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>Recommended</AnalysisMode>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<PackageReadmeFile Condition="'$(IsPackable)' == 'true'">README.md</PackageReadmeFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\graphql.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQLParser.ApiTests/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Public_Api_Should_Not_Change_Inadvertently(Type type)
string[] tfms = project.Descendants("TargetFrameworks").Union(project.Descendants("TargetFramework")).First().Value.Split(";", StringSplitOptions.RemoveEmptyEntries);

// There may be old stuff from earlier builds like net45, netcoreapp3.0, etc. so filter it out
string[] actualTfmDirs = Directory.GetDirectories(buildDir).Where(dir => tfms.Any(tfm => dir.EndsWith(tfm))).ToArray();
string[] actualTfmDirs = Directory.GetDirectories(buildDir).Where(dir => tfms.Any(tfm => dir.EndsWith(tfm, StringComparison.InvariantCulture))).ToArray();
Debug.Assert(actualTfmDirs.Length > 0, $"Directory '{buildDir}' doesn't contain subdirectories matching {string.Join(";", tfms)}");

(string tfm, string content)[] publicApi = actualTfmDirs.Select(tfmDir => (new DirectoryInfo(tfmDir).Name.Replace(".", ""), Assembly.LoadFile(Path.Combine(tfmDir, projectName + ".dll")).GeneratePublicApi(new ApiGeneratorOptions
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQLParser.ApiTests/GraphQLParser.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ namespace GraphQLParser.Visitors
public DefaultPrintContext(System.IO.TextWriter writer) { }
public int IndentLevel { get; set; }
public bool IndentPrinted { get; set; }
[System.Obsolete]
[System.Obsolete("Use LastVisitedNode instead")]
public bool LastDefinitionPrinted { get; set; }
public GraphQLParser.AST.ASTNode? LastVisitedNode { get; set; }
public bool NewLinePrinted { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQLParser.Benchmarks/Benchmarks/BenchmarkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public string GetQueryByName(string name)
"params" => _params,
"variables" => _variables,
"github" => _github,
_ => throw new System.Exception(name)
_ => throw new ArgumentException(name, nameof(name))
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/GraphQLParser.Benchmarks/Benchmarks/ParserBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ namespace GraphQLParser.Benchmarks;
//[RPlotExporter, CsvMeasurementsExporter]
public class ParserBenchmark : BenchmarkBase
{
private class Config : ManualConfig
private sealed class Config : ManualConfig
{
public Config()
{
SummaryStyle = new SummaryStyle(CultureInfo.InvariantCulture, printUnitsInHeader: true, sizeUnit: SizeUnit.B, timeUnit: TimeUnit.Microsecond, printUnitsInContent: false, printZeroValuesInContent: false, maxParameterColumnWidth: 40);
Orderer = new ParserOrderer();
}

private class ParserOrderer : IOrderer
private sealed class ParserOrderer : IOrderer
{
private static int GetOrder(object o) => o switch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net7</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);1591</NoWarn>
<NoWarn>$(NoWarn);1591;CA1822</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/GraphQLParser.Tests/GraphQLParser.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<PropertyGroup>
<SingleTestPlatform Condition="'$(SingleTestPlatform)' == ''">false</SingleTestPlatform>
<Nullable>disable</Nullable>
<NoWarn>$(NoWarn);1591;IDE0008;IDE0022;IDE0058;IDE1006</NoWarn>
<NoWarn>$(NoWarn);1591;CA2012;IDE0008;IDE0022;IDE0058;IDE1006</NoWarn>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(SingleTestPlatform)' == 'true'">
Expand Down
5 changes: 3 additions & 2 deletions src/GraphQLParser.Tests/ParserTests.Throw.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using GraphQLParser.Exceptions;

namespace GraphQLParser.Tests;
Expand Down Expand Up @@ -216,7 +217,7 @@ public void Should_Throw_GraphQLSyntaxErrorException(int number, string text, st
{
var ex = Should.Throw<GraphQLSyntaxErrorException>(() => text.Parse());
ex.Message.ShouldContain(ex.Description);
ex.Description.ShouldBe(description, number.ToString());
ex.Description.ShouldBe(description, number.ToString(CultureInfo.InvariantCulture));
ex.Location.Line.ShouldBe(line);
ex.Location.Column.ShouldBe(column);
}
Expand Down Expand Up @@ -261,7 +262,7 @@ public void Should_Throw_On_Empty_Types_With_Braces(int number, string text, str
{
var ex = Should.Throw<GraphQLSyntaxErrorException>(() => text.Parse());
ex.Message.ShouldContain(ex.Description);
ex.Description.ShouldBe(description, number.ToString());
ex.Description.ShouldBe(description, number.ToString(CultureInfo.InvariantCulture));
ex.Location.Line.ShouldBe(line);
ex.Location.Column.ShouldBe(column);
}
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQLParser.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public void Comments_on_Variable_Should_Read_Correctly(IgnoreOptions options)
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_On_SelectionSet_Should_Read_Correctly(IgnoreOptions options)
public void Comments_On_Fields_Should_Read_Correctly(IgnoreOptions options)
{
var document = @"
query {
Expand Down
21 changes: 11 additions & 10 deletions src/GraphQLParser.Tests/Values/GraphQLIntValueTests.cs
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
using System.Globalization;
using System.Numerics;

namespace GraphQLParser.Tests;

public class GraphQLIntValueTests
{
[Fact]
public void Int()
public void IntValue_From_Int()
{
var value = new GraphQLIntValue(1234567);
value.Value.Length.ShouldBe(7);
value.Value.ShouldBe("1234567");
}

[Fact]
public void Byte()
public void IntValue_From_Byte()
{
var value = new GraphQLIntValue((byte)42);
value.Value.Length.ShouldBe(2);
value.Value.ShouldBe("42");
}

[Fact]
public void Sbyte()
public void IntValue_From_Sbyte()
{
var value = new GraphQLIntValue((sbyte)-10);
value.Value.Length.ShouldBe(3);
value.Value.ShouldBe("-10");
}

[Fact]
public void Short()
public void IntValue_From_Short()
{
var value = new GraphQLIntValue((short)-300);
value.Value.Length.ShouldBe(4);
value.Value.ShouldBe("-300");
}

[Fact]
public void Ushort()
public void IntValue_From_Ushort()
{
var value = new GraphQLIntValue((ushort)60000);
value.Value.Length.ShouldBe(5);
value.Value.ShouldBe("60000");
}

[Fact]
public void Uint()
public void IntValue_From_Uint()
{
var value = new GraphQLIntValue(2247483647U);
value.Value.Length.ShouldBe(10);
value.Value.ShouldBe("2247483647");
}

[Fact]
public void Long()
public void IntValue_From_Long()
{
var value = new GraphQLIntValue(-60001L);
value.Value.Length.ShouldBe(6);
value.Value.ShouldBe("-60001");
}

[Fact]
public void Ulong()
public void IntValue_From_Ulong()
{
var value = new GraphQLIntValue(9223372036854775808UL);
value.Value.Length.ShouldBe(19);
value.Value.ShouldBe("9223372036854775808");
}

[Fact]
public void BigInt()
public void IntValue_From_BigInt()
{
var value = new GraphQLIntValue(BigInteger.Parse("7922816251426433759354395033579228162514264337593543950335"));
var value = new GraphQLIntValue(BigInteger.Parse("7922816251426433759354395033579228162514264337593543950335", CultureInfo.InvariantCulture));
value.Value.Length.ShouldBe(58);
value.Value.ShouldBe("7922816251426433759354395033579228162514264337593543950335");
}
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQLParser.Tests/Values/GraphQLNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void GraphQLName_Explicit_Cast()
((string)nameNull).ShouldBeNull();
}

private ROM FuncROM(ROM r) => r;
private static ROM FuncROM(ROM r) => r;

private string FuncString(string s) => s;
private static string FuncString(string s) => s;
}
6 changes: 3 additions & 3 deletions src/GraphQLParser.Tests/Visitors/ASTVisitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace GraphQLParser.Tests.Visitors;

public class ASTVisitorTests
{
private class Context : IASTVisitorContext
private sealed class Context : IASTVisitorContext
{
public CancellationToken CancellationToken { get; set; }
}

private class MySuperNode : ASTNode
private sealed class MySuperNode : ASTNode
{
public override ASTNodeKind Kind => (ASTNodeKind)12345;
}
Expand Down Expand Up @@ -43,7 +43,7 @@ public void ASTVisitor_Should_Respect_CancellationToken()
Should.Throw<OperationCanceledException>(() => visitor.VisitAsync(document, context).GetAwaiter().GetResult());
}

private class MyVisitor : ASTVisitor<Context>
private sealed class MyVisitor : ASTVisitor<Context>
{
protected override async ValueTask VisitScalarTypeDefinitionAsync(GraphQLScalarTypeDefinition scalarTypeDefinition, Context context)
{
Expand Down
7 changes: 3 additions & 4 deletions src/GraphQLParser.Tests/Visitors/GraphQLAstVisitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace GraphQLParser.Tests.Visitors;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly", Justification = "CountVisitor is sync")]
public class GraphQLAstVisitorTests
{
public class CountVisitor : ASTVisitor<CountContext>
internal sealed class CountVisitor : ASTVisitor<CountContext>
{
protected override async ValueTask VisitBooleanValueAsync(GraphQLBooleanValue booleanValue, CountContext context)
{
Expand Down Expand Up @@ -180,7 +179,7 @@ protected override async ValueTask VisitSchemaDefinitionAsync(GraphQLSchemaDefin
}
}

public class CountContext : IASTVisitorContext
internal sealed class CountContext : IASTVisitorContext
{
public List<GraphQLAlias> VisitedAliases = new();
public List<GraphQLArgument> VisitedArguments = new();
Expand All @@ -205,7 +204,7 @@ public class CountContext : IASTVisitorContext

private readonly CountVisitor _visitor = new();

public CountContext Context = new();
private CountContext Context { get; } = new();

[Theory]
[InlineData(IgnoreOptions.None)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public async Task SDLPrinter_Should_Throw_On_Unknown_Values(string text)
ex.Message.ShouldStartWith("Unknown ");
}

private class Context : IASTVisitorContext
private sealed class Context : IASTVisitorContext
{
public CancellationToken CancellationToken { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task Printer_Should_Print_Pretty_If_Directives_Skipped(
actual.Parse(); // should be parsed back
}

private class MyPrinter : SDLPrinter
private sealed class MyPrinter : SDLPrinter
{
protected override ValueTask VisitDirectiveAsync(GraphQLDirective directive, DefaultPrintContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public async Task Printer_Should_Print_Pretty_If_Definitions_Skipped(
actual.Parse(); // should be parsed back
}

private class PrintOnlyStartsWithA : SDLPrinter
private sealed class PrintOnlyStartsWithA : SDLPrinter
{
protected override ValueTask MakeVerticalIndentationBetweenTopLevelDefinitions(ASTNode node, DefaultPrintContext context)
{
Expand Down
2 changes: 2 additions & 0 deletions src/GraphQLParser/AST/Enums/DirectiveLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public enum DirectiveLocation

/// <summary>Location adjacent to an object type definition.</summary>
[Description("Location adjacent to an object type definition.")]
#pragma warning disable CA1720 // Identifiers should not contain type names
Object,
#pragma warning restore CA1720

/// <summary>Location adjacent to a field definition.</summary>
[Description("Location adjacent to a field definition.")]
Expand Down
9 changes: 5 additions & 4 deletions src/GraphQLParser/Exceptions/GraphQLParserException.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Text;

namespace GraphQLParser.Exceptions;
Expand Down Expand Up @@ -42,9 +43,9 @@ private static string ComposeMessage(string description, ReadOnlySpan<char> sour
private static string HighlightSourceAtLocation(ReadOnlySpan<char> source, Location location)
{
int line = location.Line;
string prevLineNum = (line - 1).ToString();
string lineNum = line.ToString();
string nextLineNum = (line + 1).ToString();
string prevLineNum = (line - 1).ToString(CultureInfo.InvariantCulture);
string lineNum = line.ToString(CultureInfo.InvariantCulture);
string nextLineNum = (line + 1).ToString(CultureInfo.InvariantCulture);
int padLen = nextLineNum.Length;
string[] lines = source
.ToString()
Expand Down Expand Up @@ -80,7 +81,7 @@ private static string ReplaceWithUnicodeRepresentation(string str)
{
if (IsReplacementCharacter(code))
{
buffer.Append("\\u").Append(((int)code).ToString("D4"));
buffer.Append("\\u").Append(((int)code).ToString("D4", CultureInfo.InvariantCulture));
}
else
{
Expand Down
9 changes: 7 additions & 2 deletions src/GraphQLParser/Extensions/ASTNodeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using GraphQLParser.AST;
using GraphQLParser.Visitors;

Expand All @@ -17,7 +18,9 @@ public static int AllNestedCount(this ASTNode node)
{
var visitor = new CountVisitor<DefaultCountContext>();
var context = new DefaultCountContext(_ => true);
visitor.VisitAsync(node, context).GetAwaiter().GetResult(); // it's safe since method is actually sync
var task = visitor.VisitAsync(node, context);
Debug.Assert(task.IsCompleted);
task.GetAwaiter().GetResult(); // it's safe since method is actually sync that is verified by Debug.Assert
return context.Count;
}

Expand All @@ -30,7 +33,9 @@ public static int MaxNestedDepth(this ASTNode node)
{
var visitor = new MaxDepthVisitor<DefaultMaxDepthContext>();
var context = new DefaultMaxDepthContext();
visitor.VisitAsync(node, context).GetAwaiter().GetResult(); // it's safe since method is actually sync
var task = visitor.VisitAsync(node, context);
Debug.Assert(task.IsCompleted);
task.GetAwaiter().GetResult(); // it's safe since method is actually sync that is verified by Debug.Assert
return context.MaxDepth;
}

Expand Down
4 changes: 4 additions & 0 deletions src/GraphQLParser/TokenKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public enum TokenKind
/// </summary>
NAME = 15,

#pragma warning disable CA1720 // Identifiers should not contain type names

/// <summary>
/// An integer number is specified without a decimal point or exponent (ex. 1).
/// </summary>
Expand Down Expand Up @@ -110,6 +112,8 @@ public enum TokenKind
/// </remarks>
STRING = 18,

#pragma warning restore CA1720

/// <summary>
/// GraphQL source documents may contain single‐line comments, starting with the # marker.
/// A comment can contain any Unicode code point except LineTerminator so a comment always
Expand Down
2 changes: 2 additions & 0 deletions src/GraphQLParser/Visitors/ASTVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ protected virtual async ValueTask VisitSelectionSetAsync(GraphQLSelectionSet sel
/// <summary>
/// Visits <see cref="GraphQLAlias"/> node.
/// </summary>
#pragma warning disable CA1716 // Identifiers should not match keywords (alias)
protected virtual async ValueTask VisitAliasAsync(GraphQLAlias alias, TContext context)
#pragma warning restore CA1716
{
await VisitAsync(alias.Comments, context).ConfigureAwait(false);
await VisitAsync(alias.Name, context).ConfigureAwait(false);
Expand Down
Loading