SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
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
はじめての静的解析
歯磨き.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勉強会です。
(もともと社内でやってたけどスピンオフしました)
歯磨き.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
 枠も用意するのでぜひぜひ登壇したい方大歓迎。
 ゆるふわな会なので怖く無いよ。
自己紹介
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 無断転載・無断複製の禁止
自己紹介
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言語に限らずものづくりに関わる開発は
全般的に好き。



毎日使う最強のツールを作るのが目標。

何を作っているか
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. 無断転載・無断複製の禁止
全人類が日々感じる不便さ
何を作っているか
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
建築業界特化型ツール
目次
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 無断転載・無断複製の禁止
目次
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)を使っているか抽出しよう!
・レイヤードアーキテクチャでの依存方向の制約間違い

 を指摘する静的解析を作ろう!(プロジェクト独自定義)
静的解析がなぜ必要か
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 無断転載・無断複製の禁止
静的解析がなぜ必要か
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テスト リリース
静的解析がなぜ必要か
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テスト リリース
右の発見ほどコスト増
シフトレフト
静的解析がなぜ必要か
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テスト リリース
静的解析が活躍
自動テストが活躍
はじめての静的解析
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 無断転載・無断複製の禁止
今日作る静的解析のおしながき
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)を使っているか抽出しよう!



②レイヤードアーキテクチャでの依存方向の制約間違い

 を指摘する静的解析を作ろう!(プロジェクト独自定義)

はじめての静的解析
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)を使っているか抽出しよう!

はじめての静的解析
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
はじめての静的解析の開発手順
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を使った実装

はじめての静的解析
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
雛形を生成
はじめての静的解析
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
雛形を生成
テストデータとし
ての
コード
開発はこちら
はじめての静的解析
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
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
静的解析をモジュール化するためのライブラリ
雛形生成で自動作成されています。
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で渡している
関数で実際の静的解析のロジックを
作成する。
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関数に引数として渡されてくやつ。
ターゲットのソースコードを静的解析するための必要な情報が入ってい
る。
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)
...
}
テストデータを作成
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を検出するだけの
シンプルなもの
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
}
“”の文字列を削除
動作
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
プロジェクト独自定義
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. 無断転載・無断複製の禁止
レイヤードアーキテクチャでの依存方向の制約間違い

 を指摘する静的解析を作ろう!

(プロジェクト独自定義)

レイヤードアーキテクチャ
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のみに依存したい)
依存が逆転してしまっているものを検
知したい!
レイヤードアーキテクチャ
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
}
レイヤードアーキテクチャ
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
まとめ
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 無断転載・無断複製の禁止
まとめ
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の開発でも自分たちで作った静的解析の
 ツールを活用していくぞい!
・簡単な静的解析ツールの作り方を説明しました。
 これくらいでも実用的なものを作れそう。

Contenu connexe

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

How resolve Gem dependencies in your code?
How resolve Gem dependencies in your code?How resolve Gem dependencies in your code?
How resolve Gem dependencies in your code?Hiroshi SHIBATA
 
Your Code Isn’t Static. Your Processes Shouldn’t be Either.
Your Code Isn’t Static. Your Processes Shouldn’t be Either.Your Code Isn’t Static. Your Processes Shouldn’t be Either.
Your Code Isn’t Static. Your Processes Shouldn’t be Either.DevOps.com
 
How resolve Gem dependencies in your code?
How resolve Gem dependencies in your code?How resolve Gem dependencies in your code?
How resolve Gem dependencies in your code?Hiroshi SHIBATA
 
Ivanti for msp
Ivanti for mspIvanti for msp
Ivanti for mspIvanti
 
Workspace Control 2020 now with Ivanti Neurons for Edge Intelligence
Workspace Control 2020 now with Ivanti Neurons for Edge IntelligenceWorkspace Control 2020 now with Ivanti Neurons for Edge Intelligence
Workspace Control 2020 now with Ivanti Neurons for Edge IntelligenceIvanti
 
Near Real-time Outlier Detection and Interpretation - Part 1 by Robert Thorma...
Near Real-time Outlier Detection and Interpretation - Part 1 by Robert Thorma...Near Real-time Outlier Detection and Interpretation - Part 1 by Robert Thorma...
Near Real-time Outlier Detection and Interpretation - Part 1 by Robert Thorma...DataWorks Summit/Hadoop Summit
 
Making Microservices Smarter with Istio, Envoy and Pivotal Ingress Router
Making Microservices Smarter with Istio, Envoy and Pivotal Ingress RouterMaking Microservices Smarter with Istio, Envoy and Pivotal Ingress Router
Making Microservices Smarter with Istio, Envoy and Pivotal Ingress RouterVMware Tanzu
 
Building a Stock Prediction system with Machine Learning using Geode, SpringX...
Building a Stock Prediction system with Machine Learning using Geode, SpringX...Building a Stock Prediction system with Machine Learning using Geode, SpringX...
Building a Stock Prediction system with Machine Learning using Geode, SpringX...William Markito Oliveira
 
Maintainability Sogeti Qx Day 2020
Maintainability Sogeti Qx Day 2020Maintainability Sogeti Qx Day 2020
Maintainability Sogeti Qx Day 2020Peter Rombouts
 
𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐢𝐯𝐞 𝐀𝐈: 𝐂𝐡𝐚𝐧𝐠𝐢𝐧𝐠 𝐇𝐨𝐰 𝐁𝐮𝐬𝐢𝐧𝐞𝐬𝐬 𝐈𝐧𝐧𝐨𝐯𝐚𝐭𝐞𝐬 𝐚𝐧𝐝 𝐎𝐩𝐞𝐫𝐚𝐭𝐞𝐬
𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐢𝐯𝐞 𝐀𝐈: 𝐂𝐡𝐚𝐧𝐠𝐢𝐧𝐠 𝐇𝐨𝐰 𝐁𝐮𝐬𝐢𝐧𝐞𝐬𝐬 𝐈𝐧𝐧𝐨𝐯𝐚𝐭𝐞𝐬 𝐚𝐧𝐝 𝐎𝐩𝐞𝐫𝐚𝐭𝐞𝐬𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐢𝐯𝐞 𝐀𝐈: 𝐂𝐡𝐚𝐧𝐠𝐢𝐧𝐠 𝐇𝐨𝐰 𝐁𝐮𝐬𝐢𝐧𝐞𝐬𝐬 𝐈𝐧𝐧𝐨𝐯𝐚𝐭𝐞𝐬 𝐚𝐧𝐝 𝐎𝐩𝐞𝐫𝐚𝐭𝐞𝐬
𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐢𝐯𝐞 𝐀𝐈: 𝐂𝐡𝐚𝐧𝐠𝐢𝐧𝐠 𝐇𝐨𝐰 𝐁𝐮𝐬𝐢𝐧𝐞𝐬𝐬 𝐈𝐧𝐧𝐨𝐯𝐚𝐭𝐞𝐬 𝐚𝐧𝐝 𝐎𝐩𝐞𝐫𝐚𝐭𝐞𝐬VINCI Digital - Industrial IoT (IIoT) Strategic Advisory
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
ANTI-ANTI-CODE-MODIFICATION MiSSConf(SP5) 2019
ANTI-ANTI-CODE-MODIFICATION MiSSConf(SP5) 2019ANTI-ANTI-CODE-MODIFICATION MiSSConf(SP5) 2019
ANTI-ANTI-CODE-MODIFICATION MiSSConf(SP5) 2019Boonpoj Thongakaraniroj
 
Business Success with Core Web Vitals
Business Success with Core Web VitalsBusiness Success with Core Web Vitals
Business Success with Core Web VitalsIzzi Smith
 
Secure Your Edge-to-Cloud IoT Solution with Intel and AWS - IOT337 - re:Inven...
Secure Your Edge-to-Cloud IoT Solution with Intel and AWS - IOT337 - re:Inven...Secure Your Edge-to-Cloud IoT Solution with Intel and AWS - IOT337 - re:Inven...
Secure Your Edge-to-Cloud IoT Solution with Intel and AWS - IOT337 - re:Inven...Amazon Web Services
 
Pentesting Android Applications
Pentesting Android ApplicationsPentesting Android Applications
Pentesting Android ApplicationsCláudio André
 
