Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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.5k
Other Decks in Technology
See All in Technology
TypeScript100%で作るMovable Typeプラグイン
usualoma
2
220
Microsoft 365と開発者ツールの素敵な関係
kkamegawa
0
470
Android 15 でウィジェットピッカーのプレビュー画像をGlanceで魅せたい/nikkei-tech-talk-27-1
nikkei_engineer_recruiting
0
110
データカタログを自作したけど 運用しなかった話@Findy Lunch LT「データカタログ 事例から学ぶメタデータ管理の実態」
ryo_suzuki
2
360
飲食店データの分析事例とそれを支えるデータ基盤
kimujun
0
260
クラウドネイティブなNewSQLで実現するミッションクリティカルなアプリケーションの運用
yuyu_hf
PRO
1
140
PFN Company Deck
pfn
PRO
1
110
セキュリティ運用って包括的にできていますか?SaaSを使って次のステップへ / Comprehensive Cyber Security Operations for Cloud Services Using SaaS
sakaitakeshi
0
260
今はまだ小さい東京ガス内製開発チームが、これからもKubernetesと共に歩み続けるために
yussugi
3
400
Continuous Integration! Raising the Bar
tdpauw
1
120
LY Accessibility Guidelines @fukuoka_a11yconf_前夜祭
lycorptech_jp
PRO
1
110
【CNDW2024】SIerで200人クラウドネイティブのファンを増やした話
yuta1979
0
160
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
181
21k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
What's new in Ruby 2.0
geeforr
343
31k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Building Adaptive Systems
keathley
38
2.3k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
A better future with KSS
kneath
238
17k
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