Skip to content

Commit

Permalink
Skip analysis of generated files (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
kseniadumpling authored May 24, 2024
1 parent 6e3ba97 commit cf0fb6d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wsl

import (
"flag"
"go/ast"
"strings"

"golang.org/x/tools/go/analysis"
Expand Down Expand Up @@ -75,6 +76,10 @@ func (wa *wslAnalyzer) flags() flag.FlagSet {

func (wa *wslAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
for _, file := range pass.Files {
if ast.IsGenerated(file) {
continue
}

filename := pass.Fset.PositionFor(file.Pos(), false).Filename
if !strings.HasSuffix(filename, ".go") {
continue
Expand Down
21 changes: 21 additions & 0 deletions testdata/src/default_config/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions testdata/src/default_config/generated.go.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Code generated by protoc-gen-go. DO NOT EDIT.

package chat

func _ChatService_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Message)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ChatServiceServer).SayHello(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/go.grpc.http.muxer.com.chat.v1.ChatService/SayHello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ChatServiceServer).SayHello(ctx, req.(*Message))
}
return interceptor(ctx, in, info, handler)
}

0 comments on commit cf0fb6d

Please sign in to comment.