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
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
240
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
130
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
1k
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.6k
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
1
370
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
180
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
210
Featured
See All Featured
Music & Morning Musume
bryan
46
6.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Language of Interfaces
destraynor
154
24k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Fireside Chat
paigeccino
34
3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
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