Skip to content

Commit

Permalink
Support RubyCop #15
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Feb 18, 2017
1 parent 68ac9c8 commit 75ad3b3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ Changelog of Git Changelog.
[f7212555f7a986b](https://github.com/tomasbjerre/violations-lib/commit/f7212555f7a986b) Tomas Bjerre *2017-02-18 20:01:36*


### GitHub [#15](https://github.com/tomasbjerre/violations-lib/issues/15) Support Rubycop

**Support RubyCop**


[1ac049fe42feaf0](https://github.com/tomasbjerre/violations-lib/commit/1ac049fe42feaf0) Tomas Bjerre *2017-02-18 21:36:15*


### GitHub [#16](https://github.com/tomasbjerre/violations-lib/issues/16) Support clang

**Support CLang**


[ed80dc48dffafa9](https://github.com/tomasbjerre/violations-lib/commit/ed80dc48dffafa9) Tomas Bjerre *2017-02-18 21:28:15*
[68ac9c8cf268d17](https://github.com/tomasbjerre/violations-lib/commit/68ac9c8cf268d17) Tomas Bjerre *2017-02-18 21:28:31*


### GitHub [#17](https://github.com/tomasbjerre/violations-lib/issues/17) Support golint
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ It supports:
* [_ESLint_](https://github.com/sindresorhus/grunt-eslint) with `format: 'checkstyle'`.
* [_PHPCS_](https://github.com/squizlabs/PHP_CodeSniffer) with `phpcs api.php --report=checkstyle`.
* [_CLang_](https://clang-analyzer.llvm.org/)
* [_RubyCop_](http://rubocop.readthedocs.io/en/latest/formatters/) with `rubycop -f clang file.rb`
* [_CodeNarc_](http://codenarc.sourceforge.net/)
* [_CPD_](http://pmd.sourceforge.net/pmd-4.3.0/cpd.html)
* [_CPPLint_](https://github.com/theandrewdavis/cpplint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public SEVERITY toSeverity(String severity) {
if (isNullOrEmpty(severity)) {
return INFO;
}
if (severity.contains("error")) {
if (severity.contains("error") || severity.contains("C")) {
return ERROR;
}
if (severity.contains("warning")) {
if (severity.contains("warning") || severity.contains("W")) {
return WARN;
}
return INFO;
Expand Down
32 changes: 31 additions & 1 deletion src/test/java/se/bjurr/violations/lib/CLangTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.model.SEVERITY.WARN;
import static se.bjurr.violations.lib.reports.Reporter.CLANG;

import java.util.List;
Expand All @@ -20,7 +21,7 @@ public void testThatViolationsCanBeParsed() {
String rootFolder = getRootFolder();

List<Violation> actual = violationsReporterApi() //
.withPattern(".*/clang/.*\\.txt$") //
.withPattern(".*/clang/clang.*\\.txt$") //
.inFolder(rootFolder) //
.findAll(CLANG) //
.violations();
Expand Down Expand Up @@ -52,4 +53,33 @@ public void testThatViolationsCanBeParsed() {
.isEqualTo(4);
}

@Test
public void testThatRubycopViolationsCanBeParsed() {
String rootFolder = getRootFolder();

List<Violation> actual = violationsReporterApi() //
.withPattern(".*/clang/rubycop\\.txt$") //
.inFolder(rootFolder) //
.findAll(CLANG) //
.violations();

assertThat(actual)//
.hasSize(4);

assertThat(actual.get(0).getMessage())//
.isEqualTo(
"Use snake_case for method names.");
assertThat(actual.get(0).getFile())//
.isEqualTo("test.rb");
assertThat(actual.get(0).getSeverity())//
.isEqualTo(ERROR);
assertThat(actual.get(0).getRule().orNull())//
.isEqualTo(null);
assertThat(actual.get(0).getStartLine())//
.isEqualTo(1);

assertThat(actual.get(3).getSeverity())//
.isEqualTo(WARN);
}

}
19 changes: 19 additions & 0 deletions src/test/resources/clang/rubycop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Inspecting 1 file
W

Offenses:

test.rb:1:5: C: Use snake_case for method names.
def badName
^^^^^^^
test.rb:2:3: C: Use a guard clause instead of wrapping the code inside a conditional expression.
if something
^^
test.rb:2:3: C: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
if something
^^
test.rb:4:5: W: end at 4, 4 is not aligned with if at 2, 2
end
^^^

1 file inspected, 4 offenses detected

0 comments on commit 75ad3b3

Please sign in to comment.