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

support suppression of warning on import #30

Closed
SethTisue opened this issue Jun 18, 2019 · 11 comments
Closed

support suppression of warning on import #30

SethTisue opened this issue Jun 18, 2019 · 11 comments

Comments

@SethTisue
Copy link
Contributor

typically the warning would be a deprecation warning

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

  • a special comment?
  • a setting where you specify what deprecated things you want to be able to import warning-free?

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

@2m
Copy link

2m commented Jun 26, 2019

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
Copy link

2m commented Jun 26, 2019

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

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

@SethTisue
Copy link
Contributor Author

@ghik should this be closed, then?

@ghik
Copy link
Owner

ghik commented Jul 3, 2019

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

@SethTisue
Copy link
Contributor Author

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

@ghik
Copy link
Owner

ghik commented Jul 3, 2019

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

@taig
Copy link

taig commented Jan 6, 2020

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
Copy link
Owner

ghik commented Jan 7, 2020

@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
Copy link

taig commented Jan 7, 2020

@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.

@ghik
Copy link
Owner

ghik commented Jan 7, 2020

@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
Copy link
Owner

ghik commented Feb 18, 2020

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

@ghik ghik closed this as completed Feb 18, 2020
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

No branches or pull requests

4 participants