Skip to content

Commit

Permalink
Add support for CodeClimate.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 11, 2024
1 parent 6ef5e52 commit 1ac336c
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package edu.hm.hafner.analysis.parser.violations;

import se.bjurr.violations.lib.parsers.CodeClimateParser;

/**
* Parses CodeClimate JSON files.
*
* @author Ullrich Hafner
*/
public class CodeClimateAdapter extends AbstractViolationAdapter {
private static final long serialVersionUID = 673249539417291948L;

@Override
CodeClimateParser createParser() {
return new CodeClimateParser();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.hm.hafner.analysis.registry;

import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.parser.violations.CodeClimateAdapter;

/**
* A descriptor for the Code Climate parser.
*
*/
class CodeClimateDescriptor extends ParserDescriptor {
private static final String ID = "code-climate";
private static final String NAME = "Code Climate";

CodeClimateDescriptor() {
super(ID, NAME);
}

@Override
public IssueParser createParser(final Option... options) {
return new CodeClimateAdapter();
}

@Override
public String getUrl() {
return "https://codeclimate.com/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ParserRegistry {
new CmakeDescriptor(),
new CodeAnalysisDescriptor(),
new CodeCheckerDescriptor(),
new CodeClimateDescriptor(),
new CodeGeneratorDescriptor(),
new CodeNarcDescriptor(),
new CoolfluxChessccDescriptor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package edu.hm.hafner.analysis.parser.violations;

import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.assertions.SoftAssertions;
import edu.hm.hafner.analysis.registry.AbstractParserTest;

/**
* Tests the class {@link CodeNarcAdapter}.
*
* @author Ullrich Hafner
*/
class CodeClimateAdapterTest extends AbstractParserTest {
CodeClimateAdapterTest() {
super("code-climate.json");
}

@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
softly.assertThat(report).hasSize(2);
softly.assertThat(report.get(0))
.hasMessage("Avoid parameter lists longer than 5 parameters. [6/5]")
.hasFileName("argument_count.rb")
.hasType("Rubocop/Metrics/ParameterLists")
.hasCategory("Complexity")
.hasLineStart(2)
.hasSeverity(Severity.WARNING_NORMAL);
softly.assertThat(report.get(1))
.hasMessage("Method `destroy` has 6 arguments (exceeds 4 allowed). Consider refactoring.")
.hasFileName("argument_count.rb")
.hasType("argument_count")
.hasCategory("Complexity")
.hasLineStart(2)
.hasSeverity(Severity.WARNING_NORMAL);
}

@Override
protected CodeClimateAdapter createParser() {
return new CodeClimateAdapter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"categories": [
"Complexity"
],
"check_name": "argument_count",
"content": {
"body": ""
},
"description": "Method `destroy` has 6 arguments (exceeds 4 allowed). Consider refactoring.",
"fingerprint": "f778445eae9245ad3a9e5a61bc380d31",
"location": {
"path": "argument_count.rb",
"lines": {
"begin": 2,
"end": 2
}
},
"other_locations": [

],
"remediation_points": 450000,
"severity": "minor",
"type": "issue",
"engine_name": "structure"
},
{
"type": "Issue",
"check_name": "Rubocop\/Metrics\/ParameterLists",
"description": "Avoid parameter lists longer than 5 parameters. [6\/5]",
"categories": [
"Complexity"
],
"remediation_points": 250000,
"location": {
"path": "argument_count.rb",
"positions": {
"begin": {
"column": 14,
"line": 2
},
"end": {
"column": 27,
"line": 2
}
}
},
"content": {
"body": "This cop checks for methods with too many parameters.\nThe maximum number of parameters is configurable.\nKeyword arguments can optionally be excluded from the total count."
},
"engine_name": "rubocop",
"fingerprint": "5182fe949b37d86b6a434d96c19ca44f",
"severity": "minor"
}
]

0 comments on commit 1ac336c

Please sign in to comment.