Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    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?
    James Hughes
    @jnh5y
    I'm interested in writing my own Wart to try and detect a code issue that I'm trying to identify across a codebase. (The goal is to identify when lazy val blocks may misbehave)
    As I'm trying to figure out the project, I tried to run a unit test in IntelliJ with the debugger and none of the breakpoints got hit, etc.
    Is there a way to use a debugger while getting started writing a Wart? (I think that it'd make it easier for me to figure out the Scala Universes, etc)
    James Hughes
    @jnh5y
    To answer my own question, one can add the JVM debugger options to the Scala compiler in IntelliJ. One then just has to ask IntelliJ to recompile a class at the same time that debugger is pointed at the Scala Language Server
    that's a little rough, but manageable
    Marcin Szałomski
    @baldram

    Hi All, I know Wartremover uses Scala compiler's built-in warning system. Do you know whether there is any SBT plugin or any other possibility to generate the XML or HTML report from the analysis?

    That would be something similar to what Scapegoat offers, but it includes only this linter related inspections in the report. I want to find a way to collect the default and Wartremover's warnings.

    Is there any SBT plugin making it possible? Do you have any other idea?

    urbanchr
    @urbanchr

    Hi
    I am trying to disable the Var, Return and MutableDataStructures warts. This works fine with something like

    wartremover -traverser org.wartremover.warts.Return -traverser org.wartremover.warts.Var -traverser org.wartremover.warts.MutableDataStructures file.scala

    The problem is that wartremover complains about the code

    Using(Source.fromFile(name))

    which has nothing to do with the warts above. "Plain" Scala would accept this code (wart remover complains that the value Using is not found). Is this because Using was introduced in Scala 2.13, but wart remover seems to be only tested with Scala 2.12? Thanks!

    vinhhv
    @vinhhv
    Hi, I’m trying to use wartremoverExcluded += sourceManaged.value, but it still fails to exclude generated files from ScalaPB. Is there anything I’m missing? That exclusion line is all that is included in the documentation.
    Henri Cook
    @henricook
    Hi all, we're looking for something to save us review time saying "please add a return type to your public def" - I realise it's like 1% of the power of wartremover but would it be a good for this? Or should I be looking into something like scalastyle?
    Ruixi Fan
    @rfan-debug
    Hey, I am trying to use the wartremover with scala-"2.11.11". However, it seems that the maven central does not have such artifactory. Is there any workaround?
    Kapil Sanghvi
    @kapil53
    Hi all, I am using the wart remover plugin with gradle as build tool and wondering whether there is a way to highlight the errors/warnings from wart remover when there is any, since I could see the warnings and errors in the following format [wartremover:TraversableOps] head is disabled - use headOption instead and doesn't suggest whether it's an error or warning
    Kapil Sanghvi
    @kapil53
    @rfan-debug I followed the setup instructions from here https://plugins.gradle.org/plugin/cz.augi.gradle.wartremover with scala v2.11.11 and it works for me
    Ruixi Fan
    @rfan-debug
    @kapil53 Sorry for my ambiguous description before. I am using sbt instead of gradle. I tried both addCompilerPlugin and addSbtPlugin. Neither of this worked for me on Scala 2.11.11
    Kapil Sanghvi
    @kapil53
    @rfan-debug no worries, I tried using wart remover v2.3.7 with sbt 0.13.8 and scala 2.11.11..works fine for me (refer this https://github.com/wartremover/wartremover/blob/da1e629e3367c0ec/docs/_posts/2017-02-11-install-setup.md)
    Ólafur Páll Geirsson
    @olafurpg
    @henricook FWIW, there exists a Scalafix ExplicitResultTypes that automatically inserts the inferred type annotations on public members https://scalacenter.github.io/scalafix/docs/rules/ExplicitResultTypes.html I use it in several of my projects and it's worked pretty well in my experience
    Ruixi Fan
    @rfan-debug
    @rfan-debug no worries, I tried using wart remover v2.3.7 with sbt 0.13.8 and scala 2.11.11..works fine for me (refer this https://github.com/wartremover/wartremover/blob/da1e629e3367c0ec/docs/_posts/2017-02-11-install-setup.md)
    Thank you! that's really helpful!
    Francois Armand
    @fanf
    hello people! I would like to find bad use of toString and StringPlusAny with wartremover. It works well, but we use a lot of integer/long/etc for metrics log, I get tons (several hundreds) of warning, which make it almost unusable. I would like to know if there is a way to tell wartremover "except integer"?