Closed SethTisue closed 4 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. :)
I was able to use the warning message matching for this:
Compile / compile / scalacOptions += "-P:silencer:globalFilters=[import scala.collection.compat._]"
@ghik should this be closed, then?
@SethTisue why? It's as unsolved as it was in the beginning so it still serves its original "partly documentation" purpose, right?
I wasn't aware when I opened the ticket that globalFilters
was applicable
Yeah, but it's global so it can't be used to silent each import independently.
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.
@Taig silencer
has a test for that situation and everything looks good. Can you file a separate issue for that and provide a reproduction?
@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:
The globalFilters
syntax shared in this issue ("-P:silencer:globalFilters=[import scala.collection.compat._]"
) appears to be wrong. From what I understand it should be a ;
-delimited list of regexes. So in this case probably something like "-P:silencer:globalFilters=import scala\\.collection\\.compat\\._"
.
Given that the globalFilters
directive from above [import scala.collection.compat._]
is treated as a regex, the contained .
probably disables/filters all messages which is the issue I was seeing.
When I look into the plugin's filter
method and the msg
it receives, I see an "Unused import" message, but it does not provide the second line which specifies the affected import. I therefore think that it's not possible to filter for a specific import as attempted in this issue.
@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.
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)