golangci / golangci-lint-action

Official GitHub Action for golangci-lint from its authors
https://github.com/marketplace/actions/golangci-lint
MIT License
1.07k stars 147 forks source link

Static type checks doesn't include embedded types with github action #1058

Closed dorimon-1 closed 3 months ago

dorimon-1 commented 3 months ago

Welcome

Description of the problem

Well I hope im not mistaken and there isn't any issues regarding this. Whenever I'm doing a check on my code base which contains a type with embedded types in it. ex:

type FtpClient struct {
    *goftp.Client
    *config.FtpConfiguration
}

I get a linting error only when doing a check with golangci-lint and I get these errors:

Error: ftp/ftp.go:61:39: client.FtpServerPath undefined (type *FtpClient has no field or method FtpServerPath) (typecheck)
        path := fmt.Sprintf("%s/%s", client.FtpServerPath, file)
                                            ^
  Error: ftp/ftp.go:62:16: client.Retrieve undefined (type *FtpClient has no field or method Retrieve) (typecheck)
        err = client.Retrieve(path, buffer)
                     ^
  Error: ftp/ftp.go:70:23: client.ReadDir undefined (type *FtpClient has no field or method ReadDir) (typecheck)
    files, err := client.ReadDir(client.FtpServerPath)

My building is passing just fine and I don't get any linting on my code editor

Version of golangci-lint

1.59

Version of the GitHub Action

latest? unsure what versions there are

Workflow file

```yml # This workflow will build a golang project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go name: golangci-lint on: push: branches: - main - master pull_request: permissions: contents: read # Optional: allow read access to pull request. Use with `only-new-issues` option. # pull-requests: read jobs: golangci: name: lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: '1.22.3' - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: version: v1.59 ```

Golangci-lint configuration

```yml ```

Go version

1.22.3

Code example or link to a public repository

```go type FtpClient struct { *goftp.Client *config.FtpConfiguration } client, err := goftp.DialConfig(ftpConfig, config.FtpServerURL) ``` repo: https://github.com/KJone1/ImageElevator/blob/master/ftp/ftp.go
ldez commented 3 months ago

Hello,

I recommend reading https://golangci-lint.run/welcome/faq/#why-do-you-have-typecheck-errors

The problem is not embedded types.

ldez commented 3 months ago

:thinking: I'm trying to understand the behavior inside your CI.

https://github.com/KJone1/ImageElevator/actions/runs/9423135394/job/25960911614

ldez commented 3 months ago

Maybe it's a side effect of the divergence between your module name github.com/Kjone1/imageElevator and your repo name https://github.com/KJone1/ImageElevator :thinking:

ldez commented 3 months ago

Do you depend on cgo?

ldez commented 3 months ago

Yes, you are depending on cgo:

So you need to install the cgo dependency inside the golangci-lint workflow. https://github.com/KJone1/ImageElevator/blob/8a157b63a67c8aa2941fc9a9e686580f2dfab268/.github/workflows/lint.yml

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: golangci-lint
on:
  push:
    branches:
      - main
      - master
  pull_request:

permissions:
  contents: read
  # Optional: allow read access to pull request. Use with `only-new-issues` option.
  # pull-requests: read

jobs:
  golangci:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: '1.22.3'

      - name: ⚙️ Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y
          sudo apt-get install libbtrfs-dev -y
          sudo apt-get install libgpgme-dev -y

      - name: golangci-lint
        uses: golangci/golangci-lint-action@v6
        with:
          version: v1.59
dorimon-1 commented 3 months ago

Much appreciated, and apologizes for the miss information