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
静的解析ツール detekt で任意の条件で警告させる
Search
Shunsuke Maeda
August 24, 2019
Technology
1
1.3k
静的解析ツール detekt で任意の条件で警告させる
Kotlin Fest 2019 の LT 発表資料です。
Shunsuke Maeda
August 24, 2019
Tweet
Share
More Decks by Shunsuke Maeda
See All by Shunsuke Maeda
GolangでDockerベースのCIを作る
duck8823
3
3.4k
GitHub と連携する CI を作る
duck8823
3
2.4k
Other Decks in Technology
See All in Technology
VPC間の接続方法を整理してみた #自治体クラウド勉強会
non97
1
850
オーティファイ会社紹介資料 / Autify Company Deck
autifyhq
9
120k
APIテスト自動化の勘所
yokawasa
7
4.2k
小規模に始めるデータメッシュとデータガバナンスの実践
kimujun
3
590
よくわからんサービスについての問い合わせが来たときの強い味方 Amazon Q について
kazzpapa3
0
220
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
630
生成AIと知識グラフの相互利用に基づく文書解析
koujikozaki
1
140
Automated Promptingを目指すその前に / Before we can aim for Automated Prompting
rkaga
0
110
独自ツール開発でスタジオ撮影をDX!「VLS(Virtual LED Studio)」 / dx-studio-vls
cyberagentdevelopers
PRO
1
180
ユーザーの購買行動モデリングとその分析 / dsc-purchase-analysis
cyberagentdevelopers
PRO
2
100
いまならこう作りたい AWSコンテナ[本格]入門ハンズオン 〜2024年版 ハンズオンの構想〜
horsewin
9
2.1k
現地でMeet Upをやる場合の注意点〜反省点を添えて〜
shotashiratori
0
530
Featured
See All Featured
Building Applications with DynamoDB
mza
90
6.1k
Automating Front-end Workflow
addyosmani
1365
200k
The Language of Interfaces
destraynor
154
24k
Bash Introduction
62gerente
608
210k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
A Philosophy of Restraint
colly
203
16k
How to Think Like a Performance Engineer
csswizardry
19
1.1k
A better future with KSS
kneath
238
17k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
Code Review Best Practice
trishagee
64
17k
Why Our Code Smells
bkeepers
PRO
334
57k
Transcript
੩తղੳπʔϧ detekt Ͱҙͷ݅Ͱܯࠂͤ͞Δɹ Kotlin Fest 2019 2019.08.24 [SAT] Shunsuke Maeda
(@duck8823)
ࣗݾհ ✓ Shunsuke Maeda ✓ @duck8823 ✓ ॴଐ ✓ גࣜձࣾΤεɾΤϜɾΤε
✓ EarthCampusגࣜձࣾ ✓ ීஈ ✓ Kotlin Ͱ։ൃʢαʔόʔαΠυʣ 2/21
੩తղੳ ϓϩάϥϜΛ࣮ߦͤͣʹιʔείʔυΛղੳ ✓ϓϩδΣΫτʹ͓͚ΔίʔσΟϯάϧʔϧ ✓ Πϯσϯτ ✓ ϝιου / Ϋϥεͷ͞ ✓
ෳࡶ => ✓ίʔυͷ࣭Λอͭ ✓ίʔυϨϏϡʔͰϩδοΫʹྗͰ͖Δ 3/21
detekt arturbosch/detekt ✓Kotlinͷ੩తղੳπʔϧ ✓ϓϥΨϒϧͳઃܭ ✓࠷ۙ(2019-08-13) ver. 1.0.0 ͕ϦϦʔε͞Εͨ 4/21
੩తղੳ ͱ CI CI (Continuous Integration) ͳͲͰৗʹಈ͔͢͜ͱ͕େࣄ ϧʔϧҧ͕͋ͬͨ߹ʹܯࠂ(= CI ͷδϣϒࣦഊ)
ಈతʹ CIͷδϣϒ ΛϋϯυϦϯά͍ͨ͠ ྫ. - ίʔυͷنʹΑͬͯܯࠂ͢ΔᮢΛม͍͑ͨ - PRͷ߹͕ࠩ͋ͬͨϑΝΠϧͷΈରʹ͍ͨ͠ 5/21
੩తղੳπʔϧ detekt Ͱҙͷ݅Ͱܯࠂͤ͞Δɹ 6/21
CI ͱ ऴྃίʔυ CI Ͱδϣϒ͕ࣦഊ͢Δ݅ = ίϚϯυͷऴྃίʔυ͕ 0 Ͱͳ͍ =>
ऴྃίʔυΛϋϯυϦϯάͰ͖Εҙͷ݅Ͱδϣϒࣦഊ 7/21
detekt ͱ ऴྃίʔυ detekt ίϚϯυͷ߹ fun main(args: Array<String>) { try
{ buildRunner(args).execute() } catch (e: BuildFailure) { e.printStackTrace() exitProcess(2) } catch (e: Exception) { e.printStackTrace() exitProcess(1) } exitProcess(0) } 8/21
BuildFailure Ͳ͔͜Β throw ͞Ε͍ͯΔʁ 9/21
ઃఆϑΝΠϧʹώϯτ͕͋Δ detekt --generate-config # ઃఆϑΝΠϧͷੜίϚϯυ ੜ͞ΕͨઃఆϑΝΠϧ console-reports: active: true exclude:
# - 'ProjectStatisticsReport' # - 'ComplexityReport' # - 'NotificationReport' # - 'FindingsReport' # - 'BuildFailureReport' 10/21
BuildFailureReport 11/21
BuildFailureReport ✓ຊମʹΈࠐ·Ε͍ͯΔ Custom Reports ϓϥάΠϯͷҰछ ✓exclude ͢Δͱϧʔϧҧ͕͋ͬͯऴྃίʔυ 0 ʹͳΔ (
1.0.0 ) console-reports: active: true exclude: # - 'ProjectStatisticsReport' # - 'ComplexityReport' # - 'NotificationReport' # - 'FindingsReport' - 'BuildFailureReport' 12/21
detekt ͷϓϥάΠϯ ✓Custom RuleSets: ಠࣗͷϧʔϧͷՃ ✓Custom Processors: ੩తղੳ࣮ߦ࣌ʢલޙʣͷॲཧ ✓ interface
FileProcessListener ✓Custom Reports: ੩తղੳͷ݁Ռͷग़ྗ ✓ abstract class ConsoleReport <= BuildFailureReport ✓ abstract class OutputReport see also https://arturbosch.github.io/detekt/extensions.html 13/21
BuildFailureReport class BuildFailureReport : ConsoleReport() { ... override fun render(detektion:
Detektion): String? { ... maxIssues.reached(amount) -> { val message = "Build failed with $amount..." println(message.red()) throw BuildFailure(message) } ,,, } } ※ ver. 1.0.0 14/21
ຊମΈࠐΈϓϥάΠϯͱಉ͡Α͏ʹ࡞Ε͍͍ 15/21
ҙͷ݅Ͱ throw ͢Δ Custom Report import io.gitlab.arturbosch.detekt.api.ConsoleReport import io.gitlab.arturbosch.detekt.api.Detektion import
io.gitlab.arturbosch.detekt.cli.console.BuildFailure class MyCustomReport : ConsoleReport() { override val priority: Int = Int.MIN_VALUE ... override fun render(detektion: Detektion): String? { ... # ͜͜Ͱҙͷ݅Ͱ throw BuildFailure("...") } } ✓priority: CustomReportΛ࣮ߦ͢Δ༏ઌ 16/21
؆୯...? 17/21
BuildFailureReport ʹมߋ... arturbosch/detekt#1818ʢ6લʣ 18/21
PR #1818 ޙ ( 1.0.1 ʹೖΔ༧ఆ ) ✓BuildFailureReport Ͱ throw
͠ͳ͍ ✓Runner Ͱ throw ͢Δ => BuildFailureReport Λ exclude ͯ͠ऴྃεςʔλεมΘΒͳ͍ ※ BuildFailureReport Ͱ throw ͍ͯ͠Δͷઃܭ্ͷόά => 1.0.1Ͱमਖ਼ 19/21
build failure ͷແޮԽ ઃఆϑΝΠϧͰ build: maxIssues: -1 ແޮԽ্ͨ͠ CustomReport ͕ྫ֎Λ͛Δ͜ͱͰऴྃίʔυมߋՄ
1.0.0 Ͱ༗ޮ 20/21
·ͱΊ ੩తղੳπʔϧ detekt Ͱҙͷ݅Ͱܯࠂͤ͞Δ ✓<= 1.0.0 ✓ BuildFailureReport Λແޮ ✓
build -> maxIssues: -1 ✓ CustomReport Ͱ throw BuildFailure ✓>= 1.0.1 ✓ build -> maxIssues: -1 ✓ CustomReport Ͱ throw BuildFailure 21/21