Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Andrey Ivanov
    @a-nigredo
    I'm using last version of wartremover
    Dmitry Polienko
    @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.

    Dmitry Polienko
    @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?
    Dmitry Polienko
    @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?
    Dmitry Polienko
    @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"?
    Stacy Curl
    @stacycurl
    Is it possible to define a custom wart locally to a project, maybe in a ‘project project’, or on plugins.sbt ?
    Alternatively is there an existing wart that’s parameterizable ? I don’t see why it’s necessary to define a new wart for every method I want to forbid.
    Stacy Curl
    @stacycurl
    wartremoverWarnings += Wart.custom(“InvocationNotAllowed(SomeClass, someMethod)”)
    Stacy Curl
    @stacycurl
    I found an answer to my first question: wartremover.WartRemover.dependsOnLocalProjectWarts(myWarts)
    Sven Ludwig
    @iosven
    @fanf I have the same experience.
    Ashesh Singh
    @user501254

    Hi, I am having a hard time trying to exclude files. As per the docs, I can use wartremoverExcluded.
    However this doesn't work:

    lazy val wartremoverSettings = Seq(
      wartremoverWarnings in (Compile, compile) ++= Warts.allBut(Wart.Throw),
      wartremoverExcluded ++= Seq(
        sourceManaged.value,
        baseDirectory.value / "common" / "src" / "main" / "scala" / "com" / "tango" / "charlie" / "clients" / "Github.scala"
      )
    )

    Any pointer would help, Thank you.

    shota jolbordi
    @shotexa

    Hi folks, I’m having issues with wartRemover working in vsCode / metals. It does work normally when I compile, but, when metals compiles it via bloop, I get this errors in metals.log:

    ERROR bad option: -P:wartremover:only-warn-traverser:org.wartremover.warts.Any

    sbt 1.4.4
    scala 2.13.4

    I’ve added

    addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.13”)

    in project/plugins.sbt
    and

    ThisBuild / wartremoverErrors ++= Warts.unsafe

    in build.sbt

    shota jolbordi
    @shotexa
    I’ve tried everything and then I’ve just restarted my mac and it fixed...
    Henri Cook
    @henricook
    Hi everyone. Relatively new wart remover user here. I notice when trying to enable the Equals wart that it also warns on Strings. Can I stop wart remover warning about String comparisons or is this an opinionated thing? i.e. Wartremover is implying I should wrap all my Strings in other types
    Dmitry Polienko
    @nigredo-tori
    @henricook, as I understand it, Equals is intended to be used with libraries that provide type-safe alternatives to ==. For example, Cats provides === and =!= operators for types that have an Eq typeclass instance.
    Henri Cook
    @henricook
    Thanks nigredo-tori - and I'm a user of cats, but I don't even Cats has something for comparing strings.. I can't use === for them for example
    Dmitry Polienko
    @nigredo-tori
    @henricook, you might be missing import cats.implicits._.
    Henri Cook
    @henricook
    Oh wow you've blown my mind, I didn't know cats had that - thanks!
    vonchav
    @voonchav_gitlab
    Hi @shotexa , does wartremover 2.4.13 work with Scala 2.13.4 for you? When I tried it, it doesn't seem wartremover isn't available for 2.13.4.
    I can see 2.13.4 has been added to github repo but there hasn't been a new release for that change. Just wondering how you got it working.
    Dmitry Polienko
    @nigredo-tori
    @voonchav_gitlab, there is a WR 2.4.13 artifact for Scala 2.13.4: https://mvnrepository.com/artifact/org.wartremover/wartremover
    1 reply
    shota jolbordi
    @shotexa
    @voonchav_gitlab yeah it does actually
    1 reply