Skip to content

Commit ec64842

Browse files
authoredMay 3, 2023
align with Spark scalastyle (#1606)
Signed-off-by: Peng Huo <penghuo@gmail.com>
1 parent 9050c6c commit ec64842

6 files changed

+506
-24
lines changed
 

‎.scalafmt.conf

-3
This file was deleted.

‎DEVELOPER_GUIDE.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
## Scala Formatting Guidelines
44

5-
For Scala code, We use [scalafmt](https://scalameta.org/scalafmt/) to format the code and check the code style.
65

7-
To use the plugin, user could check the style
6+
For Scala code, flint use [spark scalastyle](https://github.com/apache/spark/blob/master/scalastyle-config.xml). Before submitting the PR,
7+
make sure to use "scalafmtAll" to format the code. read more in [scalafmt sbt](https://scalameta.org/scalafmt/docs/installation.html#sbt)
88
```
9-
sbt scalafmtCheck
9+
sbt scalafmtAll
1010
```
11-
The code can be formatted with
11+
The code style is automatically checked, but users can also manually check it.
1212
```
13-
sbt scalafmtAll
13+
sbt sbt scalastyle
1414
```
15-
For more sbt tasks, read more in [scalafmt sbt](https://scalameta.org/scalafmt/docs/installation.html#sbt)
16-
17-
For Intellij user, read more in [scalafmt IntelliJ](https://scalameta.org/scalafmt/docs/installation.html#intellij)
15+
For IntelliJ user, read more in [scalafmt IntelliJ](https://scalameta.org/scalafmt/docs/installation.html#intellij) to integrate
16+
scalafmt with IntelliJ

‎build.sbt

+26-13
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,46 @@
55

66
lazy val scala212 = "2.12.14"
77
lazy val sparkVersion = "3.3.1"
8+
lazy val opensearchVersion = "2.6.0"
89

910
ThisBuild / version := "0.1.0-SNAPSHOT"
1011

1112
ThisBuild / scalaVersion := scala212
1213

14+
ThisBuild / scalafmtConfig := baseDirectory.value / "dev/.scalafmt.conf"
15+
16+
/**
17+
* ScalaStyle configurations
18+
*/
19+
ThisBuild / scalastyleConfig := baseDirectory.value / "scalastyle-config.xml"
20+
21+
// Run as part of compile task.
22+
lazy val compileScalastyle = taskKey[Unit]("compileScalastyle")
23+
24+
// Run as part of test task.
25+
lazy val testScalastyle = taskKey[Unit]("testScalastyle")
26+
27+
lazy val commonSettings = Seq(
28+
// Scalastyle
29+
scalastyleConfig := (ThisBuild / scalastyleConfig).value,
30+
compileScalastyle := (Compile / scalastyle).toTask("").value,
31+
Compile / compile := ((Compile / compile) dependsOn compileScalastyle).value,
32+
testScalastyle := (Test / scalastyle).toTask("").value,
33+
Test / test := ((Test / test) dependsOn testScalastyle).value)
34+
1335
lazy val root = (project in file("."))
1436
.aggregate(flintCore, flintSparkIntegration)
15-
.settings(
16-
name := "flint"
17-
)
37+
.settings(name := "flint")
1838

1939
lazy val flintCore = (project in file("flint-core"))
20-
.settings(
21-
name := "flint-core",
22-
scalaVersion := scala212
23-
)
40+
.settings(name := "flint-core", scalaVersion := scala212)
2441

2542
lazy val flintSparkIntegration = (project in file("flint-spark-integration"))
2643
.dependsOn(flintCore)
2744
.settings(
45+
commonSettings,
2846
name := "flint-spark-integration",
2947
scalaVersion := scala212,
30-
Compile / compile := (Compile / compile)
31-
.dependsOn(Compile / scalafmtCheck)
32-
.value,
3348
libraryDependencies ++= Seq(
3449
"org.apache.spark" %% "spark-core" % sparkVersion,
35-
"org.apache.spark" %% "spark-sql" % sparkVersion
36-
)
37-
)
50+
"org.apache.spark" %% "spark-sql" % sparkVersion))

‎dev/.scalafmt.conf

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Copyright OpenSearch Contributors
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
version = 3.7.3
7+
8+
# align with spark. https://github.com/apache/spark/blob/master/dev/.scalafmt.conf
9+
align = none
10+
align.openParenDefnSite = false
11+
align.openParenCallSite = false
12+
align.tokens = []
13+
importSelectors = "singleLine"
14+
optIn = {
15+
configStyleArguments = false
16+
}
17+
danglingParentheses.preset = false
18+
docstrings.style = Asterisk
19+
maxColumn = 98
20+
runner.dialect = scala212
21+
22+
# flint customized rules
23+
rewrite.rules = [Imports]
24+
rewrite.imports.sort = scalastyle
25+
# groups order
26+
# java
27+
# scala
28+
# 3rdParty
29+
# spark
30+
rewrite.imports.groups = [
31+
["javax?.*"],
32+
["scala\\..*"],
33+
["(?!org\\.apache\\.spark\\.).*"],
34+
["org\\.apache\\.spark\\..*"]
35+
]

‎project/plugins.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
*/
55

66
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
7+
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
8+
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.8.0")

‎scalastyle-config.xml

+436
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.