Git Product home page Git Product logo

scalaclean's Introduction

ScalaClean

Build Status

Join the chat at https://gitter.im/rorygraves/ScalaClean

ScalaClean is a full program static analysis tool. By looking at the entire program as a single entity we can do an in-depth analysis that is not available when working file by file as most current static analysis tools do.

Current Status

Runnable, but probably will do something bad ;). See the instructions below if you want to give it a try.

Ideas

  • Dead code detection removal
  • adjust method/class/package visibility to minimum
  • find and remove unused parameters (e.g. overriding method but parameter is not used anywhere)
  • Many more

TODO List

  • Run it on more things an fix the bugs

Running against an external project

We don't currently have a full sbt plugin or publish artifacts so you will need to do some of the legwork yourself.

1. Clone the repo

2. Build the compiler plugin

sbt analysisPlugin/assembly

This will create a jar for the compiler plugin.

You will need to find the full path for the file e.g.

/workspace/ScalaClean/analysisPlugin/target/scala-2.12/analysisPlugin_2.12.10-0.1.0-SNAPSHOT-assembly.jar

3. Update your build to pull in semanticDB and the ScalaClean plugin.

Manually add the ScalaClean plugin to your project definition(s) - this will be automated later:

.settings(
  addCompilerPlugin("org.scalameta" % "semanticdb-scalac" % "4.3.0" cross CrossVersion.full),
  scalacOptions ++= {
    val srcLocations = (sourceDirectories in Compile).value.mkString(java.io.File.pathSeparator)
    Seq(
      "-Yrangepos", // from semanticdb instructions
      "-Xplugin:/workspace/ScalaClean/analysisPlugin/target/scala-2.12/analysisPlugin_2.12.10-0.1.0-SNAPSHOT-assembly.jar",
      s"-P:scalaclean-analysis-plugin:srcdirs:${srcLocations}",
    )
  },
)

4. Now build your project

All being well you should now have a number of files in your META-INF directory:

E.g. for akka-actor in /akka-actor/target/classes/META-INF/ I have:

./akka-actor/target/classes/META-INF//semanticdb
./akka-actor/target/classes/META-INF//semanticdb/akka-actor/...lots of semanticdb files
./akka-actor/target/classes/META-INF//ScalaClean
./akka-actor/target/classes/META-INF//ScalaClean/scalaclean-relationships.csv
./akka-actor/target/classes/META-INF//ScalaClean/ScalaClean.properties
./akka-actor/target/classes/META-INF//ScalaClean/scalaclean-elements.csv

5. Build the ScalaClean main:

In ScalaClean sbt command/assembly

Creates: /workspace/ScalaClean/command/target/scala-2.12/command-assembly-0.1.0-SNAPSHOT.jar (your location may vary)

Now you can run ScalaClean using this jar. Point ScalaClean at your projects ScalaClean.properties files e.g.:

java -jar $SCALACLEAN_JAR deadcode `find myproject -name "ScalaClean.properties"

By default it will print out the diff that it computes. To apply the changes directly add --replace to the command before the list of files. BEWARE - This is destructive - do not run it on code you care about that you do not already.

6. Report the bugs

Look at the output, determine if the output does not meet your expectations (one of the steps failed or the result is broken wrong) then drop us a bug report - we would love to hear about it. If you are feeling especially kind a bit of investigation and a sample project (see testProjects/deadCodeXXX for examples that we are using for testing. )

Useful links

Setup instructions

Open in Intellij - not all tests are passing at this point

scalaclean's People

Contributors

mkeskells avatar rorygraves avatar dwijnand avatar danielasfregola avatar msumner91 avatar gg1680 avatar gitter-badger avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.