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

Unused import #105

Open
MasseGuillaume opened this Issue Jun 6, 2016 · 12 comments

Comments

Projects
None yet
@MasseGuillaume
Copy link

MasseGuillaume commented Jun 6, 2016

I have "-Xfatal-warnings", "-Ywarn-unused-import", in my scalacOptions

I cannot use twirl

import play.twirl.api._
import play.twirl.api.TemplateMagic._

class error extends BaseScalaTemplate[play.twirl.api.HtmlFormat.Appendable,Format[play.twirl.api.HtmlFormat.Appendable]](play.twirl.api$
@kusamakura

This comment has been minimized.

Copy link

kusamakura commented Jun 29, 2016

One workaround I did was to add a dummy line somewhere that uses both imports:
@if(List.empty[Txt]){}

(Uses play.twirl.api.Txt and play.twirl.api.TemplateMagic.iterableToBoolean)

@Pyppe

This comment has been minimized.

Copy link

Pyppe commented Nov 1, 2016

Any chance for this to get fixed? Or maybe a pointer (for a person such as myself who hasn't worked with sbt plugins) where to look at in order to get this fixed?

@schmitch

This comment has been minimized.

Copy link
Member

schmitch commented Nov 1, 2016

You can set TwirlKeys.templateImports := Seq() which will actually remove all the imports. However you should re add the necessary onces.

@bfil

This comment has been minimized.

Copy link

bfil commented Jan 14, 2017

Customizing the templateImports doesn't really fix the issue when you have different templates needing different imports. Unless I'm missing something?

@marcospereira

This comment has been minimized.

Copy link
Member

marcospereira commented Jan 16, 2017

@bfil if you set the value of TwirlKeys.templateImportsto an empty Seq like @schmitch suggested, then it will solve the issue, since no imports will be automatically added to the views. You can then re-add the necessary imports to each view.

@bfil

This comment has been minimized.

Copy link

bfil commented Jan 16, 2017

I was thinking: if I have template1.scala.html using @Html and template2.scala.html using @Txt, then If I add both to the SBT settings template1 will say unused import on Txt and template2 will say unused import on Html, cause it's a global setting.

I guess the suggestion is removing them all from the SBT settings and adding the import line within the templates themselves.

@TBonnin TBonnin referenced this issue Apr 5, 2017

Merged

Import cleanup #16368

digital-wonderland added a commit to digital-wonderland/play-webpack-typescript-react that referenced this issue Oct 25, 2017

bump scala to 2.12.4
This requires the default Twirl imports to be disabled because of
the unused import check.

See
scala/bug#10270
and
playframework/twirl#105
@steinybot

This comment has been minimized.

Copy link

steinybot commented Mar 27, 2018

This is similar to playframework/playframework#7382 although far more painful to workaround.

@mckinley-olsen-oc

This comment has been minimized.

Copy link

mckinley-olsen-oc commented Jun 13, 2018

@marcospereira which import would I need to add in order to use the traditional syntax of routes.Assets.versioned("someFile.js")?
edit: got it figured out; no import, just need to refer directly to controllers.routes.Assets; there must be some magic going on I don't quite understand. Anyway, happy to be failing on warnings now

@iaco86

This comment has been minimized.

Copy link

iaco86 commented Oct 25, 2018

This becomes even more painful when using gradle - no workaround to be found there :(

@robinspollak

This comment has been minimized.

Copy link

robinspollak commented Dec 19, 2018

We are also experiencing this. Any chance of a fix?

@marcospereira

This comment has been minimized.

Copy link
Member

marcospereira commented Jan 3, 2019

here must be some magic going on I don't quite understand

@mckinley-olsen-oc there are some default imports made for all the templates. That is why you can use routes.Assets without writing an import by yourself.

@marcospereira

This comment has been minimized.

Copy link
Member

marcospereira commented Jan 3, 2019

We are also experiencing this. Any chance of a fix?

Hey @robinspollak not yet. Contributions would be very helpful here since this is not a priority right now. If you are using sbt, it should be possible to use silencer compiler plugin to filter code generated by twirl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.