Framework to help integration with external analysis tools at Codacy. These tools provide the issues you can see on Codacy after an analysis is completed.
For more details and examples of tools that use this project, you can check:
Add to your SBT dependencies:
"com.codacy" %% "codacy-engine-scala-seed" % "<VERSION>"
To run the tool we provide the configuration file, /.codacyrc
, with the language to run and optional parameters a tool might need.
The source code to be analysed will be located in /src
, meaning that when provided in the configuration, the file paths are relative to /src
.
Structure of the .codacyrc file:
/src
){
"files" : ["foo/bar/baz.js", "foo2/bar/baz.php"],
"tools":[
{
"name":"jshint",
"patterns":[
{
"patternId":"latedef",
"parameters":[
{
"name":"latedef",
"value":"vars"
}
]
}
]
}
]
}
Regarding the configuration file, the tool should have different behaviours for the following situations:
/.codacyrc
exists and has files and patterns, use them to run./.codacyrc
exists and only has patterns and no files, use the patterns to invoke the tool for all files from /src
(files should be searched recursively for all folders in /src)./.codacyrc
exists and has only files and no patterns, run only for those files and look
for the tool's native configuration file, if the tool supports it./.codacyrc
does not exist or any of its contents (files or patterns) is not available,
you should invoke the tool for all files from /src (files should be searched recursively for all folders in /src)
and check them with the tool's native configuration file, if it is supported and if it exists. Otherwise, run the tool with the default patterns./.codacyrc
fails to be parsed, throw an error.Exit codes
Notes:
DEBUG
to true
when invoking the docker.TIMEOUT
when invoking the docker, setting it with values like 10 seconds
, 30 minutes
or 2 hours
.Write the docker file that will run the tool.
sbt docker:publishLocal
that generates the dockerfile automatically and publishes the docker locally.Write a patterns.json with the configuration of your tool.
{
"name":"jshint",
"version": "1.2.3",
"patterns":[
{
"patternId": "latedef",
"category": "ErrorProne",
"parameters": [
{
"name": "latedef",
"default": "nofunc"
}
],
"level": "Warning"
}
]
}
For level types we have:
For category types we have:
Write the code to run the tool You don't have to use this seed and you can write the code in any language you want but, you have to invoke the tool according to the configuration. After you have your results from the tool, you should print them to the standard output in our Result format, one result per line.
{
"filename":"codacy/core/test.js",
"message":"found this in your code",
"patternId":"latedef",
"line":2
}
{
"filename":"codacy/core/test.js",
"message":"could not parse the file"
}
At Codacy we strive to provide the best value to our users and, to accomplish that, we document our patterns so that the user can better understand the problem and fix it.
At this point, your tool has everything it needs to run, but there is one other really important thing that you should do before submitting your docker: the documentation for your tool.
Your files for this section should be placed in /docs/description/.
In order to provide more details you can create:
In the description.json you define the title for the pattern, brief description, time to fix (in minutes), and also a description of the parameters in the following format:
[
{
"patternId": "latedef",
"title": "Enforce variable def before use",
"description": "Prohibits the use of a variable before it was defined.",
"parameters": [
{
"name": "latedef",
"description": "Declaration order verification. Check all [true] | Do not check functions [nofunc]"
}
],
"timeToFix": 10
}
]
To give a more detailed explanation about the issue, you should define the
Fields in interfaces are automatically public static final, and methods are public abstract.
Classes or interfaces nested in an interface are automatically public and static (all nested interfaces are automatically static).
For historical reasons, modifiers which are implied by the context are accepted by the compiler, but are superfluous.
Ex:
public interface Foo {
public abstract void bar(); // both abstract and public are ignored by the compiler
public static final int X = 0; // public, static, and final all ignored
public static class Bar {} // public, static ignored
public static interface Baz {} // ditto
void foo(); //this is correct
}
public class Bar {
public static interface Baz {} // static ignored
}
[Source](http://pmd.sourceforge.net/pmd-5.3.2/pmd-java/rules/java/unusedcode.html#UnusedModifier)
You should explain the what and why of the issue. Adding an example is always a nice way to help other people understand the problem. For a more thorough explanation you can also add a link at the end referring a more complete source.
Follow the instructions at codacy-plugins-test.
Running the docker
docker run -t \
--net=none \
--privileged=false \
--cap-drop=ALL \
--user=docker \
--rm=true \
-v <PATH-TO-FOLDER-WITH-FILES-TO-CHECK>:/src:ro \
<YOUR-DOCKER-NAME>:<YOUR-DOCKER-VERSION>
Docker restrictions
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.
Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.
Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.
Codacy is free for Open Source projects.