Skip to content

Commit 3ea3fee

Browse files
slinkydevelopertwalthr
authored andcommitted
[FLINK-26553][build] Add scalafmt for formatting the Scala codebase
Run 'mvn spotless:apply' for auto-formatting the code base. Usually, IntelliJ should pick it up automatically if the Scala plugin is installed. This closes apache#19025.
1 parent 36660cc commit 3ea3fee

File tree

24 files changed

+105
-338
lines changed

24 files changed

+105
-338
lines changed

.editorconfig

-4
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ ij_java_wrap_first_method_in_call_chain = true
267267
indent_style = tab
268268
indent_size = 4
269269

270-
[*.scala]
271-
indent_style = space
272-
indent_size = 2
273-
274270
[*.py]
275271
indent_style = space
276272
indent_size = 4

.scalafmt.conf

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
runner.dialect = scala212
2+
3+
# Version is required to make sure IntelliJ picks the right version
4+
version = 3.4.3
5+
preset = default
6+
7+
# Max column
8+
maxColumn = 100
9+
10+
# This parameter simply says the .stripMargin method was not redefined by the user to assign
11+
# special meaning to indentation preceding the | character. Hence, that indentation can be modified.
12+
assumeStandardLibraryStripMargin = true
13+
align.stripMargin = true
14+
15+
# Align settings
16+
align.preset = none
17+
align.closeParenSite = false
18+
align.openParenCallSite = false
19+
danglingParentheses.defnSite = false
20+
danglingParentheses.callSite = false
21+
danglingParentheses.ctrlSite = true
22+
danglingParentheses.tupleSite = false
23+
align.openParenCallSite = false
24+
align.openParenDefnSite = false
25+
align.openParenTupleSite = false
26+
27+
# Newlines
28+
newlines.alwaysBeforeElseAfterCurlyIf = false
29+
newlines.beforeCurlyLambdaParams = multiline # Newline before lambda params
30+
newlines.afterCurlyLambdaParams = squash # No newline after lambda params
31+
newlines.inInterpolation = "avoid"
32+
newlines.avoidInResultType = true
33+
optIn.annotationNewlines = true
34+
35+
# Scaladoc
36+
docstrings.style = Asterisk # Javadoc style
37+
docstrings.removeEmpty = true
38+
docstrings.oneline = fold
39+
docstrings.forceBlankLineBefore = true
40+
41+
# Indentation
42+
indent.extendSite = 2 # This makes sure extend is not indented as the ctor parameters
43+
44+
# Rewrites
45+
rewrite.rules = [AvoidInfix, Imports, RedundantBraces, SortModifiers]
46+
47+
# Imports
48+
rewrite.imports.sort = scalastyle
49+
rewrite.imports.groups = [
50+
["org.apache.flink\\..*"],
51+
["org.apache.flink.shaded\\..*"],
52+
[".*"],
53+
["javax\\..*"],
54+
["java\\..*"],
55+
["scala\\..*"]
56+
]
57+
rewrite.imports.contiguousGroups = no
58+
importSelectors = singleline # Imports in a single line, like IntelliJ
59+
60+
# Remove redundant braces in string interpolation.
61+
rewrite.redundantBraces.stringInterpolation = true
62+
rewrite.redundantBraces.defnBodies = false
63+
rewrite.redundantBraces.generalExpressions = false
64+
rewrite.redundantBraces.ifElseExpressions = false
65+
rewrite.redundantBraces.methodBodies = false
66+
rewrite.redundantBraces.includeUnitMethods = false
67+
rewrite.redundantBraces.maxBreaks = 1
68+
69+
# Remove trailing commas
70+
rewrite.trailingCommas.style = "never"

flink-connectors/flink-hadoop-compatibility/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,6 @@ under the License.
178178
</executions>
179179
</plugin>
180180

181-
<!-- Scala Code Style, most of the configuration done via plugin management -->
182-
<plugin>
183-
<groupId>org.scalastyle</groupId>
184-
<artifactId>scalastyle-maven-plugin</artifactId>
185-
<configuration>
186-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
187-
</configuration>
188-
</plugin>
189-
190181
<!-- Add test classes to test jar in order to test WritableTypeInfo. -->
191182
<plugin>
192183
<groupId>org.apache.maven.plugins</groupId>

flink-connectors/flink-hcatalog/pom.xml

-10
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,6 @@ under the License.
192192
</execution>
193193
</executions>
194194
</plugin>
195-
196-
<!-- Scala Code Style, most of the configuration done via plugin management -->
197-
<plugin>
198-
<groupId>org.scalastyle</groupId>
199-
<artifactId>scalastyle-maven-plugin</artifactId>
200-
<configuration>
201-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
202-
</configuration>
203-
</plugin>
204-
205195
</plugins>
206196
</build>
207197

flink-end-to-end-tests/flink-end-to-end-tests-scala/pom.xml

+1-10
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,6 @@ under the License.
202202
</executions>
203203
</plugin>
204204

205-
<!-- Scala Code Style, most of the configuration done via plugin management -->
206-
<plugin>
207-
<groupId>org.scalastyle</groupId>
208-
<artifactId>scalastyle-maven-plugin</artifactId>
209-
<configuration>
210-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
211-
</configuration>
212-
</plugin>
213-
214205
<!-- Add Scala test classes to test jar in order to test Scala type information. -->
215206
<plugin>
216207
<groupId>org.apache.maven.plugins</groupId>
@@ -226,4 +217,4 @@ under the License.
226217
</plugins>
227218
</build>
228219

229-
</project>
220+
</project>

flink-end-to-end-tests/test-scripts/test_kubernetes_itcases.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ MVN_LOGGING_OPTIONS="-Dlog.dir=${DEBUG_FILES_OUTPUT_DIR} -Dlog4j.configurationFi
3232

3333
function run_mvn_test {
3434
local test_class=$1
35-
run_mvn test $MVN_LOGGING_OPTIONS -Dtest=${test_class}
35+
run_mvn test -pl flink-kubernetes $MVN_LOGGING_OPTIONS -Dtest=${test_class}
3636

3737
EXIT_CODE=$?
3838
if [ $EXIT_CODE != 0 ]; then
@@ -41,7 +41,7 @@ function run_mvn_test {
4141
fi
4242
}
4343

44-
cd $END_TO_END_DIR/../flink-kubernetes
44+
cd $END_TO_END_DIR/..
4545

4646
# Run the ITCases
4747
run_mvn_test org.apache.flink.kubernetes.kubeclient.Fabric8FlinkKubeClientITCase

flink-end-to-end-tests/test-scripts/test_streaming_gcp_pubsub.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,4 @@
1818
################################################################################
1919

2020
# This test is a Java end to end test, but it requires Docker. Therefore, we run it from bash.
21-
22-
cd "${END_TO_END_DIR}/flink-connector-gcp-pubsub-emulator-tests"
23-
24-
run_mvn test -DskipTests=false
21+
run_mvn test -DskipTests=false -pl flink-end-to-end-tests/flink-connector-gcp-pubsub-emulator-tests

flink-examples/flink-examples-batch/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,6 @@ under the License.
164164
</execution>
165165
</executions>
166166
</plugin>
167-
168-
<!-- Scala Code Style, most of the configuration done via plugin management -->
169-
<plugin>
170-
<groupId>org.scalastyle</groupId>
171-
<artifactId>scalastyle-maven-plugin</artifactId>
172-
<configuration>
173-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
174-
</configuration>
175-
</plugin>
176167

177168
<!-- create the example JAR files -->
178169
<plugin>

flink-examples/flink-examples-streaming/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,6 @@ under the License.
143143
</executions>
144144
</plugin>
145145

146-
<!-- Scala Code Style, most of the configuration done via plugin management -->
147-
<plugin>
148-
<groupId>org.scalastyle</groupId>
149-
<artifactId>scalastyle-maven-plugin</artifactId>
150-
<configuration>
151-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
152-
</configuration>
153-
</plugin>
154-
155146
<!-- self-contained jars for each example -->
156147
<plugin>
157148
<groupId>org.apache.maven.plugins</groupId>

flink-libraries/flink-cep-scala/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@ under the License.
122122
</execution>
123123
</executions>
124124
</plugin>
125-
126-
<!-- Scala Code Style, most of the configuration done via plugin management -->
127-
<plugin>
128-
<groupId>org.scalastyle</groupId>
129-
<artifactId>scalastyle-maven-plugin</artifactId>
130-
<configuration>
131-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
132-
</configuration>
133-
</plugin>
134125

135126
<!-- Adding scala source directories to build path for Eclipse and generating the sources jar -->
136127
<plugin>

flink-libraries/flink-gelly-examples/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,6 @@
236236
</execution>
237237
</executions>
238238
</plugin>
239-
240-
<!-- Scala Code Style, most of the configuration done via plugin management -->
241-
<plugin>
242-
<groupId>org.scalastyle</groupId>
243-
<artifactId>scalastyle-maven-plugin</artifactId>
244-
<configuration>
245-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
246-
</configuration>
247-
</plugin>
248239
</plugins>
249240
</build>
250241

flink-libraries/flink-gelly-scala/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,6 @@ under the License.
199199
</executions>
200200
</plugin>
201201

202-
<!-- Scala Code Style, most of the configuration done via plugin management -->
203-
<plugin>
204-
<groupId>org.scalastyle</groupId>
205-
<artifactId>scalastyle-maven-plugin</artifactId>
206-
<configuration>
207-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
208-
</configuration>
209-
</plugin>
210-
211202
<!-- build a jar-with-dependencies, to be included in the 'opt' build folder -->
212203
<plugin>
213204
<artifactId>maven-assembly-plugin</artifactId>

flink-libraries/flink-gelly-scala/src/main/scala/org/apache/flink/graph/scala/Graph.scala

-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ object Graph {
218218
* @tparam EV Edge value type
219219
* @return Graph with vertices and edges read from the given files.
220220
*/
221-
// scalastyle:off
222221
// This method exceeds the max allowed number of parameters -->
223222
def fromCsvReader[
224223
K: TypeInformation : ClassTag,
@@ -290,7 +289,6 @@ object Graph {
290289
}
291290
}
292291
}
293-
// scalastyle:on
294292
}
295293

