Skip to content

GoLint pre-commit hook results in incorrect behavior #529

@varunpatro

Description

@varunpatro

Hello!

The GoLint pre-commit hook needs to be changed (I'm not sure of the best way) to accommodate linting over files in different packages. Let me explain further:

If I change one file main.go, then the GoLint hook runs golint main.go which is desirable and correct.

However, when I change files that belong to multiple packages such as:

  1. main.go
  2. lib/util.go

then the GoLint hook runs golint main.go lib/util.go which will always return the error (regardless of the presence of any lint errors)

lib/util.go is in package lib, not main

This is because golint can only be used in the following way (from golint --help:

Usage of golint:
golint [flags] # runs on package in current directory
golint [flags] [packages]
golint [flags] [directories] # where a '/...' suffix includes all sub-directories
golint [flags] [files] # all must belong to a single package

This means golint shouldn't be passed files that belong to different packages.

I think a possible way to solve this is to pass golint the folders of the changed files, instead of the files themselves.

I could create a PR to resolve this, but what would be the best way to mitigate this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions