Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kotlin Static Analysis - Kotlin Everywhere 2019
Search
Matheus Cassiano Candido
October 05, 2019
Programming
0
110
Kotlin Static Analysis - Kotlin Everywhere 2019
Slides for my Kotlin Everywhere talk.
Matheus Cassiano Candido
October 05, 2019
Tweet
Share
More Decks by Matheus Cassiano Candido
See All by Matheus Cassiano Candido
JUnit rules and test parameterization
mcassiano
0
120
unraveling custom drawing
mcassiano
0
84
The Basis of Android Threading: Loopers and Handlers
mcassiano
1
130
Hackeando sua próxima entrevista: dicas para conseguir seu próximo estágio ou emprego
mcassiano
1
93
text spans: what, why and how?
mcassiano
0
640
Navigation patterns on Android and something new
mcassiano
3
390
Como conseguir o estágio (ou emprego) dos sonhos
mcassiano
0
45
Databinding e padrão MVVM
mcassiano
1
25
Desenvolvimento móvel: práticas de sucesso
mcassiano
0
28
Other Decks in Programming
See All in Programming
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
1
710
A2A プロトコルを試してみる
azukiazusa1
2
1.2k
CursorはMCPを使った方が良いぞ
taigakono
1
190
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
660
Goで作る、開発・CI環境
sin392
0
150
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
870
XSLTで作るBrainfuck処理系
makki_d
0
210
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
600
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
310
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
1.3k
エラーって何種類あるの?
kajitack
5
320
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
110
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Become a Pro
speakerdeck
PRO
28
5.4k
The World Runs on Bad Software
bkeepers
PRO
69
11k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
Building an army of robots
kneath
306
45k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Navigating Team Friction
lara
187
15k
A better future with KSS
kneath
239
17k
Agile that works and the tools we love
rasmusluckow
329
21k
The Straight Up "How To Draw Better" Workshop
denniskardys
234
140k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
124
52k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Transcript
Mantendo código Kotlin seguro: de ponta a ponta Matheus C.
Candido Mobile Software Engineer @ Uber
Agenda 01 Análise estática 02 Ferramentas 03 Arquitetura 04 Customização
05 Automação
Análise estática Static program analysis is the analysis of computer
software that is performed without actually executing programs
Ktlint Simples, drop-in
Ktlint Simples, drop-in Zero configuração
Ktlint Simples, drop-in Zero configuração Code styling*
Ktlint Simples, drop-in Zero configuração Code styling* Formatador
Ktlint Simples, drop-in Zero configuração Code styling* Formatador Baseado no
Kotlin Style Guide, mas suporta Android Style Guide
Detekt Foco no detalhe
Detekt Foco no detalhe Totalmente configurável
Detekt Foco no detalhe Totalmente configurável Code styling
Detekt Foco no detalhe Totalmente configurável Code styling Performance
Detekt Foco no detalhe Totalmente configurável Code styling Performance Tratamento
de exceções
Android Lint Java, Kotlin e Resources
Android Lint Java, Kotlin e Resources Regras especiais para Android
Android Lint Java, Kotlin e Resources Regras especiais para Android
Super extensível
Android Lint Java, Kotlin e Resources Regras especiais para Android
Super extensível Performance
Android Lint Java, Kotlin e Resources Regras especiais para Android
Super extensível Performance Análise de recursos duplicados/não utilizados
Android Lint Java, Kotlin e Resources Regras especiais para Android
Super extensível Performance Análise de recursos duplicados/não utilizados Funciona para projetos não-Android
Warning vs. Errors
Baseline
Ignorando issues conhecidos @SuppressLint("NewApi") @Suppress("NewApi")
Arquitetura
Arquitetura
None
Arquitetura
Criando novas regras
Issue registry @AutoService(IssueRegistry::class) class Registry() :fIssueRegistry() {f override val issues:
List<Issue> = listOf(GetDrawableDetector.ISSUE) override val api: Int = CURRENT_API }f
Issue registry @AutoService(IssueRegistry::class) class Registry() :fIssueRegistry() {f override val issues:
List<Issue> = listOf(GetDrawableDetector.ISSUE) override val api: Int = CURRENT_API }f
Issue registry @AutoService(IssueRegistry::class) class Registry() :fIssueRegistry() {f override val issues:
List<Issue> = listOf(GetDrawableDetector.ISSUE) override val api: Int = CURRENT_API }f
Criando um detector /** *fDetector to check for usages of
`ResourcesCompat.getDrawable` or `ContextCompat.getDrawable`. */ class GetDrawableDetector :fDetector(), SourceCodeScanner {f companion object {f val ISSUE =fIssue.create(f id =fISSUE_ID, briefDescription =fBRIEF_DESCRIPTION, explanation =fLINT_ERROR_MESSAGE, category =fCategory.CORRECTNESS,
Descrição da Issue val ISSUE =fIssue.create(f id =fISSUE_ID, briefDescription =fBRIEF_DESCRIPTION,
explanation =fLINT_ERROR_MESSAGE, category =fCategory.CORRECTNESS, priority =f6, severity =fSeverity.ERROR, implementation =fcreate<GetDrawableDetector>()) }f override fun getApplicableMethodNames() = listOf("getDrawable") override fun visitMethodCall(f context:fJavaContext,
Descrição da Issue val ISSUE =fIssue.create(f id =fISSUE_ID, briefDescription =fBRIEF_DESCRIPTION,
explanation =fLINT_ERROR_MESSAGE, category =fCategory.CORRECTNESS, priority =f6, severity =fSeverity.ERROR, implementation =fcreate<GetDrawableDetector>()) }f override fun getApplicableMethodNames() = listOf("getDrawable") override fun visitMethodCall(f context:fJavaContext,
Descrição da Issue val ISSUE =fIssue.create(f id =fISSUE_ID, briefDescription =fBRIEF_DESCRIPTION,
explanation =fLINT_ERROR_MESSAGE, category =fCategory.CORRECTNESS, priority =f6, severity =fSeverity.ERROR, implementation =fcreate<GetDrawableDetector>()) }f override fun getApplicableMethodNames() = listOf("getDrawable") override fun visitMethodCall(f context:fJavaContext,
Descrição da Issue val ISSUE =fIssue.create(f id =fISSUE_ID, briefDescription =fBRIEF_DESCRIPTION,
explanation =fLINT_ERROR_MESSAGE, category =fCategory.CORRECTNESS, priority =f6, severity =fSeverity.ERROR, implementation =fcreate<GetDrawableDetector>()) }f override fun getApplicableMethodNames() =f listOf("getDrawable") override fun visitMethodCall(f context:fJavaContext,
Filtrando a entrada overrideffunfgetApplicableMethodNames() =f listOf("getDrawable")f override fun visitMethodCall(f context:fJavaContext,
node:fUCallExpression, method:fPsiMethod ){f iff(! getApplicableMethodNames().contains(node.methodName))freturn if (node.methodName == "getDrawable" && isBlacklisted(context.evaluator, node)) {f context.report(ISSUE, context.getLocation(node),
Detectando os problemas override fun visitMethodCall(f context:fJavaContext, node:fUCallExpression, method:fPsiMethod ){f
iff(! getApplicableMethodNames().contains(node.methodName))freturn if (node.methodName == "getDrawable" && isBlacklisted(context.evaluator, node)) {f context.report(ISSUE, context.getLocation(node), LINT_ERROR_MESSAGE) }f
Detectando os problemas iff(! getApplicableMethodNames().contains(node.methodName))freturn if (node.methodName == "getDrawable" &&
isBlacklisted(context.evaluator, node)) {f context.report(ISSUE, context.getLocation(node), LINT_ERROR_MESSAGE) }f }f private fun isBlacklisted():fBoolean {f return evaluator.isMemberInClass(node.resolve(), "androidx.core.content.ContextCompat") ||f
Detectando os problemas iff(! getApplicableMethodNames().contains(node.methodName))freturn if (node.methodName == "getDrawable" &&
isBlacklisted(context.evaluator, node)) {f context.report(ISSUE, context.getLocation(node), LINT_ERROR_MESSAGE) }f }f private fun isBlacklisted():fBoolean {f return evaluator.isMemberInClass(node.resolve(), "androidx.core.content.ContextCompat") ||f
Detectando os problemas context.report(ISSUE, context.getLocation(node), LINT_ERROR_MESSAGE) }f }f private fun
isBlacklisted():fBoolean {f return evaluator.isMemberInClass(node.resolve(),f "androidx.core.content.ContextCompat") ||f evaluator.isMemberInClass(node.resolve(), "androidx.core.content.res.ResourcesCompat")f }f }f
Usando a nova regra // no build.gradle dos outros projetos
dependencies {f lintChecks project(":meu_detector") }f
Usando a nova regra // no build.gradle dos outros projetos
dependencies {f lintChecks project(":meu_detector") }f
Relatórios
Relatórios
Relatórios
Evolução do código
None
Automação
Automação https://bit.cassiano.me/sa-automation
Automação https://bit.cassiano.me/sa-automation
Automação https://bit.cassiano.me/sa-comment-machine
Automação https://bit.cassiano.me/sa-git-hooks
Automação https://bit.cassiano.me/sa-git-hooks
Resumo Combine as ferramentas e aproveite o melhor de cada
uma
Resumo Combine as ferramentas e aproveite o melhor de cada
uma Aplique as regras que façam sentido para seu contexto
Resumo Combine as ferramentas e aproveite o melhor de cada
uma Aplique as regras que façam sentido para seu contexto Automatize a formatação dos arquivos e partes do code review
https://bit.cassiano.me/sa-kotlin-conf-17-talk
https://bit.cassiano.me/sa-kotlin-conf-18-talk
…perguntas?