Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our c...
歯磨き.goとは
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc....
歯磨き.goとは
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc....
自己紹介
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of ...
自己紹介
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for...
何を作っているか
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc....
何を作っているか
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc....
目次
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of ou...
目次
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for t...
静的解析がなぜ必要か
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the u...
静的解析がなぜ必要か
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD In...
静的解析がなぜ必要か
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD In...
静的解析がなぜ必要か
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD In...
はじめての静的解析
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the us...
今日作る静的解析のおしながき
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPA...
はじめての静的解析
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc...
はじめての静的解析
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc...
はじめての静的解析の開発手順
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPA...
はじめての静的解析
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc...
はじめての静的解析
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc...
はじめての静的解析
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc...
analysis package
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by AND...
analysis.Analyzer
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by AN...
analysis.Pass
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD...
analysis.Pass
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD...
テストデータを作成
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc...
import fmtを探すコード
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by AND...
動作
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for t...
プロジェクト独自定義
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD In...
レイヤードアーキテクチャ
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD ...
レイヤードアーキテクチャ
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD ...
レイヤードアーキテクチャ
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD ...
まとめ
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of o...
まとめ
Confidential
Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for ...
Upcoming SlideShare
Loading in …5
×
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

0

Share

Download to read offline

歯磨き.go Go言語の静的解析とコード生成勉強会

Download to read offline

アンドパッドが主催する Go言語の静的解析とコード生成勉強会

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