Linux Foundation Live Webinar: Applying Governance to CI/CD
Linux Foundation Live Webinar: Applying Governance to CI/CDLinux Foundation Live Webinar: Applying Governance to CI/CD
Linux Foundation Live Webinar: Applying Governance to CI/CDTiffany Jachja
 
INTRODUCTION TO IVANTI NEURONS
INTRODUCTION TO IVANTI NEURONSINTRODUCTION TO IVANTI NEURONS
INTRODUCTION TO IVANTI NEURONSIvanti
 
"Logo Maker’s micro guts — micro frontend at Fiverr", Yuriy Dadichin
"Logo Maker’s micro guts — micro frontend at Fiverr", Yuriy Dadichin"Logo Maker’s micro guts — micro frontend at Fiverr", Yuriy Dadichin
"Logo Maker’s micro guts — micro frontend at Fiverr", Yuriy DadichinFwdays
 
CODE BLUE 2014 : Persisted: The active use and exploitation of Microsoft's Ap...
CODE BLUE 2014 : Persisted: The active use and exploitation of Microsoft's Ap...CODE BLUE 2014 : Persisted: The active use and exploitation of Microsoft's Ap...
CODE BLUE 2014 : Persisted: The active use and exploitation of Microsoft's Ap...CODE BLUE
 

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

How resolve Gem dependencies in your code?
How resolve Gem dependencies in your code?How resolve Gem dependencies in your code?
How resolve Gem dependencies in your code?
 
Your Code Isn’t Static. Your Processes Shouldn’t be Either.
Your Code Isn’t Static. Your Processes Shouldn’t be Either.Your Code Isn’t Static. Your Processes Shouldn’t be Either.
Your Code Isn’t Static. Your Processes Shouldn’t be Either.
 
How resolve Gem dependencies in your code?
How resolve Gem dependencies in your code?How resolve Gem dependencies in your code?
How resolve Gem dependencies in your code?
 
Ivanti for msp
Ivanti for mspIvanti for msp
Ivanti for msp
 
Workspace Control 2020 now with Ivanti Neurons for Edge Intelligence
Workspace Control 2020 now with Ivanti Neurons for Edge IntelligenceWorkspace Control 2020 now with Ivanti Neurons for Edge Intelligence
Workspace Control 2020 now with Ivanti Neurons for Edge Intelligence
 
Near Real-time Outlier Detection and Interpretation - Part 1 by Robert Thorma...
Near Real-time Outlier Detection and Interpretation - Part 1 by Robert Thorma...Near Real-time Outlier Detection and Interpretation - Part 1 by Robert Thorma...
Near Real-time Outlier Detection and Interpretation - Part 1 by Robert Thorma...
 
Near Real-Time Outlier Detection and Interpretation
Near Real-Time Outlier Detection and InterpretationNear Real-Time Outlier Detection and Interpretation
Near Real-Time Outlier Detection and Interpretation
 
Making Microservices Smarter with Istio, Envoy and Pivotal Ingress Router
Making Microservices Smarter with Istio, Envoy and Pivotal Ingress RouterMaking Microservices Smarter with Istio, Envoy and Pivotal Ingress Router
Making Microservices Smarter with Istio, Envoy and Pivotal Ingress Router
 
Building a Stock Prediction system with Machine Learning using Geode, SpringX...
Building a Stock Prediction system with Machine Learning using Geode, SpringX...Building a Stock Prediction system with Machine Learning using Geode, SpringX...
Building a Stock Prediction system with Machine Learning using Geode, SpringX...
 
Maintainability Sogeti Qx Day 2020
Maintainability Sogeti Qx Day 2020Maintainability Sogeti Qx Day 2020
Maintainability Sogeti Qx Day 2020
 
𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐢𝐯𝐞 𝐀𝐈: 𝐂𝐡𝐚𝐧𝐠𝐢𝐧𝐠 𝐇𝐨𝐰 𝐁𝐮𝐬𝐢𝐧𝐞𝐬𝐬 𝐈𝐧𝐧𝐨𝐯𝐚𝐭𝐞𝐬 𝐚𝐧𝐝 𝐎𝐩𝐞𝐫𝐚𝐭𝐞𝐬
𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐢𝐯𝐞 𝐀𝐈: 𝐂𝐡𝐚𝐧𝐠𝐢𝐧𝐠 𝐇𝐨𝐰 𝐁𝐮𝐬𝐢𝐧𝐞𝐬𝐬 𝐈𝐧𝐧𝐨𝐯𝐚𝐭𝐞𝐬 𝐚𝐧𝐝 𝐎𝐩𝐞𝐫𝐚𝐭𝐞𝐬𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐢𝐯𝐞 𝐀𝐈: 𝐂𝐡𝐚𝐧𝐠𝐢𝐧𝐠 𝐇𝐨𝐰 𝐁𝐮𝐬𝐢𝐧𝐞𝐬𝐬 𝐈𝐧𝐧𝐨𝐯𝐚𝐭𝐞𝐬 𝐚𝐧𝐝 𝐎𝐩𝐞𝐫𝐚𝐭𝐞𝐬
𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐢𝐯𝐞 𝐀𝐈: 𝐂𝐡𝐚𝐧𝐠𝐢𝐧𝐠 𝐇𝐨𝐰 𝐁𝐮𝐬𝐢𝐧𝐞𝐬𝐬 𝐈𝐧𝐧𝐨𝐯𝐚𝐭𝐞𝐬 𝐚𝐧𝐝 𝐎𝐩𝐞𝐫𝐚𝐭𝐞𝐬
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
ANTI-ANTI-CODE-MODIFICATION MiSSConf(SP5) 2019
ANTI-ANTI-CODE-MODIFICATION MiSSConf(SP5) 2019ANTI-ANTI-CODE-MODIFICATION MiSSConf(SP5) 2019
ANTI-ANTI-CODE-MODIFICATION MiSSConf(SP5) 2019
 
Business Success with Core Web Vitals
Business Success with Core Web VitalsBusiness Success with Core Web Vitals
Business Success with Core Web Vitals
 
Secure Your Edge-to-Cloud IoT Solution with Intel and AWS - IOT337 - re:Inven...
Secure Your Edge-to-Cloud IoT Solution with Intel and AWS - IOT337 - re:Inven...Secure Your Edge-to-Cloud IoT Solution with Intel and AWS - IOT337 - re:Inven...
Secure Your Edge-to-Cloud IoT Solution with Intel and AWS - IOT337 - re:Inven...
 
Pentesting Android Applications
Pentesting Android ApplicationsPentesting Android Applications
Pentesting Android Applications
 
Linux Foundation Live Webinar: Applying Governance to CI/CD
Linux Foundation Live Webinar: Applying Governance to CI/CDLinux Foundation Live Webinar: Applying Governance to CI/CD
Linux Foundation Live Webinar: Applying Governance to CI/CD
 
INTRODUCTION TO IVANTI NEURONS
INTRODUCTION TO IVANTI NEURONSINTRODUCTION TO IVANTI NEURONS
INTRODUCTION TO IVANTI NEURONS
 
"Logo Maker’s micro guts — micro frontend at Fiverr", Yuriy Dadichin
"Logo Maker’s micro guts — micro frontend at Fiverr", Yuriy Dadichin"Logo Maker’s micro guts — micro frontend at Fiverr", Yuriy Dadichin
"Logo Maker’s micro guts — micro frontend at Fiverr", Yuriy Dadichin
 
CODE BLUE 2014 : Persisted: The active use and exploitation of Microsoft's Ap...
CODE BLUE 2014 : Persisted: The active use and exploitation of Microsoft's Ap...CODE BLUE 2014 : Persisted: The active use and exploitation of Microsoft's Ap...
CODE BLUE 2014 : Persisted: The active use and exploitation of Microsoft's Ap...
 

Plus de Daisuke Yamashita

Introduction of ios-chart in oss-labs#3
Introduction of ios-chart in oss-labs#3Introduction of ios-chart in oss-labs#3
Introduction of ios-chart in oss-labs#3Daisuke Yamashita
 
About SnapKit - Open source lab -
About SnapKit - Open source lab -About SnapKit - Open source lab -
About SnapKit - Open source lab -Daisuke Yamashita
 
Swift open source library - ViewMonitor -
Swift open source library - ViewMonitor -Swift open source library - ViewMonitor -
Swift open source library - ViewMonitor -Daisuke Yamashita
 
