Skip to content

Commit 9a09e91

Browse files
koeningersrowen
authored andcommitted
[SPARK-26177] Automated formatting for Scala code
## What changes were proposed in this pull request? Add a maven plugin and wrapper script to use scalafmt to format files that differ from git master. Intention is for contributors to be able to use this to automate fixing code style, not to include it in build pipeline yet. If this PR is accepted, I'd make a different PR to update the code style section of https://spark.apache.org/contributing.html to mention the script ## How was this patch tested? Manually tested by modifying a few files and running ./dev/scalafmt then checking that ./dev/scalastyle still passed. Closes #23148 from koeninger/scalafmt. Authored-by: cody koeninger <cody@koeninger.org> Signed-off-by: Sean Owen <sean.owen@databricks.com>
1 parent e3ea93a commit 9a09e91

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

dev/.scalafmt.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
align = none
19+
align.openParenDefnSite = false
20+
align.openParenCallSite = false
21+
align.tokens = []
22+
docstrings = JavaDoc
23+
maxColumn = 98
24+

dev/scalafmt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership.
7+
# The ASF licenses this file to You under the Apache License, Version 2.0
8+
# (the "License"); you may not use this file except in compliance with
9+
# the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# by default, format only files that differ from git master
21+
params="${@:---diff}"
22+
23+
./build/mvn mvn-scalafmt_2.12:format -Dscalafmt.skip=false -Dscalafmt.parameters="$params"

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<commons.collections.version>3.2.2</commons.collections.version>
157157
<scala.version>2.12.7</scala.version>
158158
<scala.binary.version>2.12</scala.binary.version>
159+
<scalafmt.parameters>--diff --test</scalafmt.parameters>
160+
<!-- for now, not running scalafmt as part of default verify pipeline -->
161+
<scalafmt.skip>true</scalafmt.skip>
159162
<codehaus.jackson.version>1.9.13</codehaus.jackson.version>
160163
<fasterxml.jackson.version>2.9.6</fasterxml.jackson.version>
161164
<snappy.version>1.1.7.1</snappy.version>
@@ -2600,6 +2603,24 @@
26002603
</execution>
26012604
</executions>
26022605
</plugin>
2606+
<plugin>
2607+
<groupId>org.antipathy</groupId>
2608+
<artifactId>mvn-scalafmt_2.12</artifactId>
2609+
<version>0.9_1.5.1</version>
2610+
<configuration>
2611+
<parameters>${scalafmt.parameters}</parameters> <!-- (Optional) Additional command line arguments -->
2612+
<skip>${scalafmt.skip}</skip> <!-- (Optional) skip formatting -->
2613+
<configLocation>dev/.scalafmt.conf</configLocation> <!-- (Optional) config locataion -->
2614+
</configuration>
2615+
<executions>
2616+
<execution>
2617+
<phase>validate</phase>
2618+
<goals>
2619+
<goal>format</goal>
2620+
</goals>
2621+
</execution>
2622+
</executions>
2623+
</plugin>
26032624
</plugins>
26042625
</build>
26052626

0 commit comments

Comments
 (0)