Share
Embed
scalafmtについて調べてみた
norinori3
October 24, 2018
Transcript
16 slides
-
ൃද༰ީิͨͪ • ಈ͔͠ͳ͕ΒLagom FrameworkͷงғؾΛ௫Ή • https://github.com/lagom/online-auction-scala • alpakka elasticsearchίωΫλΛͬͯΈͯงғؾΛ௫Ή •
https://developer.lightbend.com/docs/alpakka/ current/elasticsearch.html • ScalafmtΑ͘Θ͔ͬͯͳ͍ͷͰɺษڧͯ͠ΈΔ -
Scalafmt ઃఆ ͳΜͱͳ͘ Θ͔Δͷ ͋Δ͚Ͳɺɺ ͳΜͧɾɾ?? ↓↓↓ ͜ΕΒʹ͍ͭͯ ௐͨ͜ͱ" Λઆ໌͍͖ͯ͠·͢ɻ
# See http://scalameta.org/scalafmt/#Configuration style = defaultWithAlign maxColumn = 130 includeCurlyBraceInSelectChains = false newlines.penalizeSingleSelectMultiArgList = false align = most align.tokens = [ {code = "<-"}, {code = "="}, {code = ":"}, {code = "->"}, {code = "=>"} ] align.openParenCallSite = false rewrite.rules = [ SortImports ] project.git = true project.excludeFilters = ["target/"] 1 2 3 4 5 6 7 -
ͪͳΈʹɺɺɺ • addSbtPlugin("com.geirsson" % "sbt-scalafmt" % “1.5.1") ͬͯ· ͢ɻ •
ެࣜΛݟΔͱɺʮ͍͔ͭ͘ʯͷઃఆํ๏ͱޮՌॻ͍ͯ·͢ɻ • http://scalameta.org/scalafmt/#Configuration • ͨͩɺͦͷઆ໌ͷதʹɺҎԼͷΑ͏ʹ͋Δɻ • To find all available configuration options, it's best to browse the source code of Scalafmt. A good place to start is ScalafmtConfig. Observe that this listing below is the top- level, there are more configuration options if you visited nested fields like spaces and newlines. • ιʔείʔυݟΖɻ • IntelliJͷPluginΛೖΕΔ͜ͱͰɺCtrl+Shift+l ͰscalafmtͰίʔυϑΥʔ Ϛοτ͔͚Ε·͢ɻ • build.sbtʹ scalafmtOnCompile := true Λॻ͘͜ͱͰɺίϯύΠϧ࣌ʹࣗ ಈతʹίʔυϑΥʔϚοτ͔͚Ε·͢ɻ -
“True”ͷ߹: List(1) .map { x => x + 2 }
.filter(_ > 2) includeCurlyBraceInSelectChains “False”ͷ߹: List(1).map { x => x + 2 }.filter(_ > 2) style mapͳͲʹ͏தׅހϒϩοΫͷ ѻ͍ํΛܾΊΔɻ 1 2 ઃఆ: default defaultWithAlign Scala.js IntelliJ ͍͍ײ͡ͷઃఆΛͯ͘͠ΕΔͷ? ެࣜαΠτʹ͕ͬͭΓͨ͠આ໌ͳ͠ɻίʔυΛݟΔ͔͠ͳ͍ɾɾɻ -
org.scalafmt.config.Newlines.scalaʹ͋Δઆ໌ * @param penalizeSingleSelectMultiArgList * If true, adds a penalty
to newlines before a dot starting a select * chain of length one and argument list. The penalty matches the number * of arguments to the select chain application. * {{{ * // If true, favor * logger.elem(a, * b, * c) * // instead of * logger * .elem(a, b, c) * * // penalty is proportional to argument count, example: * logger.elem(a, b, c) // penalty 2 * logger.elem(a, b, c, d) // penalty 3, etc. * }}} * * If false, matches pre-v0.5 behavior. Note. this option may be * removed in a future release. 3 ެࣜαΠτʹ͕ͬͭΓͨ͠આ໌ͳ͠ɻ trueͷ߹ɺҾ͕ෳ͋Δͱ͖ʹվߦͯ͠ྻͤ͞Δ penalizeSingleSelectMultiArgList -
align “none”ͷ߹: x match { case 2 => 22 case
22 => 222 } “some”ͷ߹(default): x match { case 2 => 22 case 22 => 222 } val x = 2 val xx = 22 case object B extends A case object BB extends A “more”ͷ߹: x match { case 1 => 1 -> 2 case 11 => 11 -> 22 } val x = 2 val xx = 22 case object B extends A case object BB extends A for { x <- List(1) yyy <- List(2) zzz <- new Integer { def value = 3 } } yield x * yyy “most”ͷ߹: x match { case 1 => 1 -> 2 case 11 => 11 -> 22 } val x = 2 val xx = 22 case object B extends A case object BB extends A for { x <- List(1) yyy <- List(2) zzz <- new Integer { def value = 3 } } yield x * yyy ΞϥΠϝϯτ(ྻ)ܥʹ͍ܾͭͯΊΔɻ 4 -
x match { case 1 => 1 -> 2 case
11 => 11 -> 22 } align.tokens = [ {code = "=>", owner = “Case"} ] ͱࢦఆͨ͠߹… align.openParenCallSite trueͷ߹: function(arg1, arg2, arg3) falseͷ߹: function( arg1, arg2, arg3 ) align.tokens ྻͤ͞Δه߸ΛܾΊΔɻ ownerΛࢦఆ͠ͳ͚ΕશͯͷOwnerʹద༻͞ΕΔɻ খׅހͷཁૉͷ ྻΛܾΊΔɻ 5 6 7 rewrite.rules ࢦఆͨ͠ϧʔϧͰஔ͖͑ͯ͘͠ΕΔ SortImports ࢦఆͨ͠߹: import foo.{bar, sand, Random, Zilch} ࢦఆ͠ͳ͍߹: import foo.{Zilch, bar, Random, sand} -
# See http://scalameta.org/scalafmt/#Configuration style = defaultWithAlign maxColumn = 130 includeCurlyBraceInSelectChains
= false newlines.penalizeSingleSelectMultiArgList = false align = most align.tokens = [ {code = "<-"}, {code = "="}, {code = ":"}, {code = "->"}, {code = "=>"} ] align.openParenCallSite = false rewrite.rules = [ SortImports ] project.git = true project.excludeFilters = ["target/"] 4 5 →githubͷissueʹͷͬͯΔ͔ɻɻ alignͲ͏ઃఆ͢Ε͍͍ͷ͔..·ͩௐͯ·ͤΜɻɻ