歯磨き.go Go言語の静的解析とコード生成勉強会

  1. 1. Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 歯磨き.go はじめての静的解析
  2. 2. 歯磨き.goとは Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 一過性の勉強会ではなく、少しずつ無理のない範囲で 毎日の歯磨きのように続けていくことを目的とした ゆるふわなgo勉強会です。 (もともと社内でやってたけどスピンオフしました)
  3. 3. 歯磨き.goとは Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 ・社内で静的解析の勉強会を始めたので  そのアウトプットの場になれば。会が進んできたら、 社内で 作った静的解析ツールを紹介(自慢)する場に  なれば良いなとか ・社内だけだと閉塞感でると思うので社外の方用のLT  枠も用意するのでぜひぜひ登壇したい方大歓迎。  ゆるふわな会なので怖く無いよ。
  4. 4. 自己紹介 Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止
  5. 5. 自己紹介 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 山下 大輔 Daisuke Yamashita ものづくり系エンジニア
 go言語に限らずものづくりに関わる開発は 全般的に好き。
 
 毎日使う最強のツールを作るのが目標。

  6. 6. 何を作っているか Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 全人類が日々感じる不便さ
  7. 7. 何を作っているか Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 全人類が日々感じる不便さ 建築業界 ANDPAD 建築業界特化型ツール
  8. 8. 目次 Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止
  9. 9. 目次 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 ・静的解析がなぜ必要か ・特定のパッケージ(fmt)を使っているか抽出しよう! ・レイヤードアーキテクチャでの依存方向の制約間違い
  を指摘する静的解析を作ろう!(プロジェクト独自定義)
  10. 10. 静的解析がなぜ必要か Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止
  11. 11. 静的解析がなぜ必要か Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 要件定義 実装 QAテスト リリース
  12. 12. 静的解析がなぜ必要か Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 要件定義 実装 QAテスト リリース 右の発見ほどコスト増 シフトレフト
  13. 13. 静的解析がなぜ必要か Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 要件定義 実装 QAテスト リリース 静的解析が活躍 自動テストが活躍
  14. 14. はじめての静的解析 Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止
  15. 15. 今日作る静的解析のおしながき Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 ① 特定のパッケージ(fmt)を使っているか抽出しよう!
 
 ②レイヤードアーキテクチャでの依存方向の制約間違い
  を指摘する静的解析を作ろう!(プロジェクト独自定義)

  16. 16. はじめての静的解析 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 特定のパッケージ(fmt)を使っているか抽出しよう!

  17. 17. はじめての静的解析 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 $ go install github.com/gostaticanalysis/skeleton@latest go 1.16以上 $ go get -u github.com/gostaticanalysis/skeleton go 1.16未満 https://github.com/gostaticanalysis/skeleton
  18. 18. はじめての静的解析の開発手順 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 ① 雛形の作成(skeleton実行するだけ)
 ② テストデータの作成
 ③ テスト実行
 ④ Analyzerのロジックを修正
 skeletonを使った実装

  19. 19. はじめての静的解析 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 $ skeleton -path=fmt_search 雛形を生成
  20. 20. はじめての静的解析 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 $ skeleton -path=fmt_search 雛形を生成 テストデータとし ての コード 開発はこちら
  21. 21. はじめての静的解析 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 $ cd fmt_search $ go mod tidy $ go test
  22. 22. analysis package Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 https://pkg.go.dev/golang.org/x/tools/go/analysis 静的解析をモジュール化するためのライブラリ 雛形生成で自動作成されています。
  23. 23. analysis.Analyzer Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 https://pkg.go.dev/golang.org/x/tools/go/analysis#Analyzer // Analyzer is ... var Analyzer = &analysis.Analyzer{ Name: "....", Doc: doc, Run: run, Requires: []*analysis.Analyzer{ inspect.Analyzer, }, } 静的解析の実行単位 自動生成されており、runで渡している 関数で実際の静的解析のロジックを 作成する。
  24. 24. analysis.Pass Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 https://pkg.go.dev/golang.org/x/tools/go/analysis#Pass func run(pass *analysis.Pass) (interface{}, error) { // 静的解析のロジックを書く } run関数に引数として渡されてくやつ。 ターゲットのソースコードを静的解析するための必要な情報が入ってい る。
  25. 25. analysis.Pass Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 https://pkg.go.dev/golang.org/x/tools/go/analysis#Pass type Pass struct { Fset *token.FileSet // file position information Files []*ast.File // the abstract syntax tree of each file Pkg *types.Package // type information about the package Report func(Diagnostic) ... }
  26. 26. テストデータを作成 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 fmt_search/testdata/src/a/a.go package a import "fmt" // want "fmt exists" func f() { fmt.Println("test") } importを検出するだけの シンプルなもの
  27. 27. import fmtを探すコード Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 fmt_search/fmt_search.go func run(pass *analysis.Pass) (interface{}, error) { for _, f := range pass.Files{ for _,imp := range f.Imports{ v, err := strconv.Unquote(imp.Path.Value) if err != nil{ return nil, err } if "fmt" == v { pass.Reportf(imp.Pos(), "%s is imported.", v) } } } return nil, nil } “”の文字列を削除
  28. 28. 動作 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 $ go test https://github.com/daisuke0131/fmt_search
  29. 29. プロジェクト独自定義 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 レイヤードアーキテクチャでの依存方向の制約間違い
  を指摘する静的解析を作ろう!
 (プロジェクト独自定義)

  30. 30. レイヤードアーキテクチャ Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 依存の方向 一番外側のレイヤー repositoryの実態とかhandlerとか 外界に依存しない、ビジネスロジック (repositoryのIFのみに依存したい) 依存が逆転してしまっているものを検 知したい!
  31. 31. レイヤードアーキテクチャ Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 https://github.com/daisuke0131/layer func run(pass *analysis.Pass) (interface{}, error) { for _, f := range pass.Files{ dir := pass.Fset.File(f.Pos()).Name() if strings.Contains(dir,"/usecase/service/"){ // infrastructureの層への依存はしない for _,imp := range f.Imports{ v, err := strconv.Unquote(imp.Path.Value) if err != nil{ return nil, err } if strings.Contains(v,"/infrastructure/") { pass.Reportf(imp.Pos(), "%s is invalid import.", v) } } } } return nil, nil }
  32. 32. レイヤードアーキテクチャ Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 https://github.com/daisuke0131/layer $ go test
  33. 33. まとめ Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止
  34. 34. まとめ Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止 ・ANDPADの開発でも自分たちで作った静的解析の  ツールを活用していくぞい! ・簡単な静的解析ツールの作り方を説明しました。  これくらいでも実用的なものを作れそう。

アンドパッドが主催する Go言語の静的解析とコード生成勉強会

Views

Total views

59

On Slideshare

0

From embeds

0

Number of embeds

25

Actions

Downloads

0

Shares

0

Comments

0

Likes

0

×