diff --git a/.editorconfig b/.editorconfig index 804817bf..1e358090 100644 --- a/.editorconfig +++ b/.editorconfig @@ -254,3 +254,6 @@ dotnet_naming_style.end_in_async_style.required_suffix = Async # dotnet_naming_rule..severity = dotnet_naming_rule.async_methods_end_in_async.severity = warning + +# Remove unnecessary import https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0005 +dotnet_diagnostic.IDE0005.severity = warning diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1de772b..4cc1541d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,10 @@ on: - src/** - .github/workflows/** +env: + DOTNET_NOLOGO: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + jobs: test: strategy: @@ -26,9 +30,12 @@ jobs: - name: Install dependencies working-directory: src run: dotnet restore - env: - DOTNET_NOLOGO: true - DOTNET_CLI_TELEMETRY_OPTOUT: true + - name: Check formatting + if: ${{ startsWith(matrix.os, 'ubuntu') }} + working-directory: src + run: | + dotnet tool install -g dotnet-format --version 5.0.205101 --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json + dotnet format --check -v diag --fix-style warn --fix-analyzers warn || (echo "Run 'dotnet format' to fix formatting issues" && exit 1) - name: Build solution [Release] working-directory: src run: dotnet build --no-restore -c Release diff --git a/src/GraphQLParser.ApiTests/ApiApprovalTests.cs b/src/GraphQLParser.ApiTests/ApiApprovalTests.cs index df32100a..066ff006 100644 --- a/src/GraphQLParser.ApiTests/ApiApprovalTests.cs +++ b/src/GraphQLParser.ApiTests/ApiApprovalTests.cs @@ -1,3 +1,4 @@ +using System; using PublicApiGenerator; using Shouldly; using Xunit; @@ -6,13 +7,22 @@ namespace GraphQLParser.ApiTests { public class ApiApprovalTests { - [Fact] - public void Public_Api_Should_Not_Change_Inadvertently() + [Theory] + [InlineData(typeof(Lexer))] + public void Public_Api_Should_Not_Change_Inadvertently(Type type) { - typeof(Lexer).Assembly.GeneratePublicApi(new ApiGeneratorOptions + string publicApi = type.Assembly.GeneratePublicApi(new ApiGeneratorOptions { - IncludeAssemblyAttributes = false - }).ShouldMatchApproved(); + IncludeAssemblyAttributes = false, + //WhitelistedNamespacePrefixes = new[] { "Microsoft.Extensions.DependencyInjection" }, + ExcludeAttributes = new[] { "System.Diagnostics.DebuggerDisplayAttribute" } + }); + + // See: https://shouldly.readthedocs.io/en/latest/assertions/shouldMatchApproved.html + // Note: If the AssemblyName.approved.txt file doesn't match the latest publicApi value, + // this call will try to launch a diff tool to help you out but that can fail on + // your machine if a diff tool isn't configured/setup. + publicApi.ShouldMatchApproved(options => options.WithFilenameGenerator((testMethodInfo, discriminator, fileType, fileExtension) => $"{type.Assembly.GetName().Name}.{fileType}.{fileExtension}")); } } } diff --git a/src/GraphQLParser.ApiTests/ApiApprovalTests.Public_Api_Should_Not_Change_Inadvertently.approved.txt b/src/GraphQLParser.ApiTests/GraphQL-Parser.approved.txt similarity index 99% rename from src/GraphQLParser.ApiTests/ApiApprovalTests.Public_Api_Should_Not_Change_Inadvertently.approved.txt rename to src/GraphQLParser.ApiTests/GraphQL-Parser.approved.txt index 1354c930..ce24bfcd 100644 --- a/src/GraphQLParser.ApiTests/ApiApprovalTests.Public_Api_Should_Not_Change_Inadvertently.approved.txt +++ b/src/GraphQLParser.ApiTests/GraphQL-Parser.approved.txt @@ -172,7 +172,6 @@ namespace GraphQLParser.AST public System.Collections.Generic.List? Values { get; set; } public override string ToString() { } } - [System.Diagnostics.DebuggerDisplay("(Start={Start}, End={End})")] public readonly struct GraphQLLocation : System.IEquatable { public GraphQLLocation(int start, int end) { } @@ -183,7 +182,6 @@ namespace GraphQLParser.AST public override int GetHashCode() { } public override string ToString() { } } - [System.Diagnostics.DebuggerDisplay("{Value}")] public class GraphQLName : GraphQLParser.AST.ASTNode { public GraphQLName() { } diff --git a/src/GraphQLParser.Tests/Validation/LexerValidationTests.cs b/src/GraphQLParser.Tests/Validation/LexerValidationTests.cs index ebb69437..75d27a44 100644 --- a/src/GraphQLParser.Tests/Validation/LexerValidationTests.cs +++ b/src/GraphQLParser.Tests/Validation/LexerValidationTests.cs @@ -1,4 +1,3 @@ -using System; using GraphQLParser.Exceptions; using Shouldly; using Xunit; diff --git a/src/GraphQLParser.Tests/Validation/ParserValidationTests.cs b/src/GraphQLParser.Tests/Validation/ParserValidationTests.cs index 4fc0ce84..a46ba1f0 100644 --- a/src/GraphQLParser.Tests/Validation/ParserValidationTests.cs +++ b/src/GraphQLParser.Tests/Validation/ParserValidationTests.cs @@ -1,4 +1,3 @@ -using System; using GraphQLParser.Exceptions; using Shouldly; using Xunit; diff --git a/src/GraphQLParser/LexerContext.cs b/src/GraphQLParser/LexerContext.cs index c7a32114..00b68aaa 100644 --- a/src/GraphQLParser/LexerContext.cs +++ b/src/GraphQLParser/LexerContext.cs @@ -428,14 +428,5 @@ private void ValidateCharacterCode(int code) $"Invalid character \"\\u{code.ToString("D4")}\".", _source, _currentIndex); } } - - private int WaitForEndOfComment(string body, int position, char code) - { - while (++position < body.Length && (code = body[position]) != 0 && (code > 0x001F || code == 0x0009) && code != 0x000A && code != 0x000D) - { - } - - return position; - } } }