Skip to content

Commit

Permalink
Build: Use shared scalafmt config; add intellij excluded directories
Browse files Browse the repository at this point in the history
raquo committed Nov 23, 2024
1 parent 5072c54 commit b270524
Showing 10 changed files with 64 additions and 176 deletions.
24 changes: 17 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
target
.idea
.bsp
.vscode
*.code-workspace
.bloop
.metals
project/metals.sbt
project/project

.DS_Store

target

.metals
.bloop
.bsp

project/metals.sbt
project/.bloop

yarn.lock
!website/yarn.lock

.downloads

website/node_modules
website/build
website/i18n/*

/.bsp
websiteJS/package-lock.json
170 changes: 2 additions & 168 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,175 +1,9 @@
version = "3.8.4-RC1"
include ".downloads/.scalafmt.shared.conf"

runner.dialect = "scala213"

# !!! TODO !!! Update styles in the generator to match scalafmt config
# - Maybe make a separate config for these files, that has two lines before method names, see https://scalameta.org/scalafmt/docs/configuration.html#fileoverride
# - Does this exclusion actually work? IntelliJ seems to ignore it
project.excludePaths = [
"glob:**/project/VersionHelper.scala",
"glob:**/src/*/scala-3/**"
"glob:**/src/*/scala/com/raquo/airstream/combine/generated/**"
]

maxColumn = 1000

indent.main = 2
indent.callSite = 2
indent.binPackCallSite = 2
indent.ctrlSite = 2
indent.defnSite = 2
indent.binPackDefnSite = 2
indent.ctorSite = 2
indent.matchSite = 2
indent.caseSite = 2
indent.extendSite = 0
indent.withSiteRelativeToExtends = 0
indent.commaSiteRelativeToExtends = 2 # 0 is not allowed
indent.extraBeforeOpenParenDefnSite = 0
indent.relativeToLhsLastLine = [match, infix]
indent.fewerBraces = never
indent.afterInfixSite = 2 # not sure what this is https://scalameta.org/scalafmt/docs/configuration.html#indentafterinfixsite

# Indenting of nested calls:
# !!! #TODO !!!: https://scalameta.org/scalafmt/docs/configuration.html#indent-for-binpackcallsite
# !!! #TODO !!!: https://scalameta.org/scalafmt/docs/configuration.html#indentoperator

align.preset = none

# TODO: alignment can be more detailed but requires knowing Scala types
# https://scalameta.org/scalafmt/docs/configuration.html#aligntokens

align.arrowEnumeratorGenerator = false
align.closeParenSite = false
align.openParenCallSite = false
align.openBracketCallSite = false
align.openParenCtrlSite = false
align.openParenDefnSite = false
align.openBracketDefnSite = false
align.openParenCallSite = false
align.beforeOpenParenCallSite = false # ??? https://scalameta.org/scalafmt/docs/configuration.html#alignbeforeopenparenxxxsite
align.beforeOpenParenDefnSite = false # ??? https://scalameta.org/scalafmt/docs/configuration.html#alignbeforeopenparenxxxsite
align.stripMargin = true
align.multiline = false
align.allowOverflow = true # Not sure, it's unused since alignment is disabled https://scalameta.org/scalafmt/docs/configuration.html#alignallowoverflow
align.inInterpolation = false
align.delayUntilSpace = true

# https://scalameta.org/scalafmt/docs/configuration.html#binpacking
binPack.callSite = onelinesjs
binPack.parentConstructors = keep

newlines.source = keep
# TODO: ??? https://scalameta.org/scalafmt/docs/configuration.html#newlinestoplevelstatementblanklines
newlines.topLevelStatementBlankLines = []
newlines.topLevelBodyIfMinStatements = []
newlines.beforeTemplateBodyIfBreakInParentCtors = false # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#newlinesbeforetemplatebodyifbreakinparentctors
newlines.beforeMultiline = keep # !!! TODO not sure, maybe `unfold` https://scalameta.org/scalafmt/docs/configuration.html#newlinesbeforemultiline
newlines.forceBeforeMultilineAssign = never
newlines.forceBeforeAssign = never
newlines.beforeTypeBounds = keep
newlines.alwaysBeforeElseAfterCurlyIf = false
newlines.beforeCurlyLambdaParams = never
newlines.afterCurlyLambdaParams = keep
newlines.configStyleCallSite.prefer = false # Lets us keep all method arguments on the same line, without forcing it
# newlines.implicitParamListModifierPrefer = after # TODO I want this to be before, but scalafmt does not work well with it. Also I can't set this to any value and set binpacking - not supported.
# newlines.implicitParamListModifierForce = [after] # !!! TODO not sure
newlines.afterInfix = keep
newlines.afterInfixBreakOnNested = false # ??? https://scalameta.org/scalafmt/docs/configuration.html#newlinesafterinfixbreakonnested
newlines.avoidForSimpleOverflow = [tooLong, punct, slc]
newlines.avoidInResultType = true
newlines.avoidAfterYield = false
newlines.sometimesBeforeColonInMethodReturnType = false
# newlines.beforeOpenParenDefnSite = keep # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#newlinesbeforeopenparenxxxsite
# newlines.beforeOpenParenCallSite = keep # TODO only supported for Scala 3. Also, not sure... https://scalameta.org/scalafmt/docs/configuration.html#newlinesbeforeopenparenxxxsite
newlines.selectChains = keep
newlines.inInterpolation = avoid # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#newlinesininterpolation
newlines.ignoreInSyntax = true # TODO very not sure https://scalameta.org/scalafmt/docs/configuration.html#newlinesignoreinsyntax

