Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goheader: fix invalid position #5238

Merged
merged 8 commits into from
Dec 18, 2024
Merged

goheader: fix invalid position #5238

merged 8 commits into from
Dec 18, 2024

Conversation

ldez
Copy link
Member

@ldez ldez commented Dec 18, 2024

Location() returns the position of the first element that needs to be changed, and Expected contains all the header lines.

If the first element to change is at L3 and the beginning of the header is at L1, you have a beautiful Christmas tree based on comment separators.

The problem has been here since the introduction of the auto fix for goheader (golangci-lint v1.57.0).

https://github.com/golangci/golangci-lint/pull/4396/files#diff-36750bd1c0da16befa607266d41aca09351630ed97e4ae48f96b63f60e6cbb6dR103

To reproduce
/*
Copyright 2024 The Awesome Project Authors

Use of this source code is governed by LICENSE
*/
package sandbox

func Foo() {}
linters:
  disable-all: true
  enable:
    - goheader

linters-settings:
  goheader:
    values:
      const:
        AUTHOR: The Awesome Project Authors
    template: |-
        Copyright 2024 {{ AUTHOR }}
  
        Use of this source code is governed by LICENSE.md

Then run golangci-lint run --fix


Also now it displays the right position of the problem.

Before:

$ golangci-lint run                                                
main.go:3:47: Missed string: .md (goheader)

Use of this source code is governed by LICENSE
*/

package sandbox
$ 

After:

$ ./golangci-lint run
main.go:4:47: Missed string: .md (goheader)
Use of this source code is governed by LICENSE
                                              ^
$ 

@ldez ldez added bug Something isn't working linter: update Update the linter implementation inside golangci-lint labels Dec 18, 2024
@ldez ldez added this to the next milestone Dec 18, 2024
@ldez ldez merged commit f5cca90 into golangci:master Dec 18, 2024
15 checks passed
@ldez ldez deleted the fix/goheader branch December 18, 2024 22:31
@ldez ldez modified the milestones: next, v1.63 Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linter: update Update the linter implementation inside golangci-lint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants