From 8064f2910a40d5beefdbe79755a895773dcc4522 Mon Sep 17 00:00:00 2001 From: Philip Conrad Date: Wed, 14 Sep 2022 12:43:22 -0400 Subject: [PATCH 1/6] Add basic PR CI/CD checks. This commit adds two manual Github Actions workflows, and one automated workflow that runs both jobs on every PR commit. The workflows include: - Automated linting with golangci-lint - Automated `go test ./...` Signed-off-by: Philip Conrad --- .github/workflows/manual-go-test.yml | 42 ++++++++++++++++++++++ .github/workflows/manual-linter.yml | 22 ++++++++++++ .github/workflows/pull-request.yml | 52 ++++++++++++++++++++++++++++ .go-version | 1 + .golangci.yaml | 2 +- 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/manual-go-test.yml create mode 100644 .github/workflows/manual-linter.yml create mode 100644 .github/workflows/pull-request.yml create mode 100644 .go-version diff --git a/.github/workflows/manual-go-test.yml b/.github/workflows/manual-go-test.yml new file mode 100644 index 00000000..df038b24 --- /dev/null +++ b/.github/workflows/manual-go-test.yml @@ -0,0 +1,42 @@ +name: Manual Go Test Run + +on: + workflow_dispatch: + +# When a new revision is pushed to a PR, cancel all in-progress CI runs for that +# PR. See https://docs.github.com/en/actions/using-jobs/using-concurrency +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + go-test: + name: Go Test (${{ matrix.os }}) + runs-on: ${{ matrix.run }} + strategy: + fail-fast: false + matrix: + include: + - os: linux + run: ubuntu-22.04 + - os: darwin + run: macos-latest + # Windows not allowed currently because of line-ending conversion issues. + #- os: windows + # run: windows-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - id: go_version + name: Read go version + run: echo "::set-output name=go_version::$(cat .go-version)" + + - name: Install Go (${{ steps.go_version.outputs.go_version }}) + uses: actions/setup-go@v3 + with: + go-version: ${{ steps.go_version.outputs.go_version }} + + - name: Unit Test Golang + run: go test ./... + timeout-minutes: 30 diff --git a/.github/workflows/manual-linter.yml b/.github/workflows/manual-linter.yml new file mode 100644 index 00000000..35900f6a --- /dev/null +++ b/.github/workflows/manual-linter.yml @@ -0,0 +1,22 @@ +name: Manual Linter Run + +on: + workflow_dispatch: + +# When a new revision is pushed to a PR, cancel all in-progress CI runs for that +# PR. See https://docs.github.com/en/actions/using-jobs/using-concurrency +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + go-lint: + name: Go Lint + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Golang Style and Lint Check + run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run -v + timeout-minutes: 30 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 00000000..932092fa --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,52 @@ +name: PR Check + +on: [pull_request] + +# When a new revision is pushed to a PR, cancel all in-progress CI runs for that +# PR. See https://docs.github.com/en/actions/using-jobs/using-concurrency +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + go-lint: + name: Go Lint + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Golang Style and Lint Check + run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run -v + timeout-minutes: 30 + + go-test: + name: Go Test (${{ matrix.os }}) + runs-on: ${{ matrix.run }} + strategy: + fail-fast: false + matrix: + include: + - os: linux + run: ubuntu-22.04 + - os: darwin + run: macos-latest + # Windows not allowed currently because of line-ending conversion issues. + #- os: windows + # run: windows-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - id: go_version + name: Read go version + run: echo "::set-output name=go_version::$(cat .go-version)" + + - name: Install Go (${{ steps.go_version.outputs.go_version }}) + uses: actions/setup-go@v3 + with: + go-version: ${{ steps.go_version.outputs.go_version }} + + - name: Unit Test Golang + run: go test ./... + timeout-minutes: 30 diff --git a/.go-version b/.go-version new file mode 100644 index 00000000..66e2ae6c --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.19.1 diff --git a/.golangci.yaml b/.golangci.yaml index accb6695..accb83fa 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -42,4 +42,4 @@ issues: - errcheck - gosec - rowserrcheck - - makezero \ No newline at end of file + - makezero From b8f0eac2ca362e4b189fd9f98d255014f9e757f9 Mon Sep 17 00:00:00 2001 From: Philip Conrad Date: Wed, 14 Sep 2022 13:51:23 -0400 Subject: [PATCH 2/6] Linter ignores for dot imports. Signed-off-by: Philip Conrad --- parser/query.go | 1 + parser/schema.go | 1 + validator/rules/fields_on_correct_type.go | 2 ++ validator/rules/fragments_on_composite_types.go | 2 ++ validator/rules/known_argument_names.go | 2 ++ validator/rules/known_directives.go | 2 ++ validator/rules/known_fragment_names.go | 2 ++ validator/rules/known_root_type.go | 2 ++ validator/rules/known_type_names.go | 2 ++ validator/rules/lone_anonymous_operation.go | 2 ++ validator/rules/no_fragment_cycles.go | 2 ++ validator/rules/no_undefined_variables.go | 2 ++ validator/rules/no_unused_fragments.go | 2 ++ validator/rules/no_unused_variables.go | 2 ++ validator/rules/overlapping_fields_can_be_merged.go | 2 ++ validator/rules/possible_fragment_spreads.go | 2 ++ validator/rules/provided_required_arguments.go | 2 ++ validator/rules/scalar_leafs.go | 2 ++ validator/rules/single_field_subscriptions.go | 2 ++ validator/rules/unique_argument_names.go | 2 ++ validator/rules/unique_directives_per_location.go | 2 ++ validator/rules/unique_fragment_names.go | 2 ++ validator/rules/unique_input_field_names.go | 2 ++ validator/rules/unique_operation_names.go | 2 ++ validator/rules/unique_variable_names.go | 2 ++ validator/rules/values_of_correct_type.go | 2 ++ validator/rules/variables_are_input_types.go | 2 ++ validator/rules/variables_in_allowed_position.go | 2 ++ validator/schema.go | 1 + validator/validator.go | 1 + 30 files changed, 56 insertions(+) diff --git a/parser/query.go b/parser/query.go index a38d982a..123423bb 100644 --- a/parser/query.go +++ b/parser/query.go @@ -3,6 +3,7 @@ package parser import ( "github.com/vektah/gqlparser/v2/lexer" + //nolint:revive . "github.com/vektah/gqlparser/v2/ast" ) diff --git a/parser/schema.go b/parser/schema.go index aec08a97..9656bcca 100644 --- a/parser/schema.go +++ b/parser/schema.go @@ -1,6 +1,7 @@ package parser import ( + //nolint:revive . "github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/lexer" ) diff --git a/validator/rules/fields_on_correct_type.go b/validator/rules/fields_on_correct_type.go index aa83c696..86ab172e 100644 --- a/validator/rules/fields_on_correct_type.go +++ b/validator/rules/fields_on_correct_type.go @@ -6,6 +6,8 @@ import ( "strings" "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/fragments_on_composite_types.go b/validator/rules/fragments_on_composite_types.go index 5215f697..81ef861b 100644 --- a/validator/rules/fragments_on_composite_types.go +++ b/validator/rules/fragments_on_composite_types.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/known_argument_names.go b/validator/rules/known_argument_names.go index da5a7962..c187dabf 100644 --- a/validator/rules/known_argument_names.go +++ b/validator/rules/known_argument_names.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/known_directives.go b/validator/rules/known_directives.go index 18fe41fd..89c6ac19 100644 --- a/validator/rules/known_directives.go +++ b/validator/rules/known_directives.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/known_fragment_names.go b/validator/rules/known_fragment_names.go index b7427d0d..3afd9c1c 100644 --- a/validator/rules/known_fragment_names.go +++ b/validator/rules/known_fragment_names.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/known_root_type.go b/validator/rules/known_root_type.go index 4c60c8d8..60bc0d52 100644 --- a/validator/rules/known_root_type.go +++ b/validator/rules/known_root_type.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/known_type_names.go b/validator/rules/known_type_names.go index 7abfbf62..902939d3 100644 --- a/validator/rules/known_type_names.go +++ b/validator/rules/known_type_names.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/lone_anonymous_operation.go b/validator/rules/lone_anonymous_operation.go index d2752854..fe8bb203 100644 --- a/validator/rules/lone_anonymous_operation.go +++ b/validator/rules/lone_anonymous_operation.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/no_fragment_cycles.go b/validator/rules/no_fragment_cycles.go index da73f349..a953174f 100644 --- a/validator/rules/no_fragment_cycles.go +++ b/validator/rules/no_fragment_cycles.go @@ -5,6 +5,8 @@ import ( "strings" "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/no_undefined_variables.go b/validator/rules/no_undefined_variables.go index 91df727a..46c18d12 100644 --- a/validator/rules/no_undefined_variables.go +++ b/validator/rules/no_undefined_variables.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/no_unused_fragments.go b/validator/rules/no_unused_fragments.go index dfc89672..218ffa77 100644 --- a/validator/rules/no_unused_fragments.go +++ b/validator/rules/no_unused_fragments.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/no_unused_variables.go b/validator/rules/no_unused_variables.go index df2e5f4b..d3088109 100644 --- a/validator/rules/no_unused_variables.go +++ b/validator/rules/no_unused_variables.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/overlapping_fields_can_be_merged.go b/validator/rules/overlapping_fields_can_be_merged.go index 38e1efa1..2ffc3dd1 100644 --- a/validator/rules/overlapping_fields_can_be_merged.go +++ b/validator/rules/overlapping_fields_can_be_merged.go @@ -6,6 +6,8 @@ import ( "reflect" "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/possible_fragment_spreads.go b/validator/rules/possible_fragment_spreads.go index a3f795c9..bed70289 100644 --- a/validator/rules/possible_fragment_spreads.go +++ b/validator/rules/possible_fragment_spreads.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/provided_required_arguments.go b/validator/rules/provided_required_arguments.go index d8ed6520..ab79163b 100644 --- a/validator/rules/provided_required_arguments.go +++ b/validator/rules/provided_required_arguments.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/scalar_leafs.go b/validator/rules/scalar_leafs.go index 718bc683..605ab9e8 100644 --- a/validator/rules/scalar_leafs.go +++ b/validator/rules/scalar_leafs.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/single_field_subscriptions.go b/validator/rules/single_field_subscriptions.go index a9e5bf63..7d4c6843 100644 --- a/validator/rules/single_field_subscriptions.go +++ b/validator/rules/single_field_subscriptions.go @@ -5,6 +5,8 @@ import ( "strings" "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/unique_argument_names.go b/validator/rules/unique_argument_names.go index 1d9a50ab..e977d638 100644 --- a/validator/rules/unique_argument_names.go +++ b/validator/rules/unique_argument_names.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/unique_directives_per_location.go b/validator/rules/unique_directives_per_location.go index 52dfb21e..47971ee1 100644 --- a/validator/rules/unique_directives_per_location.go +++ b/validator/rules/unique_directives_per_location.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/unique_fragment_names.go b/validator/rules/unique_fragment_names.go index 8c348aea..2c44a437 100644 --- a/validator/rules/unique_fragment_names.go +++ b/validator/rules/unique_fragment_names.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/unique_input_field_names.go b/validator/rules/unique_input_field_names.go index 092be671..c5fce8ff 100644 --- a/validator/rules/unique_input_field_names.go +++ b/validator/rules/unique_input_field_names.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/unique_operation_names.go b/validator/rules/unique_operation_names.go index 4d41b60a..49ffbe47 100644 --- a/validator/rules/unique_operation_names.go +++ b/validator/rules/unique_operation_names.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/unique_variable_names.go b/validator/rules/unique_variable_names.go index 6481ef4c..c93948c1 100644 --- a/validator/rules/unique_variable_names.go +++ b/validator/rules/unique_variable_names.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/values_of_correct_type.go b/validator/rules/values_of_correct_type.go index 22bea771..7ba6928b 100644 --- a/validator/rules/values_of_correct_type.go +++ b/validator/rules/values_of_correct_type.go @@ -6,6 +6,8 @@ import ( "strconv" "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/variables_are_input_types.go b/validator/rules/variables_are_input_types.go index 4ea94e5a..d16ee021 100644 --- a/validator/rules/variables_are_input_types.go +++ b/validator/rules/variables_are_input_types.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/rules/variables_in_allowed_position.go b/validator/rules/variables_in_allowed_position.go index eef74354..e3fd6fbb 100644 --- a/validator/rules/variables_in_allowed_position.go +++ b/validator/rules/variables_in_allowed_position.go @@ -2,6 +2,8 @@ package validator import ( "github.com/vektah/gqlparser/v2/ast" + + //nolint:revive // Validator rules each use dot imports for convenience. . "github.com/vektah/gqlparser/v2/validator" ) diff --git a/validator/schema.go b/validator/schema.go index 976ed830..6902dc74 100644 --- a/validator/schema.go +++ b/validator/schema.go @@ -5,6 +5,7 @@ import ( "strconv" "strings" + //nolint:revive . "github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/gqlerror" "github.com/vektah/gqlparser/v2/parser" diff --git a/validator/validator.go b/validator/validator.go index 34bf93db..c5426ada 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -1,6 +1,7 @@ package validator import ( + //nolint:revive . "github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/gqlerror" ) From 7007f8c5ab63727ff56aefc43285ed0e141c5b9d Mon Sep 17 00:00:00 2001 From: Philip Conrad Date: Wed, 14 Sep 2022 14:11:07 -0400 Subject: [PATCH 3/6] Fix linter issues with changes + ignores. Signed-off-by: Philip Conrad --- ast/path.go | 4 ++-- ast/selection.go | 4 ++-- ast/type.go | 4 ++-- formatter/formatter.go | 1 + gqlparser.go | 2 ++ lexer/lexer.go | 12 +++++++----- lexer/lexer_test.go | 3 ++- parser/query_test.go | 5 +++-- parser/schema_test.go | 3 ++- validator/prelude.go | 1 + validator/rules/known_directives.go | 2 +- validator/schema_test.go | 3 ++- validator/vars.go | 6 +++--- 13 files changed, 30 insertions(+), 20 deletions(-) diff --git a/ast/path.go b/ast/path.go index 9af16843..be1a9e4e 100644 --- a/ast/path.go +++ b/ast/path.go @@ -60,8 +60,8 @@ func (path *Path) UnmarshalJSON(b []byte) error { type PathIndex int -func (_ PathIndex) isPathElement() {} +func (PathIndex) isPathElement() {} type PathName string -func (_ PathName) isPathElement() {} +func (PathName) isPathElement() {} diff --git a/ast/selection.go b/ast/selection.go index 159db844..5ef26c6a 100644 --- a/ast/selection.go +++ b/ast/selection.go @@ -34,6 +34,6 @@ type Argument struct { Position *Position `dump:"-"` } -func (f *Field) ArgumentMap(vars map[string]interface{}) map[string]interface{} { - return arg2map(f.Definition.Arguments, f.Arguments, vars) +func (s *Field) ArgumentMap(vars map[string]interface{}) map[string]interface{} { + return arg2map(s.Definition.Arguments, s.Arguments, vars) } diff --git a/ast/type.go b/ast/type.go index 9577fdb4..5f77bc7c 100644 --- a/ast/type.go +++ b/ast/type.go @@ -63,6 +63,6 @@ func (t *Type) IsCompatible(other *Type) bool { return true } -func (v *Type) Dump() string { - return v.String() +func (t *Type) Dump() string { + return t.String() } diff --git a/formatter/formatter.go b/formatter/formatter.go index 44f97325..fc0b1383 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -15,6 +15,7 @@ type Formatter interface { FormatQueryDocument(doc *ast.QueryDocument) } +//nolint:revive // Ignore "stuttering" name format.FormatterOption type FormatterOption func(*formatter) func WithIndent(indent string) FormatterOption { diff --git a/gqlparser.go b/gqlparser.go index e242a896..69a2cf18 100644 --- a/gqlparser.go +++ b/gqlparser.go @@ -5,6 +5,8 @@ import ( "github.com/vektah/gqlparser/v2/gqlerror" "github.com/vektah/gqlparser/v2/parser" "github.com/vektah/gqlparser/v2/validator" + + // Blank import is used to load up the validator rules. _ "github.com/vektah/gqlparser/v2/validator/rules" ) diff --git a/lexer/lexer.go b/lexer/lexer.go index 25dcdcb9..8ce04fd2 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -121,7 +121,9 @@ func (s *Lexer) ReadToken() (token Token, err error) { case '|': return s.makeValueToken(Pipe, "") case '#': - s.readComment() + if comment, err := s.readComment(); err != nil { + return comment, err + } return s.ReadToken() case '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z': @@ -254,9 +256,9 @@ func (s *Lexer) readNumber() (Token, error) { if float { return s.makeToken(Float) - } else { - return s.makeToken(Int) } + return s.makeToken(Int) + } // acceptByte if it matches any of given bytes, returning true if it found anything @@ -393,8 +395,8 @@ func (s *Lexer) readString() (Token, error) { case 't': buf.WriteByte('\t') default: - s.end += 1 - s.endRunes += 1 + s.end++ + s.endRunes++ return s.makeError("Invalid character escape sequence: \\%s.", string(escape)) } s.end += 2 diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 8dc8a536..8ae5b928 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -1,9 +1,10 @@ package lexer import ( - "github.com/vektah/gqlparser/v2/gqlerror" "testing" + "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/parser/testrunner" ) diff --git a/parser/query_test.go b/parser/query_test.go index de422d54..3fd5b362 100644 --- a/parser/query_test.go +++ b/parser/query_test.go @@ -1,9 +1,10 @@ package parser import ( - "github.com/vektah/gqlparser/v2/gqlerror" "testing" + "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/parser/testrunner" ) @@ -19,7 +20,7 @@ func TestQueryDocument(t *testing.T) { } } return testrunner.Spec{ - AST: ast.Dump(doc), + AST: ast.Dump(doc), } }) } diff --git a/parser/schema_test.go b/parser/schema_test.go index cf366f24..a40abb90 100644 --- a/parser/schema_test.go +++ b/parser/schema_test.go @@ -1,9 +1,10 @@ package parser import ( + "testing" + "github.com/stretchr/testify/assert" "github.com/vektah/gqlparser/v2/gqlerror" - "testing" "github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/parser/testrunner" diff --git a/validator/prelude.go b/validator/prelude.go index c354ec0d..43766f22 100644 --- a/validator/prelude.go +++ b/validator/prelude.go @@ -2,6 +2,7 @@ package validator import ( _ "embed" + "github.com/vektah/gqlparser/v2/ast" ) diff --git a/validator/rules/known_directives.go b/validator/rules/known_directives.go index 89c6ac19..9b5f28db 100644 --- a/validator/rules/known_directives.go +++ b/validator/rules/known_directives.go @@ -14,7 +14,7 @@ func init() { Line int Column int } - var seen map[mayNotBeUsedDirective]bool = map[mayNotBeUsedDirective]bool{} + var seen = map[mayNotBeUsedDirective]bool{} observers.OnDirective(func(walker *Walker, directive *ast.Directive) { if directive.Definition == nil { addError( diff --git a/validator/schema_test.go b/validator/schema_test.go index 3c43a43b..c5f88fc1 100644 --- a/validator/schema_test.go +++ b/validator/schema_test.go @@ -1,10 +1,11 @@ package validator import ( - "github.com/vektah/gqlparser/v2/gqlerror" "os" "testing" + "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/stretchr/testify/require" "github.com/vektah/gqlparser/v2/ast" "github.com/vektah/gqlparser/v2/parser/testrunner" diff --git a/validator/vars.go b/validator/vars.go index 8dbb05bc..df530234 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -11,7 +11,7 @@ import ( "github.com/vektah/gqlparser/v2/gqlerror" ) -var UnexpectedType = fmt.Errorf("Unexpected Type") +var ErrUnexpectedType = fmt.Errorf("Unexpected Type") // VariableValues coerces and validates variable values func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables map[string]interface{}) (map[string]interface{}, error) { @@ -53,8 +53,8 @@ func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables m } else { rv := reflect.ValueOf(val) - jsonNumber, isJsonNumber := val.(json.Number) - if isJsonNumber { + jsonNumber, isJSONNumber := val.(json.Number) + if isJSONNumber { if v.Type.NamedType == "Int" { n, err := jsonNumber.Int64() if err != nil { From ffc8b426b7845417791e667308e26907741c3b66 Mon Sep 17 00:00:00 2001 From: Philip Conrad Date: Wed, 14 Sep 2022 14:35:46 -0400 Subject: [PATCH 4/6] Fix prealloc linter suggestions. Signed-off-by: Philip Conrad --- validator/imported_test.go | 2 +- validator/rules/fields_on_correct_type.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/validator/imported_test.go b/validator/imported_test.go index e34975fa..5cafdaea 100644 --- a/validator/imported_test.go +++ b/validator/imported_test.go @@ -43,7 +43,7 @@ func TestValidation(t *testing.T) { d.pattern = regexp.MustCompile("^" + d.Rule + "$") } - var schemas []*ast.Schema + var schemas = make([]*ast.Schema, 0, len(rawSchemas)) for i, schema := range rawSchemas { schema, err := gqlparser.LoadSchema(&ast.Source{Input: schema, Name: fmt.Sprintf("schemas.yml[%d]", i)}) if err != nil { diff --git a/validator/rules/fields_on_correct_type.go b/validator/rules/fields_on_correct_type.go index 86ab172e..77c3fdac 100644 --- a/validator/rules/fields_on_correct_type.go +++ b/validator/rules/fields_on_correct_type.go @@ -43,11 +43,12 @@ func getSuggestedTypeNames(walker *Walker, parent *ast.Definition, name string) return nil } - var suggestedObjectTypes []string + possibleTypes := walker.Schema.GetPossibleTypes(parent) + var suggestedObjectTypes = make([]string, 0, len(possibleTypes)) var suggestedInterfaceTypes []string interfaceUsageCount := map[string]int{} - for _, possibleType := range walker.Schema.GetPossibleTypes(parent) { + for _, possibleType := range possibleTypes { field := possibleType.Fields.ForName(name) if field == nil { continue @@ -87,7 +88,7 @@ func getSuggestedFieldNames(parent *ast.Definition, name string) []string { return nil } - var possibleFieldNames []string + var possibleFieldNames = make([]string, 0, len(parent.Fields)) for _, field := range parent.Fields { possibleFieldNames = append(possibleFieldNames, field.Name) } From b7c1b8bc4c578894503d989cbb621fc1451c2d24 Mon Sep 17 00:00:00 2001 From: Philip Conrad Date: Wed, 14 Sep 2022 15:10:40 -0400 Subject: [PATCH 5/6] Switch to `ubuntu-latest` + use GH Action for golangci-lint. Signed-off-by: Philip Conrad --- .github/workflows/manual-go-test.yml | 2 +- .github/workflows/manual-linter.yml | 7 +++++-- .github/workflows/pull-request.yml | 9 ++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/manual-go-test.yml b/.github/workflows/manual-go-test.yml index df038b24..6e9ca5d2 100644 --- a/.github/workflows/manual-go-test.yml +++ b/.github/workflows/manual-go-test.yml @@ -18,7 +18,7 @@ jobs: matrix: include: - os: linux - run: ubuntu-22.04 + run: ubuntu-latest - os: darwin run: macos-latest # Windows not allowed currently because of line-ending conversion issues. diff --git a/.github/workflows/manual-linter.yml b/.github/workflows/manual-linter.yml index 35900f6a..ddb2d879 100644 --- a/.github/workflows/manual-linter.yml +++ b/.github/workflows/manual-linter.yml @@ -12,11 +12,14 @@ concurrency: jobs: go-lint: name: Go Lint - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v3 - name: Golang Style and Lint Check - run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run -v + uses: golangci/golangci-lint-action@v3 timeout-minutes: 30 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 932092fa..ef2e8878 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,14 +11,17 @@ concurrency: jobs: go-lint: name: Go Lint - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v3 - name: Golang Style and Lint Check - run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run -v + uses: golangci/golangci-lint-action@v3 timeout-minutes: 30 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest go-test: name: Go Test (${{ matrix.os }}) @@ -28,7 +31,7 @@ jobs: matrix: include: - os: linux - run: ubuntu-22.04 + run: ubuntu-latest - os: darwin run: macos-latest # Windows not allowed currently because of line-ending conversion issues. From dbf63af5a19b9039e4bca147edf95219cac3d6df Mon Sep 17 00:00:00 2001 From: Philip Conrad Date: Wed, 14 Sep 2022 15:34:56 -0400 Subject: [PATCH 6/6] Disable MacOS tests. Signed-off-by: Philip Conrad --- .github/workflows/manual-go-test.yml | 5 +++-- .github/workflows/pull-request.yml | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/manual-go-test.yml b/.github/workflows/manual-go-test.yml index 6e9ca5d2..fa7cd3bb 100644 --- a/.github/workflows/manual-go-test.yml +++ b/.github/workflows/manual-go-test.yml @@ -19,8 +19,9 @@ jobs: include: - os: linux run: ubuntu-latest - - os: darwin - run: macos-latest + # MacOS is disabled due to the high cost multiplier on GH Actions. + #- os: darwin + # run: macos-latest # Windows not allowed currently because of line-ending conversion issues. #- os: windows # run: windows-latest diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ef2e8878..aecbed97 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -32,8 +32,9 @@ jobs: include: - os: linux run: ubuntu-latest - - os: darwin - run: macos-latest + # MacOS is disabled due to the high cost multiplier on GH Actions. + #- os: darwin + # run: macos-latest # Windows not allowed currently because of line-ending conversion issues. #- os: windows # run: windows-latest