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

fix: filter files #5272

Merged
merged 3 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/golinters/godox/godox.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func runGodox(pass *analysis.Pass, settings *config.GodoxSettings) {
for _, file := range pass.Files {
position := goanalysis.GetFilePosition(pass, file)

if !strings.HasSuffix(position.Filename, ".go") {
continue
}

messages := godox.Run(file, pass.Fset, settings.Keywords...)
if len(messages) == 0 {
continue
Expand Down
4 changes: 4 additions & 0 deletions pkg/golinters/gofumpt/gofumpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func runGofumpt(lintCtx *linter.Context, pass *analysis.Pass, diff differ, optio
for _, file := range pass.Files {
position := goanalysis.GetFilePosition(pass, file)

if !strings.HasSuffix(position.Filename, ".go") {
continue
}

input, err := os.ReadFile(position.Filename)
if err != nil {
return fmt.Errorf("unable to open file %s: %w", position.Filename, err)
Expand Down
20 changes: 20 additions & 0 deletions pkg/golinters/gofumpt/testdata/fix/in/gofumpt_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//golangcitest:args -Egofumpt
//golangcitest:config_path testdata/gofumpt-fix.yml
//golangcitest:expected_exitcode 0
package p

/*
#include <stdio.h>
#include <stdlib.h>

void myprint(char* s) {
printf("%d\n", s);
}
*/
import "C"

import "fmt"

func GofmtNotExtra(bar string, baz string) {
fmt.Print(bar, baz)
}
20 changes: 20 additions & 0 deletions pkg/golinters/gofumpt/testdata/fix/out/gofumpt_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//golangcitest:args -Egofumpt
//golangcitest:config_path testdata/gofumpt-fix.yml
//golangcitest:expected_exitcode 0
package p

/*
#include <stdio.h>
#include <stdlib.h>

void myprint(char* s) {
printf("%d\n", s);
}
*/
import "C"

import "fmt"

func GofmtNotExtra(bar, baz string) {
fmt.Print(bar, baz)
}
5 changes: 5 additions & 0 deletions pkg/golinters/goimports/goimports.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package goimports

import (
"fmt"
"strings"

goimportsAPI "github.com/golangci/gofmt/goimports"
"golang.org/x/tools/go/analysis"
Expand Down Expand Up @@ -45,6 +46,10 @@ func runGoImports(lintCtx *linter.Context, pass *analysis.Pass) error {
for _, file := range pass.Files {
position := goanalysis.GetFilePosition(pass, file)

if !strings.HasSuffix(position.Filename, ".go") {
continue
}

diff, err := goimportsAPI.Run(position.Filename)
if err != nil { // TODO: skip
return err
Expand Down
25 changes: 25 additions & 0 deletions pkg/golinters/goimports/testdata/fix/in/goimports_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//golangcitest:args -Egoimports
//golangcitest:expected_exitcode 0
package p

/*
#include <stdio.h>
#include <stdlib.h>

void myprint(char* s) {
printf("%d\n", s);
}
*/
import "C"

import (
"os"
"fmt"
)

func goimports(a, b int) int {
if a != b {
return 1
}
return 2
}
20 changes: 20 additions & 0 deletions pkg/golinters/goimports/testdata/fix/out/goimports_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//golangcitest:args -Egoimports
//golangcitest:expected_exitcode 0
package p

/*
#include <stdio.h>
#include <stdlib.h>

void myprint(char* s) {
printf("%d\n", s);
}
*/
import "C"

func goimports(a, b int) int {
if a != b {
return 1
}
return 2
}
5 changes: 5 additions & 0 deletions pkg/golinters/lll/lll.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func runLll(pass *analysis.Pass, settings *config.LllSettings) error {

func getLLLIssuesForFile(pass *analysis.Pass, file *ast.File, maxLineLen int, tabSpaces string) error {
position := goanalysis.GetFilePosition(pass, file)

if !strings.HasSuffix(position.Filename, ".go") {
return nil
}

nonAdjPosition := pass.Fset.PositionFor(file.Pos(), false)

f, err := os.Open(position.Filename)
Expand Down
6 changes: 6 additions & 0 deletions pkg/golinters/nestif/nestif.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nestif

import (
"strings"

"github.com/nakabonne/nestif"
"golang.org/x/tools/go/analysis"

Expand Down Expand Up @@ -37,6 +39,10 @@ func runNestIf(pass *analysis.Pass, settings *config.NestifSettings) {
for _, file := range pass.Files {
position := goanalysis.GetFilePosition(pass, file)

if !strings.HasSuffix(position.Filename, ".go") {
continue
}

issues := checker.Check(file, pass.Fset)
if len(issues) == 0 {
continue
Expand Down
Loading