ghik / silencer

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

support supression of warnings on annotations #32

Closed fdietze closed 5 years ago

fdietze commented 5 years ago

I have this piece of code:

@js.native
@JSGlobal("$crisp")
object crisp extends js.Object {
  def push(options: js.Array[js.Any]): Unit = js.native
}

@JSGlobal is expecting a string literal. But the compiler raises the warning: possible missing interpolator. I was not able to suppress it using @silent.

ghik commented 5 years ago

Ok, I fixed the primary problem and in principle this warning could now be silenced like this:

@JSGlobal("$crisp": @silent)

but unfortunately ScalaJS compiler doesn't like it because "$crisp": @silent is not a string literal for it. Maybe it's worth opening an issue in ScalaJS.

ghik commented 5 years ago

Here's a workaround you can employ:

object JSNames {
  @silent("possible missing interpolator")
  final val Crisp = "$crisp"
}
@js.native
@JSGlobal(JSNames.Crisp)
object crisp extends js.Object
ghik commented 5 years ago

Ok, I'm closing this as the primary problem in silencer has been fixed and released in 1.4.2.

zakpatterson commented 5 years ago

I ran into a similar issue today @ghik using the latest release 1.4.3:

[warn] /home/projects/..../App.scala:9:10: discarded non-Unit value
[warn] @silent @react class App extends Component {
[warn]          ^
[warn] one warning found

Source of react annotation

If this looks like an issue to you, I'd be happy to work on a PR, although annotations and macros are my least understood part of scala. If you can point me to a range of lines though I'd love to work on it.

ghik commented 5 years ago

@zakpatterson It doesn't work because the suppression range in this case is the class itself, without its own annotations. Sure, this probably can be fixed by making @silent also apply to "neighbouring" annotations that come after it. File an issue if you want.

In the meantime, please also check if this works: @(react@silent)

zakpatterson commented 5 years ago

Thanks for that @ghik , I gave that a try, but the @react macro annotation generates a companion object for App in my example, which doesn't get generated, or is not accessible, given your suggested annotation.

I can open a new issue, or we can just broaden the scope of this #32. It seems very similar.