From 02b94ba9dc135200ac44c4b22c2f242f78540e3e Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Mon, 4 Jan 2021 17:49:48 +0300 Subject: [PATCH] Remove setters from ISource/Source (#97) --- .github/labeler.yml | 10 ++++----- .github/workflows/label.yml | 4 +++- .github/workflows/publish-release.yml | 18 ++++++++++++++++ src/Directory.Build.props | 3 ++- ...ould_Not_Change_Inadvertently.approved.txt | 9 ++++---- src/GraphQLParser.Tests/LexerTests.cs | 1 - src/GraphQLParser.sln | 1 - src/GraphQLParser/AST/GraphQLLocation.cs | 4 +--- src/GraphQLParser/ISource.cs | 8 +++---- src/GraphQLParser/Location.cs | 21 +++++++++++++------ src/GraphQLParser/ParserContext.cs | 21 +++++++++---------- src/GraphQLParser/Source.cs | 4 ++-- 12 files changed, 65 insertions(+), 39 deletions(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index 27698571..7a0639e7 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,15 +1,15 @@ -"test": +test: - src/GraphQLParser.ApiTests/**/* - src/GraphQLParser.Tests/**/* -"CI": +CI: - .github/workflows/**/* -"code style": +code style: - .editorconfig -"documentation": +documentation: - README.md -"performance": +performance: - src/GraphQLParser.Benchmarks/**/* diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 9b2d0c9e..7ac774f4 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -12,6 +12,8 @@ jobs: label: runs-on: ubuntu-latest steps: - - uses: actions/labeler@v2 + - uses: actions/labeler@v3 with: + sync-labels: "" repo-token: "${{ secrets.GITHUB_TOKEN }}" + continue-on-error: true diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 0d1ddb7f..0c86fa39 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -51,3 +51,21 @@ jobs: - name: Publish Nuget packages to Nuget registry working-directory: src run: dotnet nuget push "out/*" -k ${{secrets.NUGET_AUTH_TOKEN}} + - name: Upload Nuget packages as release artifacts + uses: actions/github-script@v2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + console.log('environment', process.versions); + const fs = require('fs').promises; + const { repo: { owner, repo }, sha } = context; + for (let file of await fs.readdir('src/out')) { + console.log('uploading', file); + await github.repos.uploadReleaseAsset({ + owner, + repo, + release_id: ${{ github.event.release.id }}, + name: file, + data: await fs.readFile(`src/out/${file}`) + }); + } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index e584b48a..d8ae3277 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ - 5.3.4-preview + 6.0.0-preview latest true true @@ -18,6 +18,7 @@ true True + true $(NoWarn);1591 enable diff --git a/src/GraphQLParser.ApiTests/ApiApprovalTests.Public_Api_Should_Not_Change_Inadvertently.approved.txt b/src/GraphQLParser.ApiTests/ApiApprovalTests.Public_Api_Should_Not_Change_Inadvertently.approved.txt index 489643f5..1354c930 100644 --- a/src/GraphQLParser.ApiTests/ApiApprovalTests.Public_Api_Should_Not_Change_Inadvertently.approved.txt +++ b/src/GraphQLParser.ApiTests/ApiApprovalTests.Public_Api_Should_Not_Change_Inadvertently.approved.txt @@ -390,8 +390,8 @@ namespace GraphQLParser } public interface ISource { - string Body { get; set; } - string Name { get; set; } + string Body { get; } + string Name { get; } } public class Lexer : GraphQLParser.ILexer { @@ -403,6 +403,7 @@ namespace GraphQLParser public readonly struct Location { public Location(GraphQLParser.ISource source, int position) { } + public Location(string source, int position) { } public int Column { get; } public int Line { get; } } @@ -423,8 +424,8 @@ namespace GraphQLParser { public Source(string body) { } public Source(string body, string name) { } - public string Body { get; set; } - public string Name { get; set; } + public string Body { get; } + public string Name { get; } } public readonly struct Token { diff --git a/src/GraphQLParser.Tests/LexerTests.cs b/src/GraphQLParser.Tests/LexerTests.cs index 6d221beb..919479d2 100644 --- a/src/GraphQLParser.Tests/LexerTests.cs +++ b/src/GraphQLParser.Tests/LexerTests.cs @@ -1,4 +1,3 @@ -using System; using Shouldly; using Xunit; diff --git a/src/GraphQLParser.sln b/src/GraphQLParser.sln index 54623af0..17bfa796 100644 --- a/src/GraphQLParser.sln +++ b/src/GraphQLParser.sln @@ -16,7 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Directory.Build.props = Directory.Build.props ..\LICENSE.md = ..\LICENSE.md ..\assets\logo.64x64.png = ..\assets\logo.64x64.png - NuGet.config = NuGet.config ..\README.md = ..\README.md EndProjectSection EndProject diff --git a/src/GraphQLParser/AST/GraphQLLocation.cs b/src/GraphQLParser/AST/GraphQLLocation.cs index 8b2bbc2b..b3362eda 100644 --- a/src/GraphQLParser/AST/GraphQLLocation.cs +++ b/src/GraphQLParser/AST/GraphQLLocation.cs @@ -30,11 +30,9 @@ public GraphQLLocation(int start, int end) /// public int End { get; } - - public bool Equals(GraphQLLocation other) => Start == other.Start && End == other.End; - public override bool Equals(object obj) => obj is GraphQLLocation l ? Equals(l) : false; + public override bool Equals(object obj) => obj is GraphQLLocation l && Equals(l); public override int GetHashCode() => (Start, End).GetHashCode(); diff --git a/src/GraphQLParser/ISource.cs b/src/GraphQLParser/ISource.cs index 689cdd49..e597a24e 100644 --- a/src/GraphQLParser/ISource.cs +++ b/src/GraphQLParser/ISource.cs @@ -1,9 +1,9 @@ -namespace GraphQLParser +namespace GraphQLParser { public interface ISource { - string Body { get; set; } + string Body { get; } - string Name { get; set; } + string Name { get; } } -} \ No newline at end of file +} diff --git a/src/GraphQLParser/Location.cs b/src/GraphQLParser/Location.cs index 3599c402..95b3a973 100644 --- a/src/GraphQLParser/Location.cs +++ b/src/GraphQLParser/Location.cs @@ -7,18 +7,27 @@ public readonly struct Location private static readonly Regex _lineRegex = new Regex("\r\n|[\n\r]", RegexOptions.ECMAScript); public Location(ISource source, int position) + : this(source.Body, position) + { + + } + + public Location(string source, int position) { Line = 1; Column = position + 1; - var matches = _lineRegex.Matches(source.Body); - foreach (Match match in matches) + if (position > 0) { - if (match.Index >= position) - break; + var matches = _lineRegex.Matches(source); + foreach (Match match in matches) + { + if (match.Index >= position) + break; - Line++; - Column = position + 1 - (match.Index + matches[0].Length); + Line++; + Column = position + 1 - (match.Index + matches[0].Length); + } } } diff --git a/src/GraphQLParser/ParserContext.cs b/src/GraphQLParser/ParserContext.cs index 5f8f53ec..90d170b5 100644 --- a/src/GraphQLParser/ParserContext.cs +++ b/src/GraphQLParser/ParserContext.cs @@ -1,8 +1,7 @@ -using GraphQLParser.AST; -using GraphQLParser.Exceptions; using System; using System.Collections.Generic; -using System.Linq; +using GraphQLParser.AST; +using GraphQLParser.Exceptions; namespace GraphQLParser { @@ -529,7 +528,7 @@ private GraphQLFieldSelection ParseFieldSelection() return CreateFieldSelection(start, name, alias, comment); } - private GraphQLValue ParseFloat(bool isConstant) + private GraphQLValue ParseFloat(/*bool isConstant*/) { var token = _currentToken; Advance(); @@ -631,7 +630,7 @@ private GraphQLInputValueDefinition ParseInputValueDef() }; } - private GraphQLValue ParseInt(bool isConstant) + private GraphQLValue ParseInt(/*bool isConstant*/) { var token = _currentToken; Advance(); @@ -719,7 +718,7 @@ private GraphQLNamedType ParseNamedType() }; } - private GraphQLValue ParseNameValue(bool isConstant) + private GraphQLValue ParseNameValue(/*bool isConstant*/) { var token = _currentToken; @@ -891,7 +890,7 @@ private GraphQLSelectionSet ParseSelectionSet() }; } - private GraphQLValue ParseString(bool isConstant) + private GraphQLValue ParseString(/*bool isConstant*/) { var token = _currentToken; Advance(); @@ -987,10 +986,10 @@ private GraphQLUnionTypeDefinition ParseUnionTypeDefinition() { TokenKind.BRACKET_L => ParseList(isConstant), TokenKind.BRACE_L => ParseObject(isConstant), - TokenKind.INT => ParseInt(isConstant), - TokenKind.FLOAT => ParseFloat(isConstant), - TokenKind.STRING => ParseString(isConstant), - TokenKind.NAME => ParseNameValue(isConstant), + TokenKind.INT => ParseInt(/*isConstant*/), + TokenKind.FLOAT => ParseFloat(/*isConstant*/), + TokenKind.STRING => ParseString(/*isConstant*/), + TokenKind.NAME => ParseNameValue(/*isConstant*/), TokenKind.DOLLAR when !isConstant => ParseVariable(), _ => throw new GraphQLSyntaxErrorException($"Unexpected {_currentToken}", _source, _currentToken.Start) }; diff --git a/src/GraphQLParser/Source.cs b/src/GraphQLParser/Source.cs index 3fc6fc5e..268ce8ba 100644 --- a/src/GraphQLParser/Source.cs +++ b/src/GraphQLParser/Source.cs @@ -12,8 +12,8 @@ public Source(string body, string name) Body = body ?? string.Empty; } - public string Body { get; set; } + public string Body { get; } - public string Name { get; set; } + public string Name { get; } } }