Skip to content

Commit

Permalink
[FLINK-26553][build] Add scalafmt for formatting the Scala codebase
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slinkydeveloper authored and twalthr committed Apr 12, 2022
1 parent 36660cc commit 3ea3fee
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 338 deletions.
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ ij_java_wrap_first_method_in_call_chain = true
indent_style = tab
indent_size = 4

[*.scala]
indent_style = space
indent_size = 2

[*.py]
indent_style = space
indent_size = 4
70 changes: 70 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
runner.dialect = scala212

# Version is required to make sure IntelliJ picks the right version
version = 3.4.3
preset = default

# Max column
maxColumn = 100

# This parameter simply says the .stripMargin method was not redefined by the user to assign
# special meaning to indentation preceding the | character. Hence, that indentation can be modified.
assumeStandardLibraryStripMargin = true
align.stripMargin = true

# Align settings
align.preset = none
align.closeParenSite = false
align.openParenCallSite = false
danglingParentheses.defnSite = false
danglingParentheses.callSite = false
danglingParentheses.ctrlSite = true
danglingParentheses.tupleSite = false
align.openParenCallSite = false
align.openParenDefnSite = false
align.openParenTupleSite = false

# Newlines
newlines.alwaysBeforeElseAfterCurlyIf = false
newlines.beforeCurlyLambdaParams = multiline # Newline before lambda params
newlines.afterCurlyLambdaParams = squash # No newline after lambda params
newlines.inInterpolation = "avoid"
newlines.avoidInResultType = true
optIn.annotationNewlines = true

# Scaladoc
docstrings.style = Asterisk # Javadoc style
docstrings.removeEmpty = true
docstrings.oneline = fold
docstrings.forceBlankLineBefore = true

# Indentation
indent.extendSite = 2 # This makes sure extend is not indented as the ctor parameters

# Rewrites
rewrite.rules = [AvoidInfix, Imports, RedundantBraces, SortModifiers]

# Imports
rewrite.imports.sort = scalastyle
rewrite.imports.groups = [
["org.apache.flink\\..*"],
["org.apache.flink.shaded\\..*"],
[".*"],
["javax\\..*"],
["java\\..*"],
["scala\\..*"]
]
rewrite.imports.contiguousGroups = no
importSelectors = singleline # Imports in a single line, like IntelliJ

# Remove redundant braces in string interpolation.
rewrite.redundantBraces.stringInterpolation = true
rewrite.redundantBraces.defnBodies = false
rewrite.redundantBraces.generalExpressions = false
rewrite.redundantBraces.ifElseExpressions = false
rewrite.redundantBraces.methodBodies = false
rewrite.redundantBraces.includeUnitMethods = false
rewrite.redundantBraces.maxBreaks = 1

# Remove trailing commas
rewrite.trailingCommas.style = "never"
9 changes: 0 additions & 9 deletions flink-connectors/flink-hadoop-compatibility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,6 @@ under the License.
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<!-- Add test classes to test jar in order to test WritableTypeInfo. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
10 changes: 0 additions & 10 deletions flink-connectors/flink-hcatalog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,6 @@ under the License.
</execution>
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

</plugins>
</build>

Expand Down
11 changes: 1 addition & 10 deletions flink-end-to-end-tests/flink-end-to-end-tests-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ under the License.
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<!-- Add Scala test classes to test jar in order to test Scala type information. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -226,4 +217,4 @@ under the License.
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MVN_LOGGING_OPTIONS="-Dlog.dir=${DEBUG_FILES_OUTPUT_DIR} -Dlog4j.configurationFi

