pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/nativelibs4java/scalaxy-parano

thubassets.com/assets/primer-70be7debc79a8eff.css" /> GitHub - nativelibs4java/scalaxy-parano: Scalaxy/Parano: sanity checks for error-proof scala code · GitHub
Skip to content

nativelibs4java/scalaxy-parano

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central Build Status Join the chat at https://gitter.im/nativelibs4java/Scalaxy

Scalaxy/Parano

Extra compile-time checks that prevent some stupid mistakes (previously incubated at Scalaxy).

Can be used as a compiler plugin (preferred method), as a standalone compiler (scalaxy.parano.ParanoCompiler) or by calling a macro (scalaxy.parano.verify()).

Checks:

  • Confusing names in case class extractors
  • Ambiguous unnamed arguments with same type (e.g. Int parameters that could be inadvertently swapped)
  • Confusing names in method calls
  • (TODO) Potential side-effect free statements (e.g. missing + between multiline concatenations)
case class Foo(theFirst: Int, second: Int)

val foo = Foo(10, 12)                // Error: unnamed params theFirst and second have same type
                                     //        and are ambiguous.
val foo2 = Foo(10, second = 12)      // Fine.
val foo3 = Foo(theFirst = 10, 12)    // Fine.

val Foo(someFirst, someSecond) = foo // Fine.

val Foo(theSecond, first) = foo      // Error: theSecond used to extract Foo.theFirst,
                                     //        first used to extract Foo.second

val foo5 = Foo(theSecond, first)     // Error: ident theSecond used for param theFirst,
                                     //        ident first used for param second

Usage

If you're using sbt 0.13.0+, just put the following lines in build.sbt:

scalaVersion := "2.11.6"

autoCompilerPlugins := true

// Scalaxy/Parano plugin
addCompilerPlugin("com.nativelibs4java" %% "scalaxy-parano" % "0.4-SNAPSHOT")

// Ensure Scalaxy/Parano's plugin is used.
scalacOptions += "-Xplugin-require:scalaxy-parano"

// Scalaxy/Parano snapshots are published on the Sonatype repository.
resolvers += Resolver.sonatypeRepo("snapshots")

TODO

Ideas

  • Warn against non-lazy vals in traits

  • Add complete tests

  • Make an exception for natural progressions: x, y, z, a, b, c, d, i1, i2, i3... (they still need mismatching names check, but no ambiguity check)

  • Tuple return types in extractors: require an apply companion method with symmetric signature, take names from it and propagate accross matches:

    object MyExtractor {
      def apply(a: Int, b: Int) = ???
      def unapply(v: Any): Option[(Int, Int)] = v match {
        case ... =>
          val a = ...
          val b = ...
          (b, a) // Error: potential naming confusion (names of tuple are (a, b)).
      }
    }

Hacking

If you want to build / test / hack on this project:

  • Make sure to use paulp's sbt script with sbt 0.12.2+

  • Use the following commands to checkout the sources and build the tests continuously:

    git clone git://github.com/ochafik/Scalaxy.git
    cd Scalaxy
    sbt "project scalaxy-parano" "; clean ; ~test"
    
  • Test with:

    git clone git://github.com/ochafik/Scalaxy.git
    cd Scalaxy
    sbt "project scalaxy-parano" "run examples/Test.scala"
    
  • You can also use plain scalac directly, once Scalaxy/Parano's JAR is cached by sbt / Ivy:

    git clone git://github.com/ochafik/Scalaxy.git
    cd Scalaxy
    sbt update
    cd Parano
    scalac -Xplugin:$HOME/.ivy2/cache/com.nativelibs4java/scalaxy-parano_2.10/jars/scalaxy-parano_2.10-0.3-SNAPSHOT.jar examples/Test.scala
    scalac examples/Test.scala
    

About

Scalaxy/Parano: sanity checks for error-proof scala code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy