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.4k
静的解析ツール 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.5k
GitHub と連携する CI を作る
duck8823
3
2.5k
Other Decks in Technology
See All in Technology
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
170
Storage Browser for Amazon S3
miu_crescent
1
240
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
180
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
1
360
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
200
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
200
Wantedly での Datadog 活用事例
bgpat
1
520
第3回Snowflake女子会_LT登壇資料(合成データ)_Taro_CCCMK
tarotaro0129
0
200
なぜCodeceptJSを選んだか
goataka
0
160
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
380
.NET 9 のパフォーマンス改善
nenonaninu
0
1k
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Automating Front-end Workflow
addyosmani
1366
200k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Become a Pro
speakerdeck
PRO
26
5k
Facilitating Awesome Meetings
lara
50
6.1k
Writing Fast Ruby
sferik
628
61k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Thoughts on Productivity
jonyablonski
67
4.4k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
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