function run_mvn_test {
local test_class=$1
run_mvn test $MVN_LOGGING_OPTIONS -Dtest=${test_class}
run_mvn test -pl flink-kubernetes $MVN_LOGGING_OPTIONS -Dtest=${test_class}

EXIT_CODE=$?
if [ $EXIT_CODE != 0 ]; then
Expand All @@ -41,7 +41,7 @@ function run_mvn_test {
fi
}

cd $END_TO_END_DIR/../flink-kubernetes
cd $END_TO_END_DIR/..

# Run the ITCases
run_mvn_test org.apache.flink.kubernetes.kubeclient.Fabric8FlinkKubeClientITCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@
################################################################################

# This test is a Java end to end test, but it requires Docker. Therefore, we run it from bash.

cd "${END_TO_END_DIR}/flink-connector-gcp-pubsub-emulator-tests"

run_mvn test -DskipTests=false
run_mvn test -DskipTests=false -pl flink-end-to-end-tests/flink-connector-gcp-pubsub-emulator-tests
9 changes: 0 additions & 9 deletions flink-examples/flink-examples-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,6 @@ under the License.
</execution>
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<!-- create the example JAR files -->
<plugin>
Expand Down
9 changes: 0 additions & 9 deletions flink-examples/flink-examples-streaming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ under the License.
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<!-- self-contained jars for each example -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
9 changes: 0 additions & 9 deletions flink-libraries/flink-cep-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ under the License.
</execution>
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<!-- Adding scala source directories to build path for Eclipse and generating the sources jar -->
<plugin>
Expand Down
9 changes: 0 additions & 9 deletions flink-libraries/flink-gelly-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,6 @@
</execution>
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
9 changes: 0 additions & 9 deletions flink-libraries/flink-gelly-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,6 @@ under the License.
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<!-- build a jar-with-dependencies, to be included in the 'opt' build folder -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ object Graph {
* @tparam EV Edge value type
* @return Graph with vertices and edges read from the given files.
*/
// scalastyle:off
// This method exceeds the max allowed number of parameters -->
def fromCsvReader[
K: TypeInformation : ClassTag,
Expand Down Expand Up @@ -290,7 +289,6 @@ object Graph {
}
}
}
// scalastyle:on
}

/**
Expand Down
9 changes: 0 additions & 9 deletions flink-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,6 @@ under the License.
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<!-- Add Scala test classes to test jar in order to test Scala type information. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,8 @@ object ClosureCleaner {
} else {
LOG.debug(s"Cleaning lambda: ${lambdaFunc.get.getImplMethodName}")

// scalastyle:off classforname
val captClass = Class.forName(lambdaFunc.get.getCapturingClass.replace('/', '.'),
false, Thread.currentThread.getContextClassLoader)
// scalastyle:on classforname
// Fail fast if we detect return statements in closures
getClassReader(captClass)
.accept(new ReturnStatementFinder(Some(lambdaFunc.get.getImplMethodName)), 0)
Expand Down Expand Up @@ -593,12 +591,10 @@ private class InnerClosureFinder(output: Set[Class[_]]) extends ClassVisitor(ASM
if (op == INVOKESPECIAL && name == "<init>" && argTypes.length > 0
&& argTypes(0).toString.startsWith("L") // is it an object?
&& argTypes(0).getInternalName == myName) {
// scalastyle:off classforname
output += Class.forName(
owner.replace('/', '.'),
false,
Thread.currentThread.getContextClassLoader)
// scalastyle:on classforname
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions flink-streaming-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,6 @@ under the License.
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<!-- activate API compatibility checks -->
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
Expand Down
9 changes: 0 additions & 9 deletions flink-table/flink-table-api-scala-bridge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ under the License.
</execution>
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>
</project>
9 changes: 0 additions & 9 deletions flink-table/flink-table-api-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,6 @@ under the License.
</execution>
</executions>
</plugin>

<!-- Scala Code Style -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>
</project>
9 changes: 0 additions & 9 deletions flink-table/flink-table-planner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,6 @@ under the License.
</configuration>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
9 changes: 0 additions & 9 deletions flink-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,6 @@ under the License.
</execution>
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
9 changes: 0 additions & 9 deletions flink-yarn-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,6 @@ under the License.
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Loading

0 comments on commit 3ea3fee

Please sign in to comment.