Repository: spark Updated Branches: refs/heads/master e3ea93ab6 -> 9a09e91a3
[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 <c...@koeninger.org> Signed-off-by: Sean Owen <sean.o...@databricks.com> Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/9a09e91a Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/9a09e91a Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/9a09e91a Branch: refs/heads/master Commit: 9a09e91a3e880b7a07b11a957fb6766578f5a1af Parents: e3ea93a Author: cody koeninger <c...@koeninger.org> Authored: Thu Nov 29 08:54:31 2018 -0600 Committer: Sean Owen <sean.o...@databricks.com> Committed: Thu Nov 29 08:54:31 2018 -0600 ---------------------------------------------------------------------- dev/.scalafmt.conf | 24 ++++++++++++++++++++++++ dev/scalafmt | 23 +++++++++++++++++++++++ pom.xml | 21 +++++++++++++++++++++ 3 files changed, 68 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/9a09e91a/dev/.scalafmt.conf ---------------------------------------------------------------------- diff --git a/dev/.scalafmt.conf b/dev/.scalafmt.conf new file mode 100644 index 0000000..def67e0 --- /dev/null +++ b/dev/.scalafmt.conf @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +align = none +align.openParenDefnSite = false +align.openParenCallSite = false +align.tokens = [] +docstrings = JavaDoc +maxColumn = 98 + http://git-wip-us.apache.org/repos/asf/spark/blob/9a09e91a/dev/scalafmt ---------------------------------------------------------------------- diff --git a/dev/scalafmt b/dev/scalafmt new file mode 100755 index 0000000..76f688a --- /dev/null +++ b/dev/scalafmt @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# by default, format only files that differ from git master +params="${@:---diff}" + +./build/mvn mvn-scalafmt_2.12:format -Dscalafmt.skip=false -Dscalafmt.parameters="$params" http://git-wip-us.apache.org/repos/asf/spark/blob/9a09e91a/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 93075e9..3ca2f73 100644 --- a/pom.xml +++ b/pom.xml @@ -156,6 +156,9 @@ <commons.collections.version>3.2.2</commons.collections.version> <scala.version>2.12.7</scala.version> <scala.binary.version>2.12</scala.binary.version> + <scalafmt.parameters>--diff --test</scalafmt.parameters> + <!-- for now, not running scalafmt as part of default verify pipeline --> + <scalafmt.skip>true</scalafmt.skip> <codehaus.jackson.version>1.9.13</codehaus.jackson.version> <fasterxml.jackson.version>2.9.6</fasterxml.jackson.version> <snappy.version>1.1.7.1</snappy.version> @@ -2600,6 +2603,24 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.antipathy</groupId> + <artifactId>mvn-scalafmt_2.12</artifactId> + <version>0.9_1.5.1</version> + <configuration> + <parameters>${scalafmt.parameters}</parameters> <!-- (Optional) Additional command line arguments --> + <skip>${scalafmt.skip}</skip> <!-- (Optional) skip formatting --> + <configLocation>dev/.scalafmt.conf</configLocation> <!-- (Optional) config locataion --> + </configuration> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>format</goal> + </goals> + </execution> + </executions> + </plugin> </plugins> </build> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org