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
23 changes: 23 additions & 0 deletions .baseline/scala/.scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

rules = [RemoveUnused]
RemoveUnused.imports = true
RemoveUnused.privates = false
RemoveUnused.locals = false
RemoveUnused.patternvars = false
RemoveUnused.params = false
19 changes: 17 additions & 2 deletions baseline.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,21 @@ subprojects {
}

pluginManager.withPlugin('scala') {
apply plugin: 'io.github.cosmicsilence.scalafix'

scalafix {
configFile = file("${rootDir}/.baseline/scala/.scalafix.conf")
semanticdb {
autoConfigure = true
}
}

// When running scalafix, downgrade unused import errors to warnings so that
// compilation succeeds and SemanticDB is produced for Scalafix to process.
boolean scalafixRun = gradle.startParameter.taskNames.any {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This really feels like a bug in the cosmic-silence plugin. It should be automatically be downgrading the tasks on it's own.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Its working principle is to handle the issue only after a Scala compile warning occurs, since it doesn't perform the unused check itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In fact, introducing Scalafix is ​​a bit heavy, but we lack this component.
Alternatively, do you think we can maintain the current state and let users handle this code style issue themselves when they receive compilation failures related to unused imports?
If so, the PR and the issue can be closed now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we are better off just not adding anything to the build, I've grown very paranoid of adding things to the build with all the supply chain attacks lately and even though I think this would be relatively safe, I don't think we really gain that much by giving folks an auto fix command. We aren't really a scala project so the benefits here feel very low compared to adding complexity to the build and a new plugin.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, would close current PR and Issue. Thanks for your clarify.

it.toLowerCase().contains('scalafix')
}

tasks.withType(ScalaCompile).configureEach { scalaCompile ->
if (scalaVersion?.startsWith("2.12")) {
scalaCompile.scalaCompileOptions.additionalParameters = [
Expand All @@ -196,8 +211,8 @@ subprojects {
]
} else if (scalaVersion?.startsWith("2.13")) {
scalaCompile.scalaCompileOptions.additionalParameters = [
"-Wconf:cat=unused:error",
"-Wunused:imports"
"-Wunused:imports",
scalafixRun ? "-Wconf:cat=unused:warning" : "-Wconf:cat=unused:error",
]
}
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ buildscript {
classpath 'me.champeau.jmh:jmh-gradle-plugin:0.7.3'
classpath 'gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.6'
classpath "com.github.alisiikh:gradle-scalastyle-plugin:3.5.0"
classpath 'io.github.cosmicsilence:gradle-scalafix:0.2.6'
classpath 'org.revapi:gradle-revapi:1.8.0'
classpath 'com.gorylenko.gradle-git-properties:gradle-git-properties:2.5.7'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:4.3.0'
Expand Down
7 changes: 7 additions & 0 deletions site/docs/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Iceberg is built using Gradle with Java 17 or 21.
* To invoke a build and run tests: `./gradlew build`
* To skip tests: `./gradlew build -x test -x integrationTest`
* To fix code style: `./gradlew spotlessApply`
* To fix Scala unused imports: `./gradlew scalafix`
* To build particular Spark/Flink Versions: `./gradlew build -DsparkVersions=3.5,4.0 -DflinkVersions=1.20,2.0`

Iceberg table support is organized in library modules:
Expand Down Expand Up @@ -303,6 +304,12 @@ In order to automatically fix Java code style issues, please use `./gradlew spot
since that version is compatible with JDK 8. When formatting the code in the IDE, there is a slight chance that it will produce slightly different results. In such a case please run `./gradlew spotlessApply`
as CI will check the style against **google-java-format** 1.7.

For Scala code, unused imports are treated as compilation errors. To automatically remove unused imports, run [Scalafix](https://scalacenter.github.io/scalafix/):

```bash
./gradlew scalafix -DsparkVersions=4.0 -DscalaVersion=2.13
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this also work with Spark 3.5 scala 2.12?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it works.

```

### Copyright

Each file must include the Apache license information as a header.
Expand Down
Loading