Giter VIP home page Giter VIP logo

pre-commit-golang's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pre-commit-golang's Issues

Use `exclude` or another method to cause `cmd-repo-mod.bash` to ignore certain directories

cmd-repo-mod.bash will find all directories with a Go module except those that match */vendor/*; however, there are times when I need it to ignore more patterns then this.

For the moment, I have forked the repo and just hard-coded a workaround, but it would be really useful if that script would respect exclude or have some other mechanic to pass in a list of patterns.

Unknown flag --config with golangci-lint

Hello, after reading the doc, I faced an issue that I don't really understand.

Here is my precommit config :

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml

-   repo: https://github.com/tekwizely/pre-commit-golang
    rev: v1.0.0-rc.1
    # ? add a hook in the order you want to run it
    hooks:
    -   id: go-fmt
        name: go fmt
    -   id: golangci-lint
        name: go lint
        args: [--config .golangci.yaml]

    -   id: go-test-pkg
        name: go test
        args: ["--hook:env:GO111MODULE=on"]
        stages: [push]

But the run result in a weird error:
ERRO Can't get config for command line: can't parse args: unknown flag: --config .golangci.yaml

Since the doc itself recommande to use the --config args, idk what i'm doing wrong to have this error.

I tested with

        args: ["--", --config .golangci.yaml]

since i read that the first "--" is consumed but I'm really blocked rn.

Thank you for help

go-mod-tidy-repo should not update submodules

go-mod-tidy-repo is running for every directory and is updating go dependencies inside submodules which I am not supposed to touch.
It should run for directories for current git repo.
I believe git ls-files can be used to not touch submodules.

false typecheck failures only occuring in pre-commt lint check

I'm attempting to use this pre-commit hook in a number of my projects, but am consistently facing problems with false typecheck errors. When I run golangci-lint in the following cases:

  • manually on the command line with: golangci-lint run
  • within visual studio via golang plugin
  • in github actions ci

these typecheck failures do not occur. They only occur as part of the pre-commit execution. They are usually to do with an identifier not existing but they clearly do otherwise these other ways of running the lint would fail, and the test wouldn't pass and the executbles/library would not be runnable and they are.

So what is the issue here? I have also learned that typecheck is not a real linter, so it can't be disabled, so that's not a workaround. To be honest, I can't see the point of typecheck as it doesn't catch issues that wouldn't be caught by the compiler, its just proving to be a big headache.

Examples of the type of errors I'm seeing can be found here:

If there is a work-around for this problem, please can you let me know.

Unable to pass `-config .revive.toml` to revive hook.

I've tried multiple ways to pass a config file to revive, but it errors out every time:

  - repo: https://github.com/tekwizely/pre-commit-golang
    rev: v1.0.0-rc.1
    hooks:
      - id: go-fmt
      - id: go-revive
        args: [-config, .revive.toml]
cannot parse the config file: toml: line 1: expected '.' or '=', but got 'c' instead
cannot parse the config file: toml: line 1: expected '.' or '=', but got '/' instead
cannot parse the config file: toml: line 1: expected '.' or '=', but got 'c' instead
cannot parse the config file: toml: line 1: expected '.' or '=', but got 'm' instead

Running it manually with revive -config .revive.toml works completely fine.

      - id: go-revive
        args: ["--", -config, .revive.toml]

flag needs an argument: -config

      - id: go-revive
        args: ["--", "-config", ".revive.toml"]

flag needs an argument: -config

      - id: go-revive
        args: ["-config .revive.toml"]

flag provided but not defined: -config .revive.toml

Basic list of hooks for beginning Go devs

I'm learning Go and I love pre-commit. This repo has A LOT of hooks, many of them overlap and I'm a bit overwhelmed.

What is a beginner-friendly list of hooks to use for a small project?

Maybe an idea to put a simple example.yaml as a TL;DR in the README

golangci-lint-repo-mod doesn't respect skip-dirs

for sub in $(find . -name go.mod | xargs -n1 dirname | sort -u) ; do

➜  ldap git:(master) ✗ find . -name go.mod | xargs -n1 dirname | sort -u  
│.
│./vendor/github.com/caddyserver/caddy
│./vendor/github.com/cespare/xxhash/v2
│./vendor/github.com/google/uuid
│./vendor/github.com/miekg/dns
│./vendor/github.com/prometheus/procfs
│./vendor/google.golang.org/grpc
│./vendor/gopkg.in/ldap.v3

Does override: from golangci-lint docs

      --skip-dirs-use-default          Use or not use default excluded directories:
                                         - (^|/)vendor($|/)
                                         - (^|/)third_party($|/)
                                         - (^|/)testdata($|/)
                                         - (^|/)examples($|/)
                                         - (^|/)Godeps($|/)
                                         - (^|/)builtin($|/)
                                        (default true)

As a result execution is too slow.

Gosec fails when running as pre commit hook

My hook is configured as below

- repo: https://github.com/tekwizely/pre-commit-golang
  rev: 645165368711be670d1945c15060e746f5ed15c6
  hooks:
    - id: go-sec-repo-pkg
      args:
        - "-exclude-generated"

It should be noted that running gosec from the command like works just fine. Specifically I'm using the below command successfully

gosec -exclude-generated ./...

Both places gosec is installed using the below command

go install github.com/securego/gosec/v2/cmd/gosec@master

When I try to use gosec using the hooks provided by this repository I get a bunch of the following errors

...
Results:

Golang errors in file: [/home/tons/IdeaProjects/dhis2/im-database-manager/cmd/serve/main.go]:

  > [line 33 : column 2] - could not import github.com/aws/aws-sdk-go-v2/feature/s3/manager (invalid package name: "")

  > [line 35 : column 11] - could not import github.com/aws/aws-sdk-go-v2/config (invalid package name: "")

  > [line 36 : column 2] - could not import github.com/aws/aws-sdk-go-v2/service/s3 (invalid package name: "")

  > [line 38 : column 2] - could not import github.com/dhis2-sre/im-database-manager/internal/handler (invalid package name: "")

  > [line 39 : column 2] - could not import github.com/dhis2-sre/im-database-manager/internal/server (invalid package name: "")

  > [line 40 : column 2] - could not import github.com/dhis2-sre/im-database-manager/pkg/config (invalid package name: "")

  > [line 41 : column 2] - could not import github.com/dhis2-sre/im-database-manager/pkg/database (invalid package name: "")

  > [line 42 : column 2] - could not import github.com/dhis2-sre/im-database-manager/pkg/storage (invalid package name: "")

  > [line 43 : column 17] - could not import github.com/dhis2-sre/im-manager/pkg/client (invalid package name: "")

  > [line 44 : column 13] - could not import github.com/dhis2-sre/im-user/pkg/client (invalid package name: "")


Golang errors in file: [/home/tons/IdeaProjects/dhis2/im-database-manager/internal/apperror/apperror.go]:

  > [line 9 : column 2] - could not import github.com/gofrs/uuid (invalid package name: "")


Golang errors in file: [/home/tons/IdeaProjects/dhis2/im-database-manager/internal/handler/authentication.go]:

  > [line 10 : column 2] - could not import github.com/dhis2-sre/im-user/swagger/sdk/models (invalid package name: "")

  > [line 12 : column 2] - could not import github.com/dhis2-sre/im-database-manager/internal/apperror (invalid package name: "")

  > [line 13 : column 2] - could not import github.com/dhis2-sre/im-database-manager/pkg/config (invalid package name: "")

  > [line 15 : column 2] - could not import github.com/lestrrat-go/jwx/jwa (invalid package name: "")

  > [line 16 : column 2] - could not import github.com/lestrrat-go/jwx/jwk (invalid package name: "")

  > [line 17 : column 2] - could not import github.com/lestrrat-go/jwx/jwt (invalid package name: "")
...

This happens both locally and when running on GitHub as an Action (which can be seen here)

Any idea what goes wrong?

Building multiple modules

Hi TW

I have a project structure which looks like below (monorepo where I have multiple go applications inside the /cmd folder) and they consume their library code from internal directory

image

All the application main.go is inside

cmd/app1/main.go (all the shared code is inside internal/app/app1 & internal/pkg directory)
cmd/app2/main.go (all the shared code is inside internal/app/app2 & internal/pkg directory)
...

Top level go.mod & go.sum is common for all applications

Now how can i use pre-commit-golang hooks to build each application ?

As per my directory structure, I have few private packages under internal/pkg/common/types directory and I see an error

internal/mocks/MessagingClient.go:6:2: package test-module/internal/pkg/common/types is not in GOROOT (/Users/rk/sdk/go1.16.6/src/test-module/internal/pkg/common/types)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.