Let's Start Swift Open Source Activity.
Let's Start Swift Open Source Activity.Let's Start Swift Open Source Activity.
Let's Start Swift Open Source Activity.Daisuke Yamashita
 
バグのことは嫌いになってもXcodeのことは嫌いにならないでください。
バグのことは嫌いになってもXcodeのことは嫌いにならないでください。バグのことは嫌いになってもXcodeのことは嫌いにならないでください。
バグのことは嫌いになってもXcodeのことは嫌いにならないでください。Daisuke Yamashita
 
Unity Introduction from 2D shooting game.
Unity Introduction from 2D shooting game.Unity Introduction from 2D shooting game.
Unity Introduction from 2D shooting game.Daisuke Yamashita
 
Introduction of Swift from Machine Learning
Introduction of Swift from Machine LearningIntroduction of Swift from Machine Learning
Introduction of Swift from Machine LearningDaisuke Yamashita
 
Introduction of Swift from Game Development
Introduction of Swift from Game DevelopmentIntroduction of Swift from Game Development
Introduction of Swift from Game DevelopmentDaisuke Yamashita
 
How to measure UIView position on Native App
How to measure UIView position on Native AppHow to measure UIView position on Native App
How to measure UIView position on Native AppDaisuke Yamashita
 

Plus de Daisuke Yamashita (12)

Tensorflow
TensorflowTensorflow
Tensorflow
 
Introduction of ios-chart in oss-labs#3
Introduction of ios-chart in oss-labs#3Introduction of ios-chart in oss-labs#3
Introduction of ios-chart in oss-labs#3
 
About SnapKit - Open source lab -
About SnapKit - Open source lab -About SnapKit - Open source lab -
About SnapKit - Open source lab -
 
View Monitoring Tips
View Monitoring TipsView Monitoring Tips
View Monitoring Tips
 
Swift open source library - ViewMonitor -
Swift open source library - ViewMonitor -Swift open source library - ViewMonitor -
Swift open source library - ViewMonitor -
 
Let's Start Swift Open Source Activity.
Let's Start Swift Open Source Activity.Let's Start Swift Open Source Activity.
Let's Start Swift Open Source Activity.
 
バグのことは嫌いになってもXcodeのことは嫌いにならないでください。
バグのことは嫌いになってもXcodeのことは嫌いにならないでください。バグのことは嫌いになってもXcodeのことは嫌いにならないでください。
バグのことは嫌いになってもXcodeのことは嫌いにならないでください。
 
Unity Introduction from 2D shooting game.
Unity Introduction from 2D shooting game.Unity Introduction from 2D shooting game.
Unity Introduction from 2D shooting game.
 
OpenCV on mobile
OpenCV on mobileOpenCV on mobile
OpenCV on mobile
 
Introduction of Swift from Machine Learning
Introduction of Swift from Machine LearningIntroduction of Swift from Machine Learning
Introduction of Swift from Machine Learning
 
Introduction of Swift from Game Development
Introduction of Swift from Game DevelopmentIntroduction of Swift from Game Development
Introduction of Swift from Game Development
 
How to measure UIView position on Native App
How to measure UIView position on Native AppHow to measure UIView position on Native App
How to measure UIView position on Native App
 

Dernier

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Dernier (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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

  • 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. 歯磨き.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. 歯磨き.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. 自己紹介 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. 自己紹介 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. 何を作っているか 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. 何を作っているか 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. 目次 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. 目次 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. 静的解析がなぜ必要か 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. 静的解析がなぜ必要か 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. 静的解析がなぜ必要か 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. 静的解析がなぜ必要か 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. はじめての静的解析 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. 今日作る静的解析のおしながき 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. はじめての静的解析 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. はじめての静的解析 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. はじめての静的解析の開発手順 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. はじめての静的解析 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. はじめての静的解析 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. はじめての静的解析 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. 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. 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. 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. 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. テストデータを作成 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. 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. 動作 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. プロジェクト独自定義 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. レイヤードアーキテクチャ 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. レイヤードアーキテクチャ 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. レイヤードアーキテクチャ 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. まとめ 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. まとめ 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の開発でも自分たちで作った静的解析の  ツールを活用していくぞい! ・簡単な静的解析ツールの作り方を説明しました。  これくらいでも実用的なものを作れそう。