Skip to content
Scala.meta based codacy engine for scala static code analysis
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add issue template Aug 20, 2016
common/src/main/scala/codacy Update to Scala 2.12 Aug 3, 2018
core Use 4.0.0 released version Sep 24, 2018
genResources/src/main/scala/codacy Update to Scala 2.12 Aug 3, 2018
macros/src/main/scala/codacy/macros Update to Scala 2.12 Aug 3, 2018
patterns-base/src/main
project Fix sbt resource packaging Aug 13, 2018
src/main Update scalameta Aug 4, 2018
.gitignore
README.md Add Codacy info Oct 7, 2016
build.sbt
circle.yml Update tests to new version Sep 24, 2018

README.md

Codacy Badge Build Status

Codacy scala.meta

This is the codacy engine for scala static code analysis build on top of scala.meta. Check the Docs section for more information.

Developing

implementing a new Pattern:

It is usually a good idea to start by implementing the test file. It contains issues the new pattern should detect as well as implementations that correct said issues. This defines the constraints of what the pattern should and also should not detect and helps avoid false positives. To create a testfile add it to the resources under docs/tests/ You can take a look at the already implemented tests in our base plugin

Next we implement the actual code. A pattern must currently reside in the package codacy.patterns and implement the codacy.base.Pattern interface. Which means it must implement the def apply(tree:Tree):Iterable[Result]. In most cases the collect method on trees that scala.meta provides us with is sufficient for that purpose. A Result consist of a Message (which itself is just a type-wrapped String) and a Positionable which can currently be implicitly obtained by passing a scala.meta.Tree or a scala.meta.Token

Sometimes one might want to change the behavior of the pattern according to some configuration. Such a configuration has to follow some basic rules and gets passed to the pattern as the only argument in the constructor. The rules are:

  1. it needs to be a case class

  2. all arguments need to define defaults

  3. json readers and writers must exist for the argument types. (Currently that means primitive types and scala.util.matching.Regex)

Additional steps can be found in the chapter Tool Integration with one exeption: there is no need to explicitly add pattern parameters to patterns defined in patterns.json since that's already being covered by rule 2 of the configuration rules. For a full example check out the existing patterns

Quasiquotes:

https://github.com/scalameta/scalameta/blob/master/notes/quasiquotes.md

Tool Integration:

https://support.codacy.com/hc/en-us/articles/207994725-Tool-Developer-Guide

Testing with "sbt console":

import scala.meta._

val code = """ .... """

val tree = code.parse[Source]

codacy.patterns.Custom_Scala_ElseIf(tree)

//To see the tree structure:

tree.show[Structure]

Usage

You can create the docker by doing:

sbt docker:publishLocal

The docker is ran with the following command:

docker run -it -v $srcDir:/src  <DOCKER_NAME>:<DOCKER_VERSION>

Docs

Tool Developer Guide

Tool Developer Guide - Using Scala

Test

We use the codacy-plugins-test to test our external tools integration. You can follow the instructions there to make sure your tool is working as expected.

What is Codacy?

Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.

Among Codacy’s features:

  • Identify new Static Analysis issues
  • Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
  • Auto-comments on Commits and Pull Requests
  • Integrations with Slack, HipChat, Jira, YouTrack
  • Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.

You can’t perform that action at this time.