Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions project/SparkBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,18 @@ object SparkBuild extends PomBuild {
// We special case the 'println' lint rule to only be a warning on compile, because adding
// printlns for debugging is a common use case and is easy to remember to remove.
val scalaStyleOnCompileConfig: String = {
val in = "scalastyle-config.xml"
val base_style_config = "scalastyle-config.xml"
val prod_style_config = "scalastyle-config-prod.xml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Is this a convention? Does something named -prod only check the format of a specific directory?
  2. It is necessary to synchronize the modifications to the scalastyle-maven-plugin in the parent pom.xml.

Copy link
Member

@gengliangwang gengliangwang Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here: scalastyle-config-prod.xml is for production code, which means it won't check the style of tests.

But I can't tell the difference of the target files from the PR changes...

val out = "scalastyle-on-compile.generated.xml"
val replacements = Map(
"""customId="println" level="error"""" -> """customId="println" level="warn""""
)
val source = Source.fromFile(in)
val base_source = Source.fromFile(base_style_config)
val prod_source = Source.fromFile(prod_style_config)
try {
var contents = source.getLines.mkString("\n")
val base_lines = base_source.getLines().toList.dropRight(1)
val prod_lines = prod_source.getLines().drop(23)
var contents = base_lines.mkString("\n") + "\n" + prod_lines.mkString("\n")
for ((k, v) <- replacements) {
require(contents.contains(k), s"Could not rewrite '$k' in original scalastyle config.")
contents = contents.replace(k, v)
Expand All @@ -173,7 +177,8 @@ object SparkBuild extends PomBuild {
}
out
} finally {
source.close()
base_source.close()
prod_source.close()
}
}

Expand Down
31 changes: 31 additions & 0 deletions scalastyle-config-prod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
~ 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.
-->
<!--
This file defines a Scala style check to ensure logged inline variables follow the
Structured Logging Framework guidelines, as outlined in SPARK-47240.
-->
<scalastyle>
<name>Scalastyle configuration for prod only</name>

<check customId="inlineVariableMDC" level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters><parameter name="regex">log(?:Info|Warning|Error)\((?:".*"\.format\(.*\)|s".*(?:\$|\+\s*[^\s"]).*"\))</parameter></parameters>
<customMessage>
Logging message should use log"..." instead of s"..." and variables should be wrapped in `MDC`s.
Refer to Structured Logging Framework guidelines in the file `internal/Logging.scala`.
</customMessage>
</check>
</scalastyle>