diff --git a/dev/.rat-excludes b/dev/.rat-excludes index 8b5061415ff4..812f14fb40a3 100644 --- a/dev/.rat-excludes +++ b/dev/.rat-excludes @@ -98,3 +98,4 @@ LZ4BlockInputStream.java spark-deps-.* .*csv .*tsv +reference.conf \ No newline at end of file diff --git a/dev/spark_scala_style_checker/src/main/resources/reference.conf b/dev/spark_scala_style_checker/src/main/resources/reference.conf new file mode 100644 index 000000000000..56bded4590a2 --- /dev/null +++ b/dev/spark_scala_style_checker/src/main/resources/reference.conf @@ -0,0 +1,3 @@ +public.abstract.methods.have.type.message = "Public abstract methods must have explicit return types" +public.abstract.methods.have.type.label = "PulicAbstractMethod" +public.abstract.methods.have.type.description = "Check that a pulic abstract method has an explicit return type, it is not inferred" diff --git a/dev/spark_scala_style_checker/src/main/scala/org/apache/spark/scala_style/PublicAbstractMethodsHaveTypeChecker.scala b/dev/spark_scala_style_checker/src/main/scala/org/apache/spark/scala_style/PublicAbstractMethodsHaveTypeChecker.scala new file mode 100644 index 000000000000..726649996131 --- /dev/null +++ b/dev/spark_scala_style_checker/src/main/scala/org/apache/spark/scala_style/PublicAbstractMethodsHaveTypeChecker.scala @@ -0,0 +1,43 @@ +/* + * 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. + */ + +package org.apache.spark.scala_style + +import org.scalastyle.scalariform.AbstractSingleMethodChecker + +import scalariform.parser.ProcFunBody + +class PublicAbstractMethodsHaveTypeChecker extends AbstractSingleMethodChecker[Unit] { + + val errorKey = "public.abstract.methods.have.type" + + protected def matchParameters() = Unit + + protected def matches(t: FullDefOrDclVisit, p: Unit) = { + + t.funDefOrDcl.funBodyOpt match { + case Some(ProcFunBody(newlineOpt, bodyBlock)) => false + case _ => // None or Some(ExprFunBody) + t.funDefOrDcl.returnTypeOpt.isEmpty && + !isConstructor(t.fullDefOrDcl.defOrDcl) && + !privateOrProtected(t.fullDefOrDcl.modifiers) && + !t.insideDefOrValOrVar && + !t.funDefOrDcl.nameToken.text.equals("main") // public static void main(...) is OK + } + + } +} diff --git a/pom.xml b/pom.xml index 4585c8b9c2b0..f3fd1d49cd8f 100644 --- a/pom.xml +++ b/pom.xml @@ -2237,6 +2237,13 @@ ${project.build.sourceEncoding} ${project.reporting.outputEncoding} + + + org.apache.spark + scala_style_checker + ${project.version} + + diff --git a/scalastyle-config.xml b/scalastyle-config.xml index a14e3e583f87..99ff884e98ba 100644 --- a/scalastyle-config.xml +++ b/scalastyle-config.xml @@ -114,6 +114,8 @@ This file is divided into 3 sections: + +