Skip to content

Commit

Permalink
Step 1: add the new files
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Sep 20, 2015
1 parent 34b0e89 commit 2faa491
Show file tree
Hide file tree
Showing 17 changed files with 2,054 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.godaddy.sonar.ruby.metricfu;

public class CaneCommentViolation extends CaneViolation {
private int line;
private String className;

public CaneCommentViolation(String file, int line, String className) {
super(file);
this.line = line;
this.className = className;
}

public CaneCommentViolation() {
}

public String getKey() {
return "CommentViolation";
}

public int getLine() {
return line;
}

public void setLine(int line) {
this.line = line;
}

public String getClassName() {
return className;
}

public void setClassName(String className) {
this.className = className;
}

@Override
public String toString() {
return "file: " + getFile() + " line: " + line + " class: " + className;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.godaddy.sonar.ruby.metricfu;

public class CaneComplexityViolation extends CaneViolation {
private String method;
private int complexity;

public CaneComplexityViolation(String file, String method, int complexity) {
super(file);
this.method = method;
this.complexity = complexity;
}

public CaneComplexityViolation() {
}

public String getKey() {
return "ComplexityViolation";
}

public String getMethod() {
return method;
}

public void setMethod(String method) {
this.method = method;
}

public int getComplexity() {
return complexity;
}

public void setComplexity(int complexity) {
this.complexity = complexity;
}

@Override
public String toString() {
return "file: " + getFile() + " line: " + complexity + " method: " + method;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.godaddy.sonar.ruby.metricfu;

public class CaneLineStyleViolation extends CaneViolation {
private int line;
private String description;
private String key = "UnknownViolation";

public CaneLineStyleViolation(String file, int line, String description) {
super(file);
setLine(line);
setDescription(description);
}

public CaneLineStyleViolation() {
}

public String getKey() {
return key;
}

public int getLine() {
return line;
}

public void setLine(int line) {
this.line = line;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;

if (description.contains("tabs")) {
key = "LineStyleTabsViolation";
} else if (description.contains("whitespace")) {
key = "LineStyleWhitespaceViolation";
} else if (description.contains("characters")) {
key = "LineStyleLengthViolation";
}
}

@Override
public String toString() {
return "file: " + getFile() + " line: " + line + " description: " + description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.godaddy.sonar.ruby.metricfu;

import org.apache.commons.io.IOUtils;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.rules.XMLRuleParser;

import com.godaddy.sonar.ruby.RubyPlugin;
import com.godaddy.sonar.ruby.core.Ruby;

import java.io.InputStream;
import java.util.List;

public class CaneRulesRepository extends RuleRepository {
public CaneRulesRepository() {
super(RubyPlugin.KEY_REPOSITORY_CANE, Ruby.KEY);
setName(RubyPlugin.NAME_REPOSITORY_CANE);
}


@Override
public List<Rule> createRules() {
XMLRuleParser parser = new XMLRuleParser();
InputStream input = CaneRulesRepository.class.getResourceAsStream("/com/godaddy/sonar/ruby/metricfu/CaneRulesRepository.xml");
try {
return parser.parse(input);
} finally {
IOUtils.closeQuietly(input);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<rules>
<rule>
<key>ComplexityViolation</key>
<priority>MAJOR</priority>
<name><![CDATA[ABC Complexity Exceeds Threshold]]></name>
<description>
<![CDATA[
<p>
Methods exceeded maximum allowed ABC complexity.
</p>
]]>
</description>
</rule>
<rule>
<key>LineStyleLengthViolation</key>
<priority>MINOR</priority>
<name><![CDATA[Line Length Exceeds Threshold]]></name>
<description>
<![CDATA[
<p>
The line length exceeds the specified threshold.
</p>
]]>
</description>
</rule>
<rule>
<key>LineStyleTabsViolation</key>
<priority>MINOR</priority>
<name><![CDATA[Line Contains Hard Tabs]]></name>
<description>
<![CDATA[
<p>
The line contains hard tabs.
</p>
]]>
</description>
</rule>
<rule>
<key>LineStyleWhitespaceViolation</key>
<priority>MINOR</priority>
<name><![CDATA[Line Contains Trailing Whitespace]]></name>
<description>
<![CDATA[
<p>
The line contains trailing whitespace.
</p>
]]>
</description>
</rule>
<rule>
<key>CommentViolation</key>
<priority>MINOR</priority>
<name><![CDATA[Class Definition Requires Explanatory Comment]]></name>
<description>
<![CDATA[
<p>
Class definitions require explanatory comments on preceding line.
</p>
]]>
</description>
</rule>
</rules>
27 changes: 27 additions & 0 deletions src/main/java/com/godaddy/sonar/ruby/metricfu/CaneViolation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.godaddy.sonar.ruby.metricfu;

public abstract class CaneViolation {
private String file;

public CaneViolation(String file) {
this.file = file;
}

public CaneViolation() {
}

public abstract String getKey();

public String getFile() {
return file;
}

public void setFile(String file) {
this.file = file;
}

@Override
public String toString() {
return "file: " + file;
}
}
76 changes: 76 additions & 0 deletions src/main/java/com/godaddy/sonar/ruby/metricfu/FlayReason.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.godaddy.sonar.ruby.metricfu;

import java.util.ArrayList;

public class FlayReason {

public class Match {
private String file;
private Integer start;
private Integer lines;

public Match(String file, Integer start, Integer lines) {
this.file = file;
this.start = start;
this.lines = lines;
}

public Match(String file, Integer start) {
this(file, start, 1);
}

public Match(String file) {
this(file, 1, 1);
}

public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public Integer getStartLine() {
return start;
}
public void setStartLine(Integer start) {
this.start = start;
}
public Integer getLines() {
return lines;
}
public void setLines(Integer lines) {
this.lines = lines;
}
}

private String reason;
private ArrayList<Match> matches = new ArrayList<Match>();

public FlayReason(String reason) {
this.reason = reason;
}

public FlayReason() {
}

public String getReason() {
return reason;
}

public void setReason(String reason) {
this.reason = reason;
}

public ArrayList<Match> getMatches() {
return matches;
}

public void addMatch(String file, Integer start) {
matches.add(new Match(file, start));
}

@Override
public String toString() {
return "reason: " + reason;
}
}
Loading

0 comments on commit 2faa491

Please sign in to comment.