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.5k
Other Decks in Technology
See All in Technology
【若手エンジニア応援LT会】ソフトウェアを学んできた私がインフラエンジニアを目指した理由
kazushi_ohata
0
150
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
Terraform Stacks入門 #HashiTalks
msato
0
350
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
1
2.3k
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
500
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
980
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
120
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
12k
Platform Engineering for Software Developers and Architects
syntasso
1
520
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Bash Introduction
62gerente
608
210k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Happy Clients
brianwarren
98
6.7k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Music & Morning Musume
bryan
46
6.2k
Git: the NoSQL Database
bkeepers
PRO
427
64k
How GitHub (no longer) Works
holman
310
140k
Into the Great Unknown - MozCon
thekraken
32
1.5k
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