From 234ee4e36d4393d90a7f2036628f4e2ea23796b9 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 16:22:36 -0700 Subject: [PATCH 01/17] Use formatting task to check Go formatting in CI The `go:check-formatting` task has no value to the developer, since they will be better off to just run the formatting task. This means that the only use for this task is the CI. I think this can be better achieved by configuring the CI to format the code and then check for a diff. This ensures that there is no possibility for a mismatch between the formatting check and the formatting task. --- .github/workflows/check-formatting.yml | 5 ++++- Taskfile.yml | 10 ---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 9ff92f688..86a79b258 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -37,7 +37,10 @@ jobs: version: 3.x - name: Check Go code formatting - run: task go:check-formatting + run: task go:format + + - name: Check formatting + run: git diff --color --exit-code - name: Check shell script formatting # https://github.com/mvdan/sh diff --git a/Taskfile.yml b/Taskfile.yml index 9054940e6..3838f636b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -57,7 +57,6 @@ tasks: check-formatting: desc: Check formatting of all files cmds: - - task: go:check-formatting - task: docs:check-formatting - task: config:check-formatting @@ -73,7 +72,6 @@ tasks: desc: Lint and check formatting of Go code cmds: - task: go:lint - - task: go:check-formatting go:lint: desc: Lint Go code @@ -83,14 +81,6 @@ tasks: GOLINT_PATH="$(go list -f '{{"{{"}}.Target{{"}}"}}' golang.org/x/lint/golint || echo "false")" "$GOLINT_PATH" {{.GOLINTFLAGS}} "{{ default .DEFAULT_TARGETS .TARGETS }}" - go:check-formatting: - desc: Check Go code formatting - cmds: - - | - RESULTS="$(gofmt -l {{ default .DEFAULT_PATHS .PATHS }})" - echo "$RESULTS" - test -z "$RESULTS" - go:format: desc: Format Go code cmds: From 10593589fc24edb91df75c7c6cbf0f5cf9a81a6d Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 16:33:29 -0700 Subject: [PATCH 02/17] Use `go fmt` instead of `gofmt` for formatting Go code Since `go fmt` is only a formatter, it was necessary to use `gofmt` for the formatting check task, since that command has an option to skip writing the code. In order to ensure consistency between the two, I also used `gofmt` for the formatting task. The unfortunate thing about gofmt is that it works from a list of paths, rather than a list of packages as is the case with `go vet`, `go fix`, and `golint`. With the removal of the superfluous formatting check task, the motivation for using gofmt in the formatting task is removed, freeing me to use the superior `go fmt`. --- Taskfile.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 3838f636b..bddb1a952 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -84,7 +84,7 @@ tasks: go:format: desc: Format Go code cmds: - - gofmt -l -w {{ default .DEFAULT_PATHS .PATHS }} + - go fmt {{default .DEFAULT_PACKAGES .PACKAGES}} python:check: cmds: @@ -255,8 +255,6 @@ vars: DIST_DIR: "dist" DEFAULT_PACKAGES: sh: echo `go list ./... | tr '\n' ' '` - DEFAULT_PATHS: - sh: echo '`go list -f '{{"{{"}}.Dir{{"}}"}}' ./...`' # build vars COMMIT: sh: echo "$(git log -n 1 --format=%h)" From b9932fcd4f496051d9789487375bb2ec9e8b91a7 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 20:15:52 -0700 Subject: [PATCH 03/17] Move Go formatting check to "Check Go" workflow GitHub Actions provides a paths filter feature that allows you to restrict workflow run triggers to changes to specific paths within the repository. This can greatly improve the efficiency of the CI system by avoiding running irrelevant checks. The effective use of this feature requires that the purpose of a workflow be focused on a specific type of file or project component. The "Check Formatting" workflow was the antithesis of that; grouping formatting checks of all types of files. --- .github/workflows/check-formatting.yml | 8 ---- .github/workflows/check-go-task.yml | 51 ++++++++++++++++++++++++++ README.md | 1 + 3 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/check-go-task.yml diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 86a79b258..35c1b092d 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -6,7 +6,6 @@ on: - ".github/workflows/check-formatting.yml" - "Taskfile.yml" - ".prettierrc" - - "**.go" - "**.json" - "**.md" - "**.yaml" @@ -16,7 +15,6 @@ on: - ".github/workflows/check-formatting.yml" - "Taskfile.yml" - ".prettierrc" - - "**.go" - "**.json" - "**.md" - "**.yaml" @@ -36,12 +34,6 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} version: 3.x - - name: Check Go code formatting - run: task go:format - - - name: Check formatting - run: git diff --color --exit-code - - name: Check shell script formatting # https://github.com/mvdan/sh run: | diff --git a/.github/workflows/check-go-task.yml b/.github/workflows/check-go-task.yml new file mode 100644 index 000000000..cadddd3c8 --- /dev/null +++ b/.github/workflows/check-go-task.yml @@ -0,0 +1,51 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-task.md +name: Check Go + +env: + # See: https://github.com/actions/setup-go/tree/v2#readme + GO_VERSION: "1.14" + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/check-go-task.ya?ml" + - "Taskfile.ya?ml" + - "go.mod" + - "go.sum" + - "**.go" + pull_request: + paths: + - ".github/workflows/check-go-task.ya?ml" + - "Taskfile.ya?ml" + - "go.mod" + - "go.sum" + - "**.go" + workflow_dispatch: + repository_dispatch: + +jobs: + + check-formatting: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Format code + run: task go:format + + - name: Check formatting + run: git diff --color --exit-code diff --git a/README.md b/README.md index 527ab251c..2c3f40798 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Arduino Lint [![Tests Status](https://github.com/arduino/arduino-lint/workflows/Run%20tests/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Run+tests) +[![Check Go status](https://github.com/arduino/arduino-lint/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/arduino-lint/actions/workflows/check-go-task.yml) [![Nightly Status](https://github.com/arduino/arduino-lint/workflows/Nightly%20build/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Nightly+build) [![Docs Status](https://github.com/arduino/arduino-lint/workflows/Publish%20documentation/badge.svg)](https://github.com/arduino/arduino-lint/actions?workflow=Publish+documentation) [![Codecov](https://codecov.io/gh/arduino/arduino-lint/branch/main/graph/badge.svg?token=nprqPQMbdh)](https://codecov.io/gh/arduino/arduino-lint) From ca74a3a98ed1db33b40657079a3c0279cb722fad Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 20:36:28 -0700 Subject: [PATCH 04/17] Split `go vet` and `golint` checks into separate workflow jobs Splitting a workflow into distinct jobs (and steps within those jobs in the case of operations that need to occur in the same environment) makes interpreting a CI failure much easier. The check results are displayed on a per-job basis, each job having its own logs, and the results of that job shown on a per-step basis, each step having its own folded section in the logs. This means you can quickly identify which part of the workflow failed and get the logs specific to that. --- .github/workflows/lint-code.yml | 15 +++++++++++++++ Taskfile.yml | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml index ad1486418..a358d7b13 100644 --- a/.github/workflows/lint-code.yml +++ b/.github/workflows/lint-code.yml @@ -17,6 +17,21 @@ on: - "**/*.go" jobs: + check-errors: + runs-on: ubuntu-latest + steps: + - name: Checkout local repository + uses: actions/checkout@v2 + + - name: Install Taskfile + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Check for errors + run: task go:vet + lint: runs-on: ubuntu-latest steps: diff --git a/Taskfile.yml b/Taskfile.yml index bddb1a952..a40adbead 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -49,6 +49,7 @@ tasks: lint: desc: Lint all files cmds: + - task: go:vet - task: go:lint - task: python:lint - task: docs:lint @@ -71,12 +72,18 @@ tasks: go:check: desc: Lint and check formatting of Go code cmds: + - task: go:vet - task: go:lint + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml + go:vet: + desc: Check for errors in Go code + cmds: + - go vet {{default .DEFAULT_PACKAGES .PACKAGES}} + go:lint: desc: Lint Go code cmds: - - go vet {{ default .DEFAULT_PACKAGES .PACKAGES }} - | GOLINT_PATH="$(go list -f '{{"{{"}}.Target{{"}}"}}' golang.org/x/lint/golint || echo "false")" "$GOLINT_PATH" {{.GOLINTFLAGS}} "{{ default .DEFAULT_TARGETS .TARGETS }}" From 465c53b686c90012e9062f7602a3c179fa6a2853 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 20:46:38 -0700 Subject: [PATCH 05/17] Specify Go version to use when running CI linting tasks It seems best to use the same version of Go when linting the code in the CI workflow runs as we use when testing and building that code. Previously, whichever version of Go that happened to be installed in the runner at the time was used. --- .github/workflows/lint-code.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml index a358d7b13..0cfb86cc0 100644 --- a/.github/workflows/lint-code.yml +++ b/.github/workflows/lint-code.yml @@ -1,5 +1,9 @@ name: Lint code +env: + # See: https://github.com/actions/setup-go/tree/v2#readme + GO_VERSION: "1.14" + on: push: paths: @@ -23,6 +27,11 @@ jobs: - name: Checkout local repository uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + - name: Install Taskfile uses: arduino/setup-task@v1 with: @@ -38,6 +47,11 @@ jobs: - name: Checkout local repository uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + - name: Install Taskfile uses: arduino/setup-task@v1 with: From e340561e5102b02ebb717216f3de362ff15a9f8e Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 20:57:25 -0700 Subject: [PATCH 06/17] Avoid pollution of `go.mod` file by `go:lint` task Running the `go get` or `go list` commands from the module folder results in a change to the `go.mod` file. That change is reverted when you run `go mod tidy`. This results in cryptic diffs that can be confusing to contributors. The problem is avoided by running the commands from a separate folder. --- .github/workflows/lint-code.yml | 2 +- Taskfile.yml | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml index 0cfb86cc0..ca03e1515 100644 --- a/.github/workflows/lint-code.yml +++ b/.github/workflows/lint-code.yml @@ -63,4 +63,4 @@ jobs: go get golang.org/x/lint/golint - name: Lint Go code - run: task go:lint + run: task --silent go:lint diff --git a/Taskfile.yml b/Taskfile.yml index a40adbead..ed0f6226c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -81,12 +81,21 @@ tasks: cmds: - go vet {{default .DEFAULT_PACKAGES .PACKAGES}} + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:lint: desc: Lint Go code cmds: - | + PROJECT_PATH="$PWD" + # `go get` and `go list` commands must be run from a temporary folder to avoid polluting go.mod + cd "$(mktemp -d "${TMPDIR-${TMP-/tmp}}/task-temporary-XXXXX")" + go get golang.org/x/lint/golint GOLINT_PATH="$(go list -f '{{"{{"}}.Target{{"}}"}}' golang.org/x/lint/golint || echo "false")" - "$GOLINT_PATH" {{.GOLINTFLAGS}} "{{ default .DEFAULT_TARGETS .TARGETS }}" + # `golint` must be run from the module folder + cd "$PROJECT_PATH" + "$GOLINT_PATH" \ + {{.GOLINTFLAGS}} \ + {{default .DEFAULT_TARGETS .TARGETS}} go:format: desc: Format Go code From 1f3828e12d08fe9ef1bd07a76e53807460c3fddc Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 21:34:37 -0700 Subject: [PATCH 07/17] Remove unnecessary variable use from `go:lint` task The`GOLINTFLAGS` variable is only used in a single place, so it doesn't provide any benefit from the standpoint of code duplication. I don't feel that the taskfile usability is improved at all by defining these flags in a location far removed from the command they are used with, and it makes the taskfile more cryptic to contributors who are not experienced with taskfiles. So I think it's better to simply remove this variable. --- Taskfile.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index ed0f6226c..8dfc7ad7c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -94,7 +94,7 @@ tasks: # `golint` must be run from the module folder cd "$PROJECT_PATH" "$GOLINT_PATH" \ - {{.GOLINTFLAGS}} \ + {{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \ {{default .DEFAULT_TARGETS .TARGETS}} go:format: @@ -290,7 +290,6 @@ vars: -X {{ .CONFIGURATION_PACKAGE }}.buildTimestamp={{.TIMESTAMP}} ' GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic" - GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status" DOCS_VERSION: dev DOCS_ALIAS: "" From 46fac9d1f56d970da0591fa1afd26f600efe2069 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 21:04:38 -0700 Subject: [PATCH 08/17] Move Go linting workflow jobs to "Check Go" workflow GitHub Actions provides a paths filter feature that allows you to restrict workflow run triggers to changes to specific paths within the repository. This can greatly improve the efficiency of the CI system by avoiding running irrelevant checks. The effective use of this feature requires that the purpose of a workflow be focused on a specific type of file or project component. Even though the "Lint Code" workflow was in effect focused only on Go code, it's stated purpose was for the linting of all code. The "Check Go" workflow is collects the linting and formatting checks specific to the project's Go files. --- .github/workflows/check-go-task.yml | 41 ++++++++++++++++++ .github/workflows/lint-code.yml | 66 ----------------------------- 2 files changed, 41 insertions(+), 66 deletions(-) delete mode 100644 .github/workflows/lint-code.yml diff --git a/.github/workflows/check-go-task.yml b/.github/workflows/check-go-task.yml index cadddd3c8..0d3b53065 100644 --- a/.github/workflows/check-go-task.yml +++ b/.github/workflows/check-go-task.yml @@ -25,6 +25,47 @@ on: repository_dispatch: jobs: + check-errors: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Check for errors + run: task go:vet + + check-style: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Check style + run: task --silent go:lint check-formatting: runs-on: ubuntu-latest diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml deleted file mode 100644 index ca03e1515..000000000 --- a/.github/workflows/lint-code.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Lint code - -env: - # See: https://github.com/actions/setup-go/tree/v2#readme - GO_VERSION: "1.14" - -on: - push: - paths: - - ".github/workflows/lint-code.yml" - - "Taskfile.yml" - - "go.mod" - - "go.sum" - - "**/*.go" - pull_request: - paths: - - ".github/workflows/lint-code.yml" - - "Taskfile.yml" - - "go.mod" - - "go.sum" - - "**/*.go" - -jobs: - check-errors: - runs-on: ubuntu-latest - steps: - - name: Checkout local repository - uses: actions/checkout@v2 - - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Install Taskfile - uses: arduino/setup-task@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - version: 3.x - - - name: Check for errors - run: task go:vet - - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout local repository - uses: actions/checkout@v2 - - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Install Taskfile - uses: arduino/setup-task@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - version: 3.x - - - name: Install golint - run: | - go get golang.org/x/lint/golint - - - name: Lint Go code - run: task --silent go:lint From fec16685407c5bd94f1b65f7f7261fca4f73b817 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 21:12:49 -0700 Subject: [PATCH 09/17] Use `go fix` in "Check Go" CI workflow This command moderizes usages of outdated Go APIs. If usage of any such APIs are found, the workflow job will fail, showing a diff of the suggested changes in the logs. --- .github/workflows/check-go-task.yml | 24 ++++++++++++++++++++++++ Taskfile.yml | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/.github/workflows/check-go-task.yml b/.github/workflows/check-go-task.yml index 0d3b53065..07511efaa 100644 --- a/.github/workflows/check-go-task.yml +++ b/.github/workflows/check-go-task.yml @@ -46,6 +46,30 @@ jobs: - name: Check for errors run: task go:vet + check-outdated: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Modernize usages of outdated APIs + run: task go:fix + + - name: Check if any fixes were needed + run: git diff --color --exit-code + check-style: runs-on: ubuntu-latest diff --git a/Taskfile.yml b/Taskfile.yml index 8dfc7ad7c..aeaa4813e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -81,6 +81,12 @@ tasks: cmds: - go vet {{default .DEFAULT_PACKAGES .PACKAGES}} + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml + go:fix: + desc: Modernize usages of outdated APIs + cmds: + - go fix {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:lint: desc: Lint Go code From ac8f5b0815617dd56b9e0fe71c34b83652a6898d Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 21:15:30 -0700 Subject: [PATCH 10/17] Add check for out of sync go.mod to "Check Go" workflow Changes to the go.mod manifest file or go.sum lock files can be unexpected and cryptic. The contributor may be confused about whether to commit these to the repository, or may commit unwanted changes, causing confusion to the next contributor when they get a mysterious diff. To avoid this, a check is added to the "Check Go" CI workflow which fails the job if a run of `go mod tidy` results in any diff. --- .github/workflows/check-go-task.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/check-go-task.yml b/.github/workflows/check-go-task.yml index 07511efaa..7c65b27d2 100644 --- a/.github/workflows/check-go-task.yml +++ b/.github/workflows/check-go-task.yml @@ -114,3 +114,21 @@ jobs: - name: Check formatting run: git diff --color --exit-code + + check-config: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Run go mod tidy + run: go mod tidy + + - name: Check whether any tidying was needed + run: git diff --color --exit-code From bce00f5cbdd357c857d2306db8cd984f60e428de Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 21:42:15 -0700 Subject: [PATCH 11/17] Run `go mod tidy` to remove unnecessary entries from Go manifest --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 5e5bf031f..2a7b09b8c 100644 --- a/go.sum +++ b/go.sum @@ -1194,8 +1194,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY= -golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= From d0a9b6cd42d2fa680be58f5fd51fd73a13774cb6 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 21:22:44 -0700 Subject: [PATCH 12/17] Sync description of go:format task with template https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml --- Taskfile.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index aeaa4813e..7ffe54340 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -70,8 +70,8 @@ tasks: - task: config:format go:check: - desc: Lint and check formatting of Go code - cmds: + desc: Check for problems with Go code + deps: - task: go:vet - task: go:lint From a1a79f99860b5360f70a1e331c4b42f9d6d8df47 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 21:24:07 -0700 Subject: [PATCH 13/17] Add source URL comment to standardized tasks This will make it easier for the maintainers to sync fixes and improvements in either direction between the upstream "template" tasks and their installation in this repository. --- Taskfile.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Taskfile.yml b/Taskfile.yml index 7ffe54340..3c6a4f26a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -69,6 +69,7 @@ tasks: - task: docs:format - task: config:format + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:check: desc: Check for problems with Go code deps: @@ -103,6 +104,7 @@ tasks: {{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \ {{default .DEFAULT_TARGETS .TARGETS}} + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:format: desc: Format Go code cmds: From 9478b28a6e55db2a906de3cefcbc4c2bdd80bb63 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 22:27:27 -0700 Subject: [PATCH 14/17] Use standardized taskfile variable name for Go packages list This is the variable name used by the Tooling team's template tasks. --- Taskfile.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 3c6a4f26a..0d3e6575d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -28,7 +28,7 @@ tasks: go:test-unit: desc: Run unit tests cmds: - - go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_PACKAGES .PACKAGES }} + - go test -short -run '{{ default ".*" .TEST_REGEX }}' {{ default "-v" .GOFLAGS }} -coverprofile=coverage_unit.txt {{ default .DEFAULT_GO_PACKAGES .GO_PACKAGES }} test-integration: desc: Run integration tests @@ -80,7 +80,7 @@ tasks: go:vet: desc: Check for errors in Go code cmds: - - go vet {{default .DEFAULT_PACKAGES .PACKAGES}} + - go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:fix: @@ -108,7 +108,7 @@ tasks: go:format: desc: Format Go code cmds: - - go fmt {{default .DEFAULT_PACKAGES .PACKAGES}} + - go fmt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} python:check: cmds: @@ -277,7 +277,7 @@ tasks: vars: PROJECT_NAME: "arduino-lint" DIST_DIR: "dist" - DEFAULT_PACKAGES: + DEFAULT_GO_PACKAGES: sh: echo `go list ./... | tr '\n' ' '` # build vars COMMIT: From bd8aa386f984fb56319a52320d9ccd64546d761c Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 22:28:34 -0700 Subject: [PATCH 15/17] Correct package list taskfile variable name used by `go:lint` task The incorrect variable name used in the `go:lint` task's `golint` command resulted in the task doing nothing, meaning that `golint` has never been ran on the project's packages. --- Taskfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Taskfile.yml b/Taskfile.yml index 0d3e6575d..ef5101841 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -102,7 +102,7 @@ tasks: cd "$PROJECT_PATH" "$GOLINT_PATH" \ {{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \ - {{default .DEFAULT_TARGETS .TARGETS}} + {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml go:format: From c09c9aacb4adcb672cd76ed1c1f50b288864b18e Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 22:50:34 -0700 Subject: [PATCH 16/17] Bring Go code into golint compliance These violations were missed due to the error in the `golint` command used by the `go:lint` task. --- internal/project/projecttype/projecttype.go | 18 +++++++++----- internal/result/outputformat/outputformat.go | 4 +++- internal/result/result.go | 4 ++-- internal/result/result_test.go | 2 +- .../ruleconfiguration/ruleconfiguration.go | 20 ++++++++-------- internal/rule/rulefunction/library.go | 16 ++++++------- internal/rule/rulefunction/library_test.go | 8 +++---- internal/rule/rulefunction/packageindex.go | 24 +++++++++---------- .../rule/rulefunction/packageindex_test.go | 12 +++++----- internal/rule/rulefunction/platform.go | 2 +- internal/rule/ruleresult/ruleresult.go | 8 ++++--- internal/rule/schema/parsevalidationresult.go | 2 +- 12 files changed, 65 insertions(+), 55 deletions(-) diff --git a/internal/project/projecttype/projecttype.go b/internal/project/projecttype/projecttype.go index 72ad8dce7..9f8f30c96 100644 --- a/internal/project/projecttype/projecttype.go +++ b/internal/project/projecttype/projecttype.go @@ -26,12 +26,18 @@ import ( type Type int const ( - Sketch Type = iota // sketch - Library // library - Platform // platform - PackageIndex // package-index - All // all - Not // N/A + // Sketch is used for Arduino sketch projects. + Sketch Type = iota // sketch + // Library is used for Arduino library projects. + Library // library + // Platform is used for Arduino boards platform projects. + Platform // platform + // PackageIndex is used for Arduino package index projects. + PackageIndex // package-index + // All is the catch-all for all supported Arduino project types. + All // all + // Not is the project type used when an Arduino project was not detected. + Not // N/A ) // FromString parses the --project-type flag value and returns the corresponding project type. diff --git a/internal/result/outputformat/outputformat.go b/internal/result/outputformat/outputformat.go index 0f3da968c..db1734b79 100644 --- a/internal/result/outputformat/outputformat.go +++ b/internal/result/outputformat/outputformat.go @@ -26,8 +26,10 @@ import ( type Type int const ( + // Text is the text output format. Text Type = iota // text - JSON // json + // JSON is the JSON output format. + JSON // json ) // FromString parses the --format flag value and returns the corresponding output format type. diff --git a/internal/result/result.go b/internal/result/result.go index 8f9f13b0b..82e5687a8 100644 --- a/internal/result/result.go +++ b/internal/result/result.go @@ -200,9 +200,9 @@ func (results *Type) AddProjectSummary(lintedProject project.Type) { for _, ruleReport := range results.Projects[projectReportIndex].Rules { if ruleReport.Result == ruleresult.Fail.String() { if ruleReport.Level == rulelevel.Warning.String() { - warningCount += 1 + warningCount++ } else if ruleReport.Level == rulelevel.Error.String() { - errorCount += 1 + errorCount++ pass = false } } diff --git a/internal/result/result_test.go b/internal/result/result_test.go index aa1f11668..5f93d4f14 100644 --- a/internal/result/result_test.go +++ b/internal/result/result_test.go @@ -208,7 +208,7 @@ func TestAddProjectSummary(t *testing.T) { if (result == ruleresult.Fail) || configuration.Verbose() { level := testTable.levels[testDataIndex].String() results.Projects[0].Rules[ruleIndex].Level = level - ruleIndex += 1 + ruleIndex++ } } results.AddProjectSummary(lintedProject) diff --git a/internal/rule/ruleconfiguration/ruleconfiguration.go b/internal/rule/ruleconfiguration/ruleconfiguration.go index f0f67f4bd..9bcfd6ec9 100644 --- a/internal/rule/ruleconfiguration/ruleconfiguration.go +++ b/internal/rule/ruleconfiguration/ruleconfiguration.go @@ -903,7 +903,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: nil, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.LibraryPropertiesUrlFieldMissing, + RuleFunction: rulefunction.LibraryPropertiesURLFieldMissing, }, { ProjectType: projecttype.Library, @@ -919,7 +919,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: nil, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.LibraryPropertiesUrlFieldLTMinLength, + RuleFunction: rulefunction.LibraryPropertiesURLFieldLTMinLength, }, { ProjectType: projecttype.Library, @@ -935,7 +935,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: []rulemode.Type{rulemode.Permissive}, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.LibraryPropertiesUrlFieldInvalid, + RuleFunction: rulefunction.LibraryPropertiesURLFieldInvalid, }, { ProjectType: projecttype.Library, @@ -951,7 +951,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: []rulemode.Type{rulemode.Default}, ErrorModes: []rulemode.Type{rulemode.Strict}, - RuleFunction: rulefunction.LibraryPropertiesUrlFieldDeadLink, + RuleFunction: rulefunction.LibraryPropertiesURLFieldDeadLink, }, { ProjectType: projecttype.Library, @@ -3703,7 +3703,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: nil, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.PackageIndexPackagesPlatformsUrlMissing, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsURLMissing, }, { ProjectType: projecttype.PackageIndex, @@ -3719,7 +3719,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: nil, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.PackageIndexPackagesPlatformsUrlIncorrectType, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsURLIncorrectType, }, { ProjectType: projecttype.PackageIndex, @@ -3735,7 +3735,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: nil, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.PackageIndexPackagesPlatformsUrlInvalidFormat, + RuleFunction: rulefunction.PackageIndexPackagesPlatformsURLInvalidFormat, }, { ProjectType: projecttype.PackageIndex, @@ -4631,7 +4631,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: nil, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.PackageIndexPackagesToolsSystemsUrlMissing, + RuleFunction: rulefunction.PackageIndexPackagesToolsSystemsURLMissing, }, { ProjectType: projecttype.PackageIndex, @@ -4647,7 +4647,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: nil, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.PackageIndexPackagesToolsSystemsUrlIncorrectType, + RuleFunction: rulefunction.PackageIndexPackagesToolsSystemsURLIncorrectType, }, { ProjectType: projecttype.PackageIndex, @@ -4663,7 +4663,7 @@ var configurations = []Type{ InfoModes: nil, WarningModes: nil, ErrorModes: []rulemode.Type{rulemode.Default}, - RuleFunction: rulefunction.PackageIndexPackagesToolsSystemsUrlInvalidFormat, + RuleFunction: rulefunction.PackageIndexPackagesToolsSystemsURLInvalidFormat, }, { ProjectType: projecttype.PackageIndex, diff --git a/internal/rule/rulefunction/library.go b/internal/rule/rulefunction/library.go index e441ebf16..471d4294c 100644 --- a/internal/rule/rulefunction/library.go +++ b/internal/rule/rulefunction/library.go @@ -946,8 +946,8 @@ func LibraryPropertiesCategoryFieldUncategorized() (result ruleresult.Type, outp return ruleresult.Pass, "" } -// LibraryPropertiesUrlFieldMissing checks for missing library.properties "url" field. -func LibraryPropertiesUrlFieldMissing() (result ruleresult.Type, output string) { +// LibraryPropertiesURLFieldMissing checks for missing library.properties "url" field. +func LibraryPropertiesURLFieldMissing() (result ruleresult.Type, output string) { if projectdata.LibraryPropertiesLoadError() != nil { return ruleresult.NotRun, "Couldn't load library.properties" } @@ -962,8 +962,8 @@ func LibraryPropertiesUrlFieldMissing() (result ruleresult.Type, output string) return ruleresult.Pass, "" } -// LibraryPropertiesUrlFieldLTMinLength checks if the library.properties "url" value is less than the minimum length. -func LibraryPropertiesUrlFieldLTMinLength() (result ruleresult.Type, output string) { +// LibraryPropertiesURLFieldLTMinLength checks if the library.properties "url" value is less than the minimum length. +func LibraryPropertiesURLFieldLTMinLength() (result ruleresult.Type, output string) { if projectdata.LibraryPropertiesLoadError() != nil { return ruleresult.NotRun, "Couldn't load library.properties" } @@ -979,8 +979,8 @@ func LibraryPropertiesUrlFieldLTMinLength() (result ruleresult.Type, output stri return ruleresult.Pass, "" } -// LibraryPropertiesUrlFieldInvalid checks whether the library.properties "url" value has a valid URL format. -func LibraryPropertiesUrlFieldInvalid() (result ruleresult.Type, output string) { +// LibraryPropertiesURLFieldInvalid checks whether the library.properties "url" value has a valid URL format. +func LibraryPropertiesURLFieldInvalid() (result ruleresult.Type, output string) { if projectdata.LibraryPropertiesLoadError() != nil { return ruleresult.NotRun, "Couldn't load library.properties" } @@ -997,8 +997,8 @@ func LibraryPropertiesUrlFieldInvalid() (result ruleresult.Type, output string) return ruleresult.Pass, "" } -// LibraryPropertiesUrlFieldDeadLink checks whether the URL in the library.properties `url` field can be loaded. -func LibraryPropertiesUrlFieldDeadLink() (result ruleresult.Type, output string) { +// LibraryPropertiesURLFieldDeadLink checks whether the URL in the library.properties `url` field can be loaded. +func LibraryPropertiesURLFieldDeadLink() (result ruleresult.Type, output string) { if projectdata.LibraryPropertiesLoadError() != nil { return ruleresult.NotRun, "Couldn't load library.properties" } diff --git a/internal/rule/rulefunction/library_test.go b/internal/rule/rulefunction/library_test.go index eaa68d711..8cb59c2e6 100644 --- a/internal/rule/rulefunction/library_test.go +++ b/internal/rule/rulefunction/library_test.go @@ -736,7 +736,7 @@ func TestLibraryPropertiesUrlFieldMissing(t *testing.T) { {"Valid", "Recursive", ruleresult.Pass, ""}, } - checkLibraryRuleFunction(LibraryPropertiesUrlFieldMissing, testTables, t) + checkLibraryRuleFunction(LibraryPropertiesURLFieldMissing, testTables, t) } func TestLibraryPropertiesUrlFieldLTMinLength(t *testing.T) { @@ -747,7 +747,7 @@ func TestLibraryPropertiesUrlFieldLTMinLength(t *testing.T) { {"Valid", "Recursive", ruleresult.Pass, ""}, } - checkLibraryRuleFunction(LibraryPropertiesUrlFieldLTMinLength, testTables, t) + checkLibraryRuleFunction(LibraryPropertiesURLFieldLTMinLength, testTables, t) } func TestLibraryPropertiesUrlFieldInvalid(t *testing.T) { @@ -758,7 +758,7 @@ func TestLibraryPropertiesUrlFieldInvalid(t *testing.T) { {"Valid", "Recursive", ruleresult.Pass, ""}, } - checkLibraryRuleFunction(LibraryPropertiesUrlFieldInvalid, testTables, t) + checkLibraryRuleFunction(LibraryPropertiesURLFieldInvalid, testTables, t) } func TestLibraryPropertiesUrlFieldDeadLink(t *testing.T) { @@ -770,7 +770,7 @@ func TestLibraryPropertiesUrlFieldDeadLink(t *testing.T) { {"Good URL", "Recursive", ruleresult.Pass, ""}, } - checkLibraryRuleFunction(LibraryPropertiesUrlFieldDeadLink, testTables, t) + checkLibraryRuleFunction(LibraryPropertiesURLFieldDeadLink, testTables, t) } func TestLibraryPropertiesArchitecturesFieldMissing(t *testing.T) { diff --git a/internal/rule/rulefunction/packageindex.go b/internal/rule/rulefunction/packageindex.go index ebe272a6a..c18e083dd 100644 --- a/internal/rule/rulefunction/packageindex.go +++ b/internal/rule/rulefunction/packageindex.go @@ -1084,8 +1084,8 @@ func PackageIndexPackagesPlatformsHelpOnlineDeadLink() (result ruleresult.Type, return ruleresult.Pass, "" } -// PackageIndexPackagesPlatformsUrlMissing checks for missing packages[].platforms[].url property. -func PackageIndexPackagesPlatformsUrlMissing() (result ruleresult.Type, output string) { +// PackageIndexPackagesPlatformsURLMissing checks for missing packages[].platforms[].url property. +func PackageIndexPackagesPlatformsURLMissing() (result ruleresult.Type, output string) { if projectdata.PackageIndexLoadError() != nil { return ruleresult.NotRun, "Error loading package index" } @@ -1104,8 +1104,8 @@ func PackageIndexPackagesPlatformsUrlMissing() (result ruleresult.Type, output s return ruleresult.Pass, "" } -// PackageIndexPackagesPlatformsUrlIncorrectType checks for incorrect type of the packages[].platforms[].url property. -func PackageIndexPackagesPlatformsUrlIncorrectType() (result ruleresult.Type, output string) { +// PackageIndexPackagesPlatformsURLIncorrectType checks for incorrect type of the packages[].platforms[].url property. +func PackageIndexPackagesPlatformsURLIncorrectType() (result ruleresult.Type, output string) { if projectdata.PackageIndexLoadError() != nil { return ruleresult.NotRun, "Error loading package index" } @@ -1124,8 +1124,8 @@ func PackageIndexPackagesPlatformsUrlIncorrectType() (result ruleresult.Type, ou return ruleresult.Pass, "" } -// PackageIndexPackagesPlatformsUrlInvalidFormat checks for incorrect format of the packages[].platforms[].url property. -func PackageIndexPackagesPlatformsUrlInvalidFormat() (result ruleresult.Type, output string) { +// PackageIndexPackagesPlatformsURLInvalidFormat checks for incorrect format of the packages[].platforms[].url property. +func PackageIndexPackagesPlatformsURLInvalidFormat() (result ruleresult.Type, output string) { if projectdata.PackageIndexLoadError() != nil { return ruleresult.NotRun, "Error loading package index" } @@ -2255,8 +2255,8 @@ func PackageIndexPackagesToolsSystemsHostInvalid() (result ruleresult.Type, outp return ruleresult.Pass, "" } -// PackageIndexPackagesToolsSystemsUrlMissing checks for missing packages[].tools[].systems[].url property. -func PackageIndexPackagesToolsSystemsUrlMissing() (result ruleresult.Type, output string) { +// PackageIndexPackagesToolsSystemsURLMissing checks for missing packages[].tools[].systems[].url property. +func PackageIndexPackagesToolsSystemsURLMissing() (result ruleresult.Type, output string) { if projectdata.PackageIndexLoadError() != nil { return ruleresult.NotRun, "Error loading package index" } @@ -2275,8 +2275,8 @@ func PackageIndexPackagesToolsSystemsUrlMissing() (result ruleresult.Type, outpu return ruleresult.Pass, "" } -// PackageIndexPackagesToolsSystemsUrlIncorrectType checks for incorrect type of the packages[].tools[].systems[].url property. -func PackageIndexPackagesToolsSystemsUrlIncorrectType() (result ruleresult.Type, output string) { +// PackageIndexPackagesToolsSystemsURLIncorrectType checks for incorrect type of the packages[].tools[].systems[].url property. +func PackageIndexPackagesToolsSystemsURLIncorrectType() (result ruleresult.Type, output string) { if projectdata.PackageIndexLoadError() != nil { return ruleresult.NotRun, "Error loading package index" } @@ -2295,8 +2295,8 @@ func PackageIndexPackagesToolsSystemsUrlIncorrectType() (result ruleresult.Type, return ruleresult.Pass, "" } -// PackageIndexPackagesToolsSystemsUrlInvalidFormat checks for incorrect format of the packages[].tools[].systems[].url property. -func PackageIndexPackagesToolsSystemsUrlInvalidFormat() (result ruleresult.Type, output string) { +// PackageIndexPackagesToolsSystemsURLInvalidFormat checks for incorrect format of the packages[].tools[].systems[].url property. +func PackageIndexPackagesToolsSystemsURLInvalidFormat() (result ruleresult.Type, output string) { if projectdata.PackageIndexLoadError() != nil { return ruleresult.NotRun, "Error loading package index" } diff --git a/internal/rule/rulefunction/packageindex_test.go b/internal/rule/rulefunction/packageindex_test.go index 8e56c2384..a2100947f 100644 --- a/internal/rule/rulefunction/packageindex_test.go +++ b/internal/rule/rulefunction/packageindex_test.go @@ -599,7 +599,7 @@ func TestPackageIndexPackagesPlatformsUrlMissing(t *testing.T) { {"Valid", "valid-package-index", ruleresult.Pass, ""}, } - checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsUrlMissing, testTables, t) + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsURLMissing, testTables, t) } func TestPackageIndexPackagesPlatformsUrlIncorrectType(t *testing.T) { @@ -609,7 +609,7 @@ func TestPackageIndexPackagesPlatformsUrlIncorrectType(t *testing.T) { {"Valid", "valid-package-index", ruleresult.Pass, ""}, } - checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsUrlIncorrectType, testTables, t) + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsURLIncorrectType, testTables, t) } func TestPackageIndexPackagesPlatformsUrlInvalidFormat(t *testing.T) { @@ -619,7 +619,7 @@ func TestPackageIndexPackagesPlatformsUrlInvalidFormat(t *testing.T) { {"Valid", "valid-package-index", ruleresult.Pass, ""}, } - checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsUrlInvalidFormat, testTables, t) + checkPackageIndexRuleFunction(PackageIndexPackagesPlatformsURLInvalidFormat, testTables, t) } func TestPackageIndexPackagesPlatformsURLDeadLink(t *testing.T) { @@ -1179,7 +1179,7 @@ func TestPackageIndexPackagesToolsSystemsUrlMissing(t *testing.T) { {"Valid", "valid-package-index", ruleresult.Pass, ""}, } - checkPackageIndexRuleFunction(PackageIndexPackagesToolsSystemsUrlMissing, testTables, t) + checkPackageIndexRuleFunction(PackageIndexPackagesToolsSystemsURLMissing, testTables, t) } func TestPackageIndexPackagesToolsSystemsUrlIncorrectType(t *testing.T) { @@ -1189,7 +1189,7 @@ func TestPackageIndexPackagesToolsSystemsUrlIncorrectType(t *testing.T) { {"Valid", "valid-package-index", ruleresult.Pass, ""}, } - checkPackageIndexRuleFunction(PackageIndexPackagesToolsSystemsUrlIncorrectType, testTables, t) + checkPackageIndexRuleFunction(PackageIndexPackagesToolsSystemsURLIncorrectType, testTables, t) } func TestPackageIndexPackagesToolsSystemsUrlInvalidFormat(t *testing.T) { @@ -1199,7 +1199,7 @@ func TestPackageIndexPackagesToolsSystemsUrlInvalidFormat(t *testing.T) { {"Valid", "valid-package-index", ruleresult.Pass, ""}, } - checkPackageIndexRuleFunction(PackageIndexPackagesToolsSystemsUrlInvalidFormat, testTables, t) + checkPackageIndexRuleFunction(PackageIndexPackagesToolsSystemsURLInvalidFormat, testTables, t) } func TestPackageIndexPackagesToolsSystemsURLDeadLink(t *testing.T) { diff --git a/internal/rule/rulefunction/platform.go b/internal/rule/rulefunction/platform.go index dae4932bb..0803d1a38 100644 --- a/internal/rule/rulefunction/platform.go +++ b/internal/rule/rulefunction/platform.go @@ -1048,7 +1048,7 @@ func PlatformTxtCompilerCElfExtraFlagsMissing() (result ruleresult.Type, output return ruleresult.Pass, "" } -// PlatformTxtCompilerCExtraFlagsNotEmpty checks for non-empty compiler.c.extra_flags property in platform.txt. +// PlatformTxtCompilerCElfExtraFlagsNotEmpty checks for non-empty compiler.c.elf.extra_flags property in platform.txt. func PlatformTxtCompilerCElfExtraFlagsNotEmpty() (result ruleresult.Type, output string) { if !projectdata.PlatformTxtExists() { return ruleresult.Skip, "Platform has no platform.txt" diff --git a/internal/rule/ruleresult/ruleresult.go b/internal/rule/ruleresult/ruleresult.go index fde718a6c..5c1e523ea 100644 --- a/internal/rule/ruleresult/ruleresult.go +++ b/internal/rule/ruleresult/ruleresult.go @@ -21,10 +21,12 @@ package ruleresult type Type int const ( + // Pass indicates rule compliance. Pass Type = iota // pass - Fail // fail - // The rule is configured to be skipped in the current tool configuration mode + // Fail indicates a rule violation. + Fail // fail + // Skip indicates the rule is configured to be skipped in the current tool configuration mode. Skip // skipped - // An unrelated error prevented the rule from running + // NotRun indicates an unrelated error prevented the rule from running. NotRun // unable to run ) diff --git a/internal/rule/schema/parsevalidationresult.go b/internal/rule/schema/parsevalidationresult.go index 4d076f79d..0395ac6b2 100644 --- a/internal/rule/schema/parsevalidationresult.go +++ b/internal/rule/schema/parsevalidationresult.go @@ -64,7 +64,7 @@ func PropertyFormatMismatch(propertyName string, validationResult ValidationResu return ValidationErrorMatch("^#/?"+propertyName+"$", "/format$", "", "", validationResult) } -// ProhibitedAdditionalProperty returns whether the given property has prohibited additional subproperty(s). +// ProhibitedAdditionalProperties returns whether the given property has prohibited additional subproperty(s). func ProhibitedAdditionalProperties(propertyName string, validationResult ValidationResult) bool { return ValidationErrorMatch("^#/?"+propertyName+"$", "/additionalProperties$", "", "", validationResult) } From a897ddf2bd14577eb835cfa502e0f221c167cb0f Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 27 Jul 2021 23:02:47 -0700 Subject: [PATCH 17/17] Exclude generated code from Go package list This list is used for linting and formatting checks, which don't apply to tool generated code. --- Taskfile.yml | 2 +- internal/rule/schema/schemadata/bindata.go | 1 - internal/rule/schema/testdata/bindata.go | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index ef5101841..26ce413f9 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -278,7 +278,7 @@ vars: PROJECT_NAME: "arduino-lint" DIST_DIR: "dist" DEFAULT_GO_PACKAGES: - sh: echo `go list ./... | tr '\n' ' '` + sh: echo `go list ./... | grep --invert-match 'github.com/arduino/arduino-lint/internal/rule/schema/schemadata' | tr '\n' ' '` # build vars COMMIT: sh: echo "$(git log -n 1 --format=%h)" diff --git a/internal/rule/schema/schemadata/bindata.go b/internal/rule/schema/schemadata/bindata.go index 1ff2f050e..098658271 100644 --- a/internal/rule/schema/schemadata/bindata.go +++ b/internal/rule/schema/schemadata/bindata.go @@ -31,7 +31,6 @@ import ( "strings" "time" ) - type asset struct { bytes []byte info os.FileInfo diff --git a/internal/rule/schema/testdata/bindata.go b/internal/rule/schema/testdata/bindata.go index 4702b6a4b..2b542483e 100644 --- a/internal/rule/schema/testdata/bindata.go +++ b/internal/rule/schema/testdata/bindata.go @@ -16,7 +16,6 @@ import ( "strings" "time" ) - type asset struct { bytes []byte info os.FileInfo