by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Nicolas Rinaudo
    @nrinaudo
    oh, sure, that's not what I'm arguing. I'm saying that it feels like the wrong wart is triggered
    Greg Pfeil
    @sellout
    Ah, I see.
    So, there’s another wart to catch use of toString.
    Nicolas Rinaudo
    @nrinaudo
    yeah. ToString
    If that were triggered by string interpolation, I'd get it. But StringPlusAny feels confusing for newcomers - it's another of these failures where the root cause is hidden
    and... does it mean that you basically do not use string interpolation, by the way?
    Greg Pfeil
    @sellout
    Yeah, I don’t. Not for any good reason. But I wonder if there was a change in Scala 2.13 to have interpolation expand to + foo + instead of + foo.toString +? It seems like that would be a simplification that could prevent diverging semantics – i.e., it means that interpolation and concatenation both have the same conversion semantics, rather that having interpolation do its own string conversion, which could get out of sync with that for concatenation. Since both are currently defined to use .toString, it wouldn’t change behavior, but could change how it’s seen by WartRemover.
    Nicolas Rinaudo
    @nrinaudo
    I believe that's the case, yes
    @som-snytt @nrinaudo string interpolator converts to string + now.
    If you didn't like string interpolation before, you won't ike string_+ either. It's all stringifications.
    Greg Pfeil
    @sellout
    I think this is a case where those two warts should be a single thing like ImplicitStringConversion. Having each wart catch one low-level pattern makes these things a bit more fragile, where an “invisible” change becomes exposed.
    I use Warts.AllBut(Any, Nothing) – but I guess most people probably want something more fine-grained than that 😆
    som-snytt
    @som-snytt
    In the spirit of TMI, they wanted to make s-interpolator more efficient, so instead of a loop calling stringbuilder.append, you get a "" + arg expression that the platform can optimize. Maybe StringBuilder.append(Object) is the missing wart.
    Warts.andAll.
    If you use Warts.andAll, your code still passes the build even if it's really ugly.
    Nicolas Rinaudo
    @nrinaudo
    But I like string interpolation:(
    Greg Pfeil
    @sellout
    @nrinaudo You can still use string interpolation – just "some ${foo.show} string".
    som-snytt
    @som-snytt
    Is it worth adding that you can have a show interpolation that takes implicits? You can call it s"" for show.
    Greg Pfeil
    @sellout
    Oh, right! That’s a thing that exists already. I actually don’t use Show, either – just explicit functions that result in a String. But yeah, that’s definitely a useful thing to remember that would also silence the wart.
    udalrich
    @udalrich
    It seems difficult to use MutableList with Warts.unsafe. val list:MutableList[Integer] = MutableList(); list += 4 fails to compile, as list += 4 does not return unit. I haven't tried, but I suspect var list = List[Integer](); list = list + 4 would fail the Var wart
    ritschwumm
    @ritschwumm
    @udalrich Warts.unsafe and MutableList sound like a weird combination - like making absolutely sure there's not a single knife in the house to so the kids won't ever hurt themselves, and then buying them a chainsaw as a birthday present...
    udalrich
    @udalrich
    It seemed like Wars.unsafe was a recommended/good if you can get there setting. My use case is this. I have a bunch of objects from a 3rd party library. I need to remember which ones I have done a particular action with, and I can't query the object to find out if I did it. So I have code like def doStuff(x: Thing) = { x.doThing(); list.add(x) } so that list holds the Things I have operated on. How would I write that with Warts.unsafe?
    udalrich
    @udalrich

    I had code that did

    if (list.isEmpty) {
      stuff(list.head, list.tail)
    } else {
      otherStuff()
    }

    Warts.TraversibleOpts told me to use headOption instead. Warts.OptionPartial won't like

    list.headOption.ifPresent(stuff(_, list.tail)).orElse(() => otherStuff()).get

    but I don't see another way to do it. getOrElse(otherStuff()) is wrong, because calling otherStuff is wrong if the list is not empty.

    I suspect the problem is that Option should have a getOrElse that takes a function to build the result, not just getOrElse(T). Is there another way to do this?

    ritschwumm
    @ritschwumm
    @udalrich how about this?
    list match {
      case Nil    => otherStuff()
      case h :: t => stuff(head, tail)
    }
    and btw getOrElse does take a function under the hood: the type of its parameter is =>T and not T, so the parameter will not be evaluated in the nonEmpty case
    udalrich
    @udalrich
    That would work. I'm new enough to scala that writing getOrElse(otherStuff()) looks like it should always call otherStuff.
    Stefan E. Mayer
    @stefanerwinmayer
    Hello, Is there a way to make wartremover work with bloop?
    David Roon
    @adridadou
    hi everyone! I have a question. I’m trying to use the rule NonUnitStatement but I have an issue with parboiled rules
    it seems that it sees every rule as a NonUnitStatement
    is there a way how to solve that ?
    David Roon
    @adridadou
    looks like the issue is that because parboiled is using macros, the code seems wrong but isn’t
    David Roon
    @adridadou
    I have now another issue that I find interesting. It seems like in Scala 2.13, Seq[T] extends JavaSerializable so it triggers the javaSerializable error
    works fine in scala 2.12
    Andrey Ivanov
    @a-nigredo
    Hi all, is it possible for SuppresWarning with custom wart?
    I'm using last version of wartremover
    nigredo-tori
    @nigredo-tori
    @a-nigredo, the warts handle SuppressWarnings themselves. So your wart has to support that.
    Andrey Ivanov
    @a-nigredo
    @nigredo-tori thanks
    Dmitrii Kostianoi
    @DStranger

    Hi guys, I have a question, although it might be more of an sbt-in-general type of question, but anyway.
    I have a multi-project build for which I'd like to enable wartremover in one place.
    I'd like to use something like the following, but it doesn't seem to work.

    ThisBuild / Compile / wartremoverErrors := Warts.all
    ThisBuild / Test / wartremoverErrors := Seq.empty

    I can use the common settings approach, but there must be a better solution.

    nigredo-tori
    @nigredo-tori
    @DStranger, please run inspect foo/Compile/wartremoverErrors in your SBT console (replacing foo with your project identifier), and post the result here.
    Andrey Bobylev
    @x0ji0d
    Hi
    trying to install wartremover, added to plugins.sbt
    addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.3")
    and
    wartremoverErrors ++= Warts.unsafe to build.sbt
    sbt compile produces errors like
    [error] bad option: -P:wartremover:traverser:org.wartremover.warts.Any
    [error] bad option: -P:wartremover:traverser:org.wartremover.warts.AsInstanceOf
    Andrey Bobylev
    @x0ji0d
    ah, the problem was that I used libraryDependencies := instead of ++=
    sahil anand
    @anandsahil
    Hi, I would like to ask something I have a wart remover for throws andn code like this
    val errorHandler: PartialFunction[Throwable, F[T]]
    try {.....} catch errorHandler
    The wart still says throws are disbaled and compilation fails. Why is that ?
    Eugene Wolfson
    @yegeniy
    Hi, why is this an issue with nonUnitStatement:
     [wartremover:NonUnitStatements] Statements must return Unit
    [error]     alist(arr).map { case k =>
    [error]                    ^
    [error] one error found
    object WeightedShuffle {
      private def swap[T](arr: Array[T], a: Int, b: Int): Unit = {
        val t = arr(a)
        arr(a) = arr(b)
        arr(b) = t
      }
    
      def shuffle[T: ClassTag](wpts: Seq[T], getWeight: T => Double): Seq[T] = {
        val eps = 1e-6
        val rnd = Random
        val arr = wpts.toArray
        (0 to arr.length - 1).map { k =>
          val weights = arr.view.slice(0, arr.length - k).map(getWeight(_) + eps)
          val totalWt = weights.sum
          val rWt = rnd.nextDouble * totalWt
          val cWt = weights.scan(0d)(_ + _) // cumulative sum
          val tgt = cWt.indexWhere(_ > rWt) - 1
          swap(arr, tgt, arr.length - k - 1)
        }
        arr.reverse
      }
    }
    Eugene Wolfson
    @yegeniy
    I realize that the workaround is to do val _ = (0 to arr.length - 1).map { k =>, but not sure whether wartremover is suggesting there is an actual fix or something?
    nigredo-tori
    @nigredo-tori
    @yegeniy, map returns some kind of Seq[Unit], which you don't use - that's what the wart catches. If you don't need the return value here (that is, you just want side effects), just use foreach instead of map. More generally, side-effects in map are an antipattern.
    Eugene Wolfson
    @yegeniy
    Thank you. That makes sense. A colleague actually told me the same thing this morning!
    bjenkinsgit
    @bjenkinsgit
    Added addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.5") to a brand new, simple project and immediately get org.wartremover#sbt-wartremover;2.4.5: not found when launching sbt. Is there a specific repository I need to point to?
    nigredo-tori
    @nigredo-tori
    @bjenkinsgit, what SBT version are you using? Starting from 2.4.0, sbt-wartremover is only available for SBT 1.x.
    bjenkinsgit
    @bjenkinsgit
    @nigredo-tori Yep. Updated to 1.3.8. Now just have to find a version of cats that works. Thanks
    Mostafa Mahmoud
    @moustafaalaa

    Hi,

    I have a question If I need to add some custom rules for project build for example

    • If the number of tests less than 2 let the build fail.
    • If there is any "println" or some special commands.

    I don't have any experience with wartremover library, But How can we use it for this purpose?

    Diego Bernardes
    @diegobernardes
    It's possible to disable WartRemover not on a file, but at class that a given file is using? Actually the tool is complaining about the shouldEqual from ScalaTest with this rule: [wartremover:NonUnitStatements] Statements must return Unit.
    I don't want to disable this rule on the whole file or even on the tests because it's useful, I just want to disable it for all ScalaTest things. Is it possible?