optIn.annotationNewlines = true # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#optinannotationnewlines

danglingParentheses.defnSite = true
danglingParentheses.callSite = true
danglingParentheses.bracketDefnSite = true
danglingParentheses.bracketCallSite = true
danglingParentheses.ctrlSite = true
danglingParentheses.tupleSite = true
danglingParentheses.exclude = [] # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#danglingparenthesesexclude
# !!! TODO not sure how !!! newlines.configStyleXxxSite.prefer https://scalameta.org/scalafmt/docs/configuration.html#newlinesconfigstylexxxsiteprefer

# prefercurlyfors, redundantparens, redundantbraces, sortmodifiers, sortimports, expandimportselectors, imports, avoidinfix, asciisortimports

rewrite.rules = [SortModifiers, PreferCurlyFors, Imports]
# rewrite.sortModifiers.preset = styleGuide # TODO consider removing (changes position of `final` keyword) https://scalameta.org/scalafmt/docs/configuration.html#sortmodifiers
rewrite.sortModifiers.order = [ # TODO maybe a custom order...
"final", "override",
"implicit",
"sealed", "abstract",
"private", "protected",
"lazy"
]
rewrite.preferCurlyFors.removeTrailingSemicolonsOnly = true # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#prefercurlyfors
rewrite.imports.expand = false
rewrite.imports.sort = scalastyle # TODO not sure - change this later https://scalameta.org/scalafmt/docs/configuration.html#imports-sort--ascii
rewrite.imports.groups = [ # TODO not sure
[".*"], # Other imports first
["java\\..*", "scala\\..*", "scala.scalajs\\..*"]
]
rewrite.imports.contiguousGroups = only # TODO not sure
rewrite.trailingCommas.style = keep # TODO consider changing to `never`
rewrite.trailingCommas.allowFolding = true # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#rewritetrailingcommasallowfolding

# TODO Scala 3 rewrites? https://scalameta.org/scalafmt/docs/configuration.html#scala3-rewrites

# !!!! TODO not sure about any of this !!! Maybe disable completely?
# https://scalameta.org/scalafmt/docs/configuration.html#vertical-multiline
verticalMultiline.atDefnSite = true
verticalMultiline.arityThreshold = 10
verticalMultiline.newlineAfterOpenParen = true

comments.wrap = no
comments.wrapStandaloneSlcAsSlc = true // # TODO not sure because unused
comments.wrapSingleLineMlcAsSlc = false

docstrings.style = keep # !!! TODO not sure, can also be Space, SpaceAsterisk, or AsteriskSpace https://scalameta.org/scalafmt/docs/configuration.html#docstringsstyle
docstrings.removeEmpty = true
docstrings.oneline = keep # TODO not sure. Note: Ignored if docstrings.style = keep https://scalameta.org/scalafmt/docs/configuration.html#docstringsoneline
docstrings.wrap = keep
docstrings.wrapMaxColumn = 100 # TODO change if want it to be different from maxColumn
docstrings.blankFirstLine = keep # !!! TODO not sure, try `fold`
docstrings.forceBlankLineBefore = false # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#docstringsforceblanklinebefore

spaces.beforeContextBoundColon = never # !!! TODO not sure, Always or IfMultipleBounds may be better style https://scalameta.org/scalafmt/docs/configuration.html#spacesbeforecontextboundcolon
spaces.inImportCurlyBraces = false
spaces.inInterpolatedStringCurlyBraces = false
spaces.inParentheses = false
spaces.neverAroundInfixTypes = []
spaces.aroundSymbolicInfixOperators.include = [".*"]
spaces.aroundSymbolicInfixOperators.exclude = []
spaces.afterKeywordBeforeParen = true
spaces.inByNameTypes = true
spaces.afterSymbolicDefs = false
spaces.beforeApplyArgInParens = AfterSymbolic # TODO not sure https://scalameta.org/scalafmt/docs/configuration.html#spacesbeforexxxarginparens
spaces.beforeInfixArgInParens = always
spaces.afterColonInMatchPattern = always