296294
/**

flink-scala/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,6 @@ under the License.
252252
</executions>
253253
</plugin>
254254

255-
<!-- Scala Code Style, most of the configuration done via plugin management -->
256-
<plugin>
257-
<groupId>org.scalastyle</groupId>
258-
<artifactId>scalastyle-maven-plugin</artifactId>
259-
<configuration>
260-
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
261-
</configuration>
262-
</plugin>
263-
264255
<!-- Add Scala test classes to test jar in order to test Scala type information. -->
265256
<plugin>
266257
<groupId>org.apache.maven.plugins</groupId>

flink-scala/src/main/scala/org/apache/flink/api/scala/ClosureCleaner.scala

-4
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,8 @@ object ClosureCleaner {
381381
} else {
382382
LOG.debug(s"Cleaning lambda: ${lambdaFunc.get.getImplMethodName}")
383383

384-
// scalastyle:off classforname
385384
val captClass = Class.forName(lambdaFunc.get.getCapturingClass.replace('/', '.'),
386385
false, Thread.currentThread.getContextClassLoader)
387-
// scalastyle:on classforname
388386
// Fail fast if we detect return statements in closures
389387
getClassReader(captClass)
390388
.accept(new ReturnStatementFinder(Some(lambdaFunc.get.getImplMethodName)), 0)
@@ -593,12 +591,10 @@ private class InnerClosureFinder(output: Set[Class[_]]) extends ClassVisitor(ASM
593591
if (op == INVOKESPECIAL && name == "<init>" && argTypes.length > 0
594592
&& argTypes(0).toString.startsWith("L") // is it an object?
595593
&& argTypes(0).getInternalName == myName) {
596-
// scalastyle:off classforname
597594
output += Class.forName(
598595
owner.replace('/', '.'),
599596
false,
600597
Thread.currentThread.getContextClassLoader)
601-
// scalastyle:on classforname
602598
}
603599
}
604600
}

flink-streaming-scala/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,6 @@ under the License.
238238
</executions>
239239
</plugin>
240240

241-
<!-- Scala Code Style, most of the configuration done via plugin management -->
242-
<plugin>
243-
<groupId>org.scalastyle</groupId>
244-
<artifactId>scalastyle-maven-plugin</artifactId>
245-
<configuration>
246-
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
247-
</configuration>
248-
</plugin>
249-
250241
<!-- activate API compatibility checks -->
251242
<plugin>
252243
<groupId>com.github.siom79.japicmp</groupId>

flink-table/flink-table-api-scala-bridge/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ under the License.
103103
</execution>
104104
</executions>
105105
</plugin>
106-
107-
<!-- Scala Code Style, most of the configuration done via plugin management -->
108-
<plugin>
109-
<groupId>org.scalastyle</groupId>
110-
<artifactId>scalastyle-maven-plugin</artifactId>
111-
<configuration>
112-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
113-
</configuration>
114-
</plugin>
115106
</plugins>
116107
</build>
117108
</project>

flink-table/flink-table-api-scala/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,6 @@ under the License.
114114
</execution>
115115
</executions>
116116
</plugin>
117-
118-
<!-- Scala Code Style -->
119-
<plugin>
120-
<groupId>org.scalastyle</groupId>
121-
<artifactId>scalastyle-maven-plugin</artifactId>
122-
<configuration>
123-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
124-
</configuration>
125-
</plugin>
126117
</plugins>
127118
</build>
128119
</project>

flink-table/flink-table-planner/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,6 @@ under the License.
389389
</configuration>
390390
</plugin>
391391

392-
<!-- Scala Code Style, most of the configuration done via plugin management -->
393-
<plugin>
394-
<groupId>org.scalastyle</groupId>
395-
<artifactId>scalastyle-maven-plugin</artifactId>
396-
<configuration>
397-
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
398-
</configuration>
399-
</plugin>
400-
401392
<plugin>
402393
<groupId>org.apache.maven.plugins</groupId>
403394
<artifactId>maven-jar-plugin</artifactId>

flink-tests/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,6 @@ under the License.
374374
</execution>
375375
</executions>
376376
</plugin>
377-
378-
<!-- Scala Code Style, most of the configuration done via plugin management -->
379-
<plugin>
380-
<groupId>org.scalastyle</groupId>
381-
<artifactId>scalastyle-maven-plugin</artifactId>
382-
<configuration>
383-
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
384-
</configuration>
385-
</plugin>
386377

387378
<plugin>
388379
<groupId>org.apache.maven.plugins</groupId>

flink-yarn-tests/pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,6 @@ under the License.
344344
</executions>
345345
</plugin>
346346

347-
<!-- Scala Code Style, most of the configuration done via plugin management -->
348-
<plugin>
349-
<groupId>org.scalastyle</groupId>
350-
<artifactId>scalastyle-maven-plugin</artifactId>
351-
<configuration>
352-
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
353-
</configuration>
354-
</plugin>
355-
356347
<plugin>
357348
<groupId>org.apache.maven.plugins</groupId>
358349
<artifactId>maven-jar-plugin</artifactId>

0 commit comments

Comments
 (0)