acyclic icon indicating copy to clipboard operation
acyclic copied to clipboard

Doesn’t play well with `-Ywarn-unused-import`.

Open sellout opened this issue 9 years ago • 7 comments

We use -Ywarn-unused-import (and -Xfatal-warnings), and get

Unused import
import acyclic.file

on any file I add it to.

I don’t know of any way to silence an unused import warning (e.g., using @SuppressWarnings), but I’d happily do that if possible.

sellout avatar Aug 31 '16 19:08 sellout

@sellout maybe this plugin can help? https://github.com/ghik/silencer (disclaimer: haven't used it myself)

rintcius avatar May 12 '17 09:05 rintcius

One solution would be to make the acyclic plugin remove that import when it sees it. If anyone wants to send a PR doing so, I'll gladly merge it

lihaoyi avatar May 12 '17 15:05 lihaoyi

Or you could use -P:acyclic:force which would remove the need for those imports in the first place, assuming your entire codebase is already compliant

lihaoyi avatar May 20 '17 16:05 lihaoyi

Yeah, our codebase is far from compliant. We’ll need to add the import one file at a time.

sellout avatar May 20 '17 19:05 sellout

If the acyclic imports defined some def workaroundUnusedImportWarning: Unit = () then would that solve the problem? File level imports could then

import acyclic.file

object MyClass {
  file.workaroundUnusedImportWarning

Daenyth avatar Apr 16 '20 15:04 Daenyth

Adding -P:acyclic:force doesn't help if you want to prevent package level cycles (an awesome feature by the way).

Silencer is fine for handling this, but I'm curious for why you didn't use annotations instead of an import? That feels like it would read better and be less surprising.

EDIT: annotations were a stupid idea. I see now why you did it this way. You can't put annotations on a package.

caoilte avatar Apr 22 '20 11:04 caoilte

If anyone still needs this, you can silence (that is what the s at the end stands for) these warnings with the newish Wconf compiler option:

-Wconf:cat=unused-imports&origin=acyclic\.skipped:s

cornerman avatar Jan 09 '24 20:01 cornerman