Giter Site home page Giter Site logo

Comments (4)

martingd avatar martingd commented on June 2, 2024 1

@kubukoz

About final vals - #158

Thanks for the pointer. And it seems to do the trick also for annotation parameters.

As for the import, I also don't see why it'd be necessary unless someone disables the default imports.

I had a discussion about this issue on Discord and it seems the import is there for exactly for that reason: if somene uses Yno-imports or -Yno-predef. See commit e924a28

I am not sure why someone would do that and if we need to keep the import then the plugin will need to generate Scala 2/3 specific code.

from sbt-buildinfo.

armanbilge avatar armanbilge commented on June 2, 2024

I ran into this too. Here's my workaround:

// put this in project directory and use with:
// buildInfoRenderFactory := sbtbuildinfo.Scala3CaseObjectRenderer.apply

package sbtbuildinfo // couldn't access ScalaCaseObjectRenderer outside this pkg (?)

final case class Scala3CaseObjectRenderer(
    options: Seq[BuildInfoOption],
    pkg: String,
    obj: String)
    extends ScalaRenderer {
  private lazy val delegate = ScalaCaseObjectRenderer(options, pkg, obj)

  def extension: String = delegate.extension
  def fileType: BuildInfoType = delegate.fileType
  def renderKeys(infoKeysNameAndValues: Seq[BuildInfoResult]): Seq[String] =
    delegate.renderKeys(infoKeysNameAndValues).map {
      case "import scala.Predef._" => "import scala.Predef.*"
      case x => x
    }
}

from sbt-buildinfo.

martingd avatar martingd commented on June 2, 2024

@kubukoz and @eed3si9n, is that import of scala.Predef._ even necessary at all?

Removing it, the code still compiles with Scala 3, 2.12, 2.11, and 2.10.
(I haven't tried to compile with earlier Scala versions as it requires a JDK earlier then 1.8.)

So I would suggest getting rid of the import altogether and also (which is a different issue) change code generation so all vals are final and without a type annotation as the vals then can be used as constants in annotation parameters.

For example, instead of generating

val version: String = "1.5.0+2-44650e3c-SNAPSHOT"

we should generate this

final val version = "1.5.0+2-44650e3c-SNAPSHOT"

from sbt-buildinfo.

kubukoz avatar kubukoz commented on June 2, 2024

About final vals - #158

As for the import, I also don't see why it'd be necessary unless someone disables the default imports.

from sbt-buildinfo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.