Slide 1

Slide 1 text

੩తղੳπʔϧ detekt Ͱ೚ҙͷ৚݅Ͱܯࠂͤ͞Δɹ Kotlin Fest 2019 2019.08.24 [SAT] Shunsuke Maeda (@duck8823)

Slide 2

Slide 2 text

ࣗݾ঺հ ✓ Shunsuke Maeda ✓ @duck8823 ✓ ॴଐ ✓ גࣜձࣾΤεɾΤϜɾΤε ✓ EarthCampusגࣜձࣾ ✓ ීஈ͸ ✓ Kotlin Ͱ։ൃʢαʔόʔαΠυʣ 2/21

Slide 3

Slide 3 text

੩తղੳ ϓϩάϥϜΛ࣮ߦͤͣʹιʔείʔυΛղੳ ✓ϓϩδΣΫτʹ͓͚ΔίʔσΟϯάϧʔϧ ✓ Πϯσϯτ ✓ ϝιου / Ϋϥεͷ௕͞ ✓ ෳࡶ౓ => ✓ίʔυͷ඼࣭Λอͭ ✓ίʔυϨϏϡʔͰϩδοΫʹ஫ྗͰ͖Δ 3/21

Slide 4

Slide 4 text

detekt arturbosch/detekt ✓Kotlin੡ͷ੩తղੳπʔϧ ✓ϓϥΨϒϧͳઃܭ ✓࠷ۙ(2019-08-13) ver. 1.0.0 ͕ϦϦʔε͞Εͨ 4/21

Slide 5

Slide 5 text

੩తղੳ ͱ CI CI (Continuous Integration) ͳͲͰৗʹಈ͔͢͜ͱ͕େࣄ ϧʔϧҧ൓͕͋ͬͨ৔߹ʹܯࠂ(= CI ͷδϣϒࣦഊ) ಈతʹ CIͷδϣϒ ΛϋϯυϦϯά͍ͨ͠ ྫ. - ίʔυͷن໛ʹΑͬͯܯࠂ͢Δᮢ஋Λม͍͑ͨ - PRͷ৔߹͸ࠩ෼͕͋ͬͨϑΝΠϧͷΈର৅ʹ͍ͨ͠ 5/21

Slide 6

Slide 6 text

੩తղੳπʔϧ detekt Ͱ೚ҙͷ৚݅Ͱܯࠂͤ͞Δɹ 6/21

Slide 7

Slide 7 text

CI ͱ ऴྃίʔυ CI Ͱδϣϒ͕ࣦഊ͢Δ৚݅ = ίϚϯυͷऴྃίʔυ͕ 0 Ͱͳ͍ => ऴྃίʔυΛϋϯυϦϯάͰ͖Ε͹೚ҙͷ৚݅Ͱδϣϒࣦഊ 7/21

Slide 8

Slide 8 text

detekt ͱ ऴྃίʔυ detekt ίϚϯυͷ৔߹ fun main(args: Array) { try { buildRunner(args).execute() } catch (e: BuildFailure) { e.printStackTrace() exitProcess(2) } catch (e: Exception) { e.printStackTrace() exitProcess(1) } exitProcess(0) } 8/21

Slide 9

Slide 9 text

BuildFailure ͸Ͳ͔͜Β throw ͞Ε͍ͯΔʁ 9/21

Slide 10

Slide 10 text

ઃఆϑΝΠϧʹώϯτ͕͋Δ detekt --generate-config # ઃఆϑΝΠϧͷੜ੒ίϚϯυ ੜ੒͞ΕͨઃఆϑΝΠϧ console-reports: active: true exclude: # - 'ProjectStatisticsReport' # - 'ComplexityReport' # - 'NotificationReport' # - 'FindingsReport' # - 'BuildFailureReport' 10/21

Slide 11

Slide 11 text

BuildFailureReport 11/21

Slide 12

Slide 12 text

BuildFailureReport ✓ຊମʹ૊Έࠐ·Ε͍ͯΔ Custom Reports ϓϥάΠϯͷҰछ ✓exclude ͢Δͱϧʔϧҧ൓͕͋ͬͯ΋ऴྃίʔυ͸ 0 ʹͳΔ ( 1.0.0 ) console-reports: active: true exclude: # - 'ProjectStatisticsReport' # - 'ComplexityReport' # - 'NotificationReport' # - 'FindingsReport' - 'BuildFailureReport' 12/21

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

ຊମ૊ΈࠐΈϓϥάΠϯͱಉ͡Α͏ʹ࡞Ε͹͍͍ 15/21

Slide 16

Slide 16 text

೚ҙͷ৚݅Ͱ 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

Slide 17

Slide 17 text

؆୯...? 17/21

Slide 18

Slide 18 text

BuildFailureReport ʹมߋ... arturbosch/detekt#1818ʢ6೔લʣ 18/21

Slide 19

Slide 19 text

PR #1818 ޙ ( 1.0.1 ʹೖΔ༧ఆ ) ✓BuildFailureReport Ͱ͸ throw ͠ͳ͍ ✓Runner Ͱ throw ͢Δ => BuildFailureReport Λ exclude ͯ͠΋ऴྃεςʔλε͸มΘΒͳ͍ ※ BuildFailureReport Ͱ throw ͍ͯ͠Δͷ͸ઃܭ্ͷόά => 1.0.1Ͱमਖ਼ 19/21

Slide 20

Slide 20 text

build failure ͷແޮԽ ઃఆϑΝΠϧͰ build: maxIssues: -1 ແޮԽ্ͨ͠ CustomReport ͕ྫ֎Λ౤͛Δ͜ͱͰऴྃίʔυมߋՄ 1.0.0 Ͱ΋༗ޮ 20/21

Slide 21

Slide 21 text

·ͱΊ ੩తղੳπʔϧ detekt Ͱ೚ҙͷ৚݅Ͱܯࠂͤ͞Δ ✓<= 1.0.0 ✓ BuildFailureReport Λແޮ ✓ build -> maxIssues: -1 ✓ CustomReport Ͱ throw BuildFailure ✓>= 1.0.1 ✓ build -> maxIssues: -1 ✓ CustomReport Ͱ throw BuildFailure 21/21