Scala Abide: A lint tool for Scala

of 23 /23
Scala Iulian Dragos

Embed Size (px)

Transcript of Scala Abide: A lint tool for Scala

  • Scala

    Iulian Dragos

  • Overview

    Static checker tool

    Based on type-checked ASTs

    Easy to use and write rules

  • Goals

    Unify existing approaches in one platform

    Easy to write rules

    Easy to use other peoples rules

    Reasonable performance

    Good integrations

  • Abide

    Rules are decoupled from the tool

    rule packages

    project-specific rules

    Integrates with Sbt

    planned: Maven, Eclipse

  • Examples Core package

    Unused members

    Vars that are never re-assigned

    Renamed arguments with defaults


    sender method called inside future

  • Architecture




    core rules

    extra rules


    . . .

  • Use

    addSbtPlugin("com.typesafe" % "sbt-abide" % "0.1.0")

    libraryDependencies += "com.typesafe" %% "abide-core" % 0.1.0 % "abide"

    libraryDependencies += "com.typesafe" %% "abide-extra" % 0.1.0 % "abide"

    Project(...).dependsOn(rules % "abide")

  • Anatomy

  • Traversers

    Fused: one-pass for all rules

    Optimised: rules are filtered on what they match

  • Directives

    Shared context between rules

    compiler universe

    user-defined mix-ins

  • Rules

    val step = { case varDef @ q"$mods var $name : $tpt = $value" => nok(varDef.symbol, Warning(varDef)) case q"$rcv = $expr" => ok(rcv.symbol) }


    state helpers

    Replace `var` with `val`

  • Rules

    partial function Tree => Unit

    collect keys that can do one transition

    nok (not ok)

    ok (stable state)

  • Rules existential rules (what weve seen)

    scoping rules

    helpers to maintain nesting

    enter (no need for removing, handled by the library)

    path rules

    like scoping, but richer state checks

  • Coding a rule

  • For example..

  • Mutation inside iteration

    Lets forbid mutating the underlying collection while iterating

    for (x xs -= x }

    ys foreach { case (k, v) => ys remove 1 }

    for (p

  • Simplifying assumptions

    purely syntactical matching (no points-to analysis)


    xs map { x => xs -= x }

  • Lets code

  • Future

  • Next

    SupressWarning support

    Integrations: maven and IDEs

    More rules

  • Contribute!

    The value is in rules

    Contribute to scala/scala-abide

    ..or write your own rule package

  • Acknowledgements

    Nicolas Voirol (@samarion) did all the work during his internship at Typesafe Switzerland

  • Thank you