forked from pica/ruby-sonar-plugin
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
2,054 additions
and
1 deletion.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/main/java/com/godaddy/sonar/ruby/metricfu/CaneCommentViolation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/godaddy/sonar/ruby/metricfu/CaneComplexityViolation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/godaddy/sonar/ruby/metricfu/CaneLineStyleViolation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/godaddy/sonar/ruby/metricfu/CaneRulesRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/godaddy/sonar/ruby/metricfu/CaneRulesRepository.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
src/main/java/com/godaddy/sonar/ruby/metricfu/CaneViolation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
76
src/main/java/com/godaddy/sonar/ruby/metricfu/FlayReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.