literals.long = Upper
literals.float = Lower
literals.double = Lower
literals.hexPrefix = Lower
literals.hexDigits = Lower # Not sure, unused https://scalameta.org/scalafmt/docs/configuration.html#literalshexdigits
literals.scientific = Lower

xmlLiterals.assumeFormatted = false

# !!! TODO Classic select chains !!! https://scalameta.org/scalafmt/docs/configuration.html#classic-select-chains
# - I don't think this applies to us, it's only for when newlines.source = classic, but we have `keep`

# lineEndings = unix # TODO: Is there a difference between omitting it and setting `unix`? https://scalameta.org/scalafmt/docs/configuration.html#lineendings

rewriteTokens = {
"⇒": "=>"
"→": "->"
"←": "<-"
}

importSelectors = binPack # TODO Not sure, is there a `keep` option? https://scalameta.org/scalafmt/docs/configuration.html#importselectors
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ I created Airstream because I found existing solutions were not suitable for bui
## Table of Contents

* [Community](#community)
* [Contributing](#contributing)
* [Documentation](#documentation)
* [EventStream](#eventstream)
* [Laziness](#laziness)
@@ -108,6 +109,10 @@ I created Airstream because I found existing solutions were not suitable for bui
* [Github issues](https://github.com/raquo/Airstream/issues) for bugs, feature requests


## Contributing

Please run `sbt +test` and `sbt scalafmtAll` locally before submitting the PR.


## Documentation

27 changes: 27 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.raquo.buildkit.SourceDownloader
import VersionHelper.{versionFmt, fallbackVersion}

// Lets me depend on Maven Central artifacts immediately without waiting
@@ -7,6 +8,26 @@ enablePlugins(ScalaJSPlugin)

enablePlugins(ScalaJSBundlerPlugin)

lazy val preload = taskKey[Unit]("runs Laminar-specific pre-load tasks")

preload := {
val projectDir = (ThisBuild / baseDirectory).value
// TODO Move code generators here as well?

SourceDownloader.downloadVersionedFile(
name = "scalafmt-shared-conf",
version = "v0.1.0",
urlPattern = version => s"https://raw.githubusercontent.com/raquo/scalafmt-config/refs/tags/$version/.scalafmt.shared.conf",
versionFile = projectDir / ".downloads" / ".scalafmt.shared.conf.version",
outputFile = projectDir / ".downloads" / ".scalafmt.shared.conf",
processOutput = "#\n# DO NOT EDIT. See SourceDownloader in build.sbt\n" + _
)
}

Global / onLoad := {
(Global / onLoad).value andThen { state => preload.key.label :: state }
}

libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % Versions.ScalaJsDom,
"app.tulz" %%% "tuplez-full-light" % Versions.Tuplez,
@@ -155,3 +176,9 @@ Test / sourceGenerators += Def.task {
).run
)
}.taskValue

// https://github.com/JetBrains/sbt-ide-settings
SettingKey[Seq[File]]("ide-excluded-directories").withRank(KeyRanks.Invisible) := Seq(
".downloads", ".idea", ".metals", ".bloop", ".bsp",
"target", "project/target", "project/project/target", "project/project/project/target"
).map(file)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.9.7
sbt.version = 1.10.3
5 changes: 5 additions & 0 deletions project/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// #Note this is /project/build.sbt – see /build.sbt for the main build config.

libraryDependencies ++= Seq(
"com.raquo" %% "buildkit" % ProjectVersions.BuildKit,
)
4 changes: 4 additions & 0 deletions project/project/ProjectVersions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object ProjectVersions {

val BuildKit: String = "0.1.0"
}
1 change: 1 addition & 0 deletions project/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 1.10.3
Original file line number Diff line number Diff line change
@@ -110,3 +110,4 @@ class TupleSignal9[T1, T2, T3, T4, T5, T6, T7, T8, T9](val signal: Signal[(T1, T
}

// --

Original file line number Diff line number Diff line change
@@ -166,3 +166,4 @@ class TupleStream9[T1, T2, T3, T4, T5, T6, T7, T8, T9](val stream: EventStream[(
}

// --

0 comments on commit b270524

Please sign in to comment.