-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Build: Integrate Scalafix to auto-fix unused Scala imports #15676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jackylee-ch
wants to merge
2
commits into
apache:main
from
jackylee-ch:apply_scalafix_to_autofix_unused_imports
+48
−2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this also work with Spark 3.5 scala 2.12?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.