Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ func (wa *wslAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
continue
}

// if the file is related to cgo the filename of the unadjusted position is a not a '.go' file.
fn := pass.Fset.PositionFor(file.Pos(), false).Filename

// if the file is related to cgo the filename of the unadjusted position is a not a '.go' file.
if !strings.HasSuffix(fn, ".go") {
continue
}
Comment on lines +91 to +94
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just return pass.Fset.PositionFor(file.Pos(), false).Filename from getFilename, or even drop getFilename and just do this once? I don't think there's any need for first calling getFilename to get potential adjusted position/file and then again here to skip it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we do that, the line directive will not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For files with line directives:

  • adj: The filename is not a Go file
  • non-adj: The filename is a Go file

For files with cgo:

  • adj: The filename is a Go file
  • non-adj: The filename is not a Go file (but its' a Go file 😉)


// The file is skipped if the "unadjusted" file is a Go file, and it's a generated file (ex: "_test.go" file).
// The other non-Go files are skipped by the first 'if' with the adjusted position.
if !wa.config.IncludeGenerated && ast.IsGenerated(file) && strings.HasSuffix(fn, ".go") {
Expand Down
8 changes: 4 additions & 4 deletions testdata/src/default_config/cgo/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ func _() {

func Advanced() {
var foo = 1
var bar = 2 // want "declarations should never be cuddled"
var biz int // want "declarations should never be cuddled"
var bar = 2
var biz int

x := []string{}
x = append(x, "literal")
notUsed := "just assigning, don't mind me"
x = append(x, "not z..") // want "append only allowed to cuddle with appended value"
x = append(x, "not z..")
useMe := "right away"
alsoNotUsed := ":("
x = append(x, "just noise") // want "append only allowed to cuddle with appended value"
x = append(x, "just noise")
x = append(x, useMe)

_ = foo
Expand Down
Loading