ghik / silencer

Scala compiler plugin for warning suppression
Apache License 2.0
255 stars 33 forks source link

support suppression of warning on `import` #30

Closed SethTisue closed 4 years ago

SethTisue commented 5 years ago

typically the warning would be a deprecation warning

imports can't have annotations, so it would have to be via some other mechanism:

(opening the issue partly as documentation that there isn't any support currently)

2m commented 5 years ago

I have bumped into this when migrating some code that is using .mapValues from 2.12 to 2.13. Such code shows a warning with 2.13 and suggests to change to .view.mapValues. However for that one to compile with 2.12 an import scala.collection.compat._ is needed. Which is unused in 2.13 and thus shows a warning. :)

2m commented 5 years ago

I was able to use the warning message matching for this:

Compile / compile / scalacOptions += "-P:silencer:globalFilters=[import scala.collection.compat._]"
SethTisue commented 5 years ago

@ghik should this be closed, then?

ghik commented 5 years ago

@SethTisue why? It's as unsolved as it was in the beginning so it still serves its original "partly documentation" purpose, right?

SethTisue commented 5 years ago

I wasn't aware when I opened the ticket that globalFilters was applicable

ghik commented 5 years ago

Yeah, but it's global so it can't be used to silent each import independently.

taig commented 4 years ago

I was able to use the warning message matching for this:

Compile / compile / scalacOptions += "-P:silencer:globalFilters=[import scala.collection.compat._]"

Unfortunately this suppressed all warnings ~from files with an import scala.collection.compat._~ for me.

ghik commented 4 years ago

@Taig silencer has a test for that situation and everything looks good. Can you file a separate issue for that and provide a reproduction?

taig commented 4 years ago

@ghik I prepared a reproducer and checked out the project to take a deeper look and possibly submit a fix. I'm happy to share the reproduction repo and raise a new issue but I have a couple assumptions that I'd like to clarify beforehand:

ghik commented 4 years ago

@Taig thanks a lot for your insight, it indeed looks like @2m accidentally silenced everything.

I think the solution would be to create a separate option to silence warnings based on line content. I've created #42 for that.

ghik commented 4 years ago

42 is fixed and IMO this is the best solution for suppressing unused import warnings.