Skip to content
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

respect -Xlint or -Xlint:unused scalac options in RemoveUnused rule #1163

Merged
merged 2 commits into from
Jun 15, 2020

Conversation

taisukeoe
Copy link
Contributor

@taisukeoe taisukeoe commented Jun 14, 2020

This PullRequests suppress RemoveUnused configuration error if scalac options contain -Xlint or -Xlint:unused, both of which generate and add unused diagnostics message string into SemanticDB.

Note: There might be discussions at the following point.

-Xlint linting options notation

Currently this PullRequest supports no explicit linting option (just -Xlint) or only a linting option per a line (-Xlint:unused) for implementation simplicity. IMHO this covers majority of -Xlint usage, as long as I check with "-Xlint" GitHub search.

This PR does NOT support multiple linting options together like -Xlint:unused,constant, wildcard like -Xlint:_, nor unary operator like -Xlint:-constant,_.

If we want to support multiple linting options notation or else above, it may need to introduce a simple scalac option parser (or just check in a naive way, like
option.startsWith("-Xlint:") && (option.contains("_") || option.contains("unused")) && !option.contains("-unused") ?).

)
if (!hasWarnUnused) {
Configured.error(
s"""|The Scala compiler option "-Ywarn-unused" is required to use RemoveUnused.
|To fix this problem, update your build to use at least one Scala compiler
|option that starts with -Ywarn-unused or -Wunused (2.13 only)""".stripMargin
|option like -Ywarn-unused, -Xlint:unused, or -Wunused (2.13 only).""".stripMargin
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add -Xlint to suggestions in the error message since -Xlint is for multi purposes.

@taisukeoe taisukeoe force-pushed the respect-xlint-unused branch from 630e378 to 555f2d2 Compare June 14, 2020 15:49
)
if (!hasWarnUnused) {
Configured.error(
s"""|The Scala compiler option "-Ywarn-unused" is required to use RemoveUnused.
|To fix this problem, update your build to use at least one Scala compiler
|option that starts with -Ywarn-unused or -Wunused (2.13 only)""".stripMargin
|option like -Ywarn-unused, -Xlint:unused (2.12.2 or above), or -Wunused (2.13 only)""".stripMargin
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused warnings by -Xlint or -Xlint:unused are effective since Scala 2.12.2.

scala/bug#10270
scala/scala#5402

So suggesting -Xlint:unused is not relevant in Scala 2.12.1 or lower while Scalafix still supports 2.11 . To be safer, I would clarify which versions are supported.

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants