Skip to content

daikieng/static_analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Static analysis tool

The better error handling suggestion for a concurrent execution using go routine.
Explore the docs »

View Demo

Table of Contents
  1. About The Project
  2. License
  3. Contact

About The Project

Static analysis is a great tool to find problems often related to performance, coding style, and some logic errors without running the application. I have implemented a tool that suggests to use sync.ErrGroup instead of sync.WaitGroup as sync.ErrGroup is generally more useful when you wish to handle error for groups of goroutines working on subtasks of a common task in parallel.

How I did it

When you run the test from error_handling_test.go, it prints out the following AST. Then, analyze the following AST tree that is comprised of AST nodes.

    88  .  .  .  .  .  1: *ast.GoStmt { <- AST node for Go Routine 
    89  .  .  .  .  .  .  Go: sample.go:11:2
    90  .  .  .  .  .  .  Call: *ast.CallExpr {
    91  .  .  .  .  .  .  .  Fun: *ast.FuncLit { <- AST node for function literal
    92  .  .  .  .  .  .  .  .  Type: *ast.FuncType {
    93  .  .  .  .  .  .  .  .  .  Func: sample.go:11:5
    94  .  .  .  .  .  .  .  .  .  Params: *ast.FieldList { <- AST node for field list
    95  .  .  .  .  .  .  .  .  .  .  Opening: sample.go:11:9
    96  .  .  .  .  .  .  .  .  .  .  List: []*ast.Field (len = 1) { <- contains one param
    97  .  .  .  .  .  .  .  .  .  .  .  0: *ast.Field {
    98  .  .  .  .  .  .  .  .  .  .  .  .  Names: []*ast.Ident (len = 1) {
    99  .  .  .  .  .  .  .  .  .  .  .  .  .  0: *ast.Ident {
   100  .  .  .  .  .  .  .  .  .  .  .  .  .  .  NamePos: sample.go:11:10
   101  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Name: "ch"
   102  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Obj: *ast.Object {
   103  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Kind: var
   104  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Name: "ch"
   105  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Decl: *(obj @ 97)
   106  .  .  .  .  .  .  .  .  .  .  .  .  .  .  }
   107  .  .  .  .  .  .  .  .  .  .  .  .  .  }
   108  .  .  .  .  .  .  .  .  .  .  .  .  }
   109  .  .  .  .  .  .  .  .  .  .  .  .  Type: *ast.ChanType {
   110  .  .  .  .  .  .  .  .  .  .  .  .  .  Begin: sample.go:11:13
   111  .  .  .  .  .  .  .  .  .  .  .  .  .  Arrow: - <- We care about only this arrow type for now.
   112  .  .  .  .  .  .  .  .  .  .  .  .  .  Dir: 3
   113  .  .  .  .  .  .  .  .  .  .  .  .  .  Value: *ast.Ident {
   114  .  .  .  .  .  .  .  .  .  .  .  .  .  .  NamePos: sample.go:11:18
   115  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Name: "error" <- if it uses error then we can confirm that this goroutine func is used for error handling
   116  .  .  .  .  .  .  .  .  .  .  .  .  .  }
   117  .  .  .  .  .  .  .  .  .  .  .  .  }
   118  .  .  .  .  .  .  .  .  .  .  .  }
   119  .  .  .  .  .  .  .  .  .  .  }
   120  .  .  .  .  .  .  .  .  .  .  Closing: sample.go:11:23
   121  .  .  .  .  .  .  .  .  .  }
   122  .  .  .  .  .  .  .  .  }

(back to top)

Built With

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Daiki Kubo - LinkedIn

Project Link: https://github.com/daikidev111/static_analysis

(back to top)

About

The better error handling suggestion for a concurrent execution using go routine.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages