diff --git a/.github/actionlint-matcher.json b/.github/actionlint-matcher.json new file mode 100644 index 0000000..4613e16 --- /dev/null +++ b/.github/actionlint-matcher.json @@ -0,0 +1,17 @@ +{ + "problemMatcher": [ + { + "owner": "actionlint", + "pattern": [ + { + "regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$", + "file": 1, + "line": 2, + "column": 3, + "message": 4, + "code": 5 + } + ] + } + ] +} diff --git a/.github/workflows/code-health-tools.yml b/.github/workflows/code-health-tools.yml new file mode 100644 index 0000000..14450fc --- /dev/null +++ b/.github/workflows/code-health-tools.yml @@ -0,0 +1,60 @@ +name: 'Code Health Tools' +on: + push: + branches: + - main + paths: + - 'tools/**' + pull_request: {} + workflow_dispatch: {} + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout CLI + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: Install Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 + with: + go-version-file: 'tools/cli/go.mod' + - name: Build CLI + run: | + pushd tools/cli + make build + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + with: + sparse-checkout: | + .github + tools + - name: Install Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 + with: + go-version-file: 'tools/cli/go.mod' + cache: false # see https://github.com/golangci/golangci-lint-action/issues/807 + - name: golangci-lint + uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 + with: + version: v1.56.2 + working-directory: tools/cli + - name: Checkout GitHub actions + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + with: + sparse-checkout: | + .github + - name: Download actionlint + id: get_actionlint + run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) + shell: bash + - name: Check workflow files + run: | + echo "::add-matcher::.github/actionlint-matcher.json" + ${{ steps.get_actionlint.outputs.executable }} -color + shell: bash diff --git a/tools/cli/.golangci.yml b/tools/cli/.golangci.yml new file mode 100644 index 0000000..59f2104 --- /dev/null +++ b/tools/cli/.golangci.yml @@ -0,0 +1,116 @@ +linters-settings: + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + govet: + check-shadowing: true + enable: + - fieldalignment + + revive: + # see https://github.com/mgechev/revive#available-rules for details. + ignore-generated-header: true + severity: warning + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: errorf + - name: exported + - name: indent-error-flow + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: struct-tag + - name: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + misspell: + locale: US + lll: + line-length: 120 + nestif: + # minimal complexity of if statements to report, 5 by default + min-complexity: 7 + gomnd: + settings: + mnd: + # don't include the "operation" and "assign" + checks: [case, return] + funlen: + lines: 360 + statements: 120 +linters: + disable-all: true + enable: + - dogsled + - errcheck + - funlen + - gocritic + - gofmt + - goimports + - revive + - gomnd + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - nolintlint + - rowserrcheck + - exportloopref + - staticcheck + - stylecheck + - typecheck + - unconvert + - unused + - whitespace + - thelper + - testifylint + - exhaustive + - makezero + - noctx + - tenv + - prealloc + - predeclared + - whitespace + + # don't enable: + # - deadcode + # - varcheck + # - structcheck + # - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false] + # - gocyclo # we already have funlen lint + # - dupl # we have a lot of duplicate test cases + # - gochecknoinits # we need the init function for the provider + # - gochecknoglobals # we need some global variables + # - unparam # Forces to create global variables when one variable is repeated in different functions + # - goerr113 # It does not allow you to return an error, you need to save the error in a variable to do it + # - goconst + # - gocognit + +run: + timeout: 10m + tests: true + modules-download-mode: readonly diff --git a/tools/cli/Makefile b/tools/cli/Makefile index c1e8608..8dc6f04 100644 --- a/tools/cli/Makefile +++ b/tools/cli/Makefile @@ -1,5 +1,6 @@ # A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +GOLANGCI_VERSION=v1.56.2 SOURCE_FILES?=./cmd BINARY_NAME=openapicli VERSION=v0.0.1 @@ -20,8 +21,13 @@ deps: ## Download go module dependencies go mod download go mod tidy +.PHONY: devtools +devtools: ## Install dev tools + @echo "==> Installing dev tools..." + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION) + .PHONY: setup -setup: deps ## Set up dev env +setup: deps devtools ## Set up dev env .PHONY: fmt fmt: ### Format all go files with goimports and gofmt @@ -39,6 +45,13 @@ build-debug: @echo "==> Building openapicli binary for debugging" go build -gcflags="$(DEBUG_FLAGS)" -ldflags "$(LINKER_FLAGS)" -o $(DESTINATION) $(SOURCE_FILES) +.PHONY: lint +lint: ## Run linter + golangci-lint run + +.PHONY: fix-lint +fix-lint: ## Fix linting errors + golangci-lint run --fix .PHONY: list list: ## List all make targets diff --git a/tools/cli/internal/cli/merge/merge.go b/tools/cli/internal/cli/merge/merge.go index 249bcde..1aee19b 100644 --- a/tools/cli/internal/cli/merge/merge.go +++ b/tools/cli/internal/cli/merge/merge.go @@ -20,25 +20,15 @@ import ( ) type Opts struct { - Base *load.SpecInfo - outputPath string + Base *load.SpecInfo } -func (o *Opts) Run(args []string) error { +func (o *Opts) Run(_ []string) error { // To add in follow up PR: CLOUDP-225849 return nil } -func (o *Opts) removeExternalReferences(paths []string, federated *load.SpecInfo) ([]byte, error) { - // To add in follow up PR: CLOUDP-225849 - return nil, nil - -} -func (o *Opts) saveFile(data []byte) error { - return nil -} - -func (o *Opts) PreRunE(args []string) error { +func (o *Opts) PreRunE(_ []string) error { // To Add in follow up PR: CLOUDP-225849 return nil } @@ -50,10 +40,10 @@ func Builder() *cobra.Command { Use: "merge [base-spec] [spec-1] [spec-2] [spec-3] ... [spec-n]", Short: "Merge Open API specifications into a base spec.", Args: cobra.MinimumNArgs(2), - PreRunE: func(cmd *cobra.Command, args []string) error { + PreRunE: func(_ *cobra.Command, args []string) error { return opts.PreRunE(args) }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { return opts.Run(args) }, }