Skip to content

Commit

Permalink
Adding MyPy and PyDocStyle parsers #12 #13
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Feb 6, 2017
1 parent 6063d15 commit acfe331
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 0 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@

Changelog of Git Changelog.

## Unreleased
### GitHub [#12](https://github.com/tomasbjerre/violations-lib/issues/12) Support pydocstyle (old pep257)

**Adding MyPy and PyDocStyle parsers**


[31b2ded01433fb8](https://github.com/tomasbjerre/violations-lib/commit/31b2ded01433fb8) Tomas Bjerre *2017-02-06 17:06:43*


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

**Adding MyPy and PyDocStyle parsers**


[31b2ded01433fb8](https://github.com/tomasbjerre/violations-lib/commit/31b2ded01433fb8) Tomas Bjerre *2017-02-06 17:06:43*


### No issue

**Set theme jekyll-theme-slate**


[6063d15ecfbb8a7](https://github.com/tomasbjerre/violations-lib/commit/6063d15ecfbb8a7) Tomas Bjerre *2017-01-12 03:06:06*

**doc**


[943154cb27cfd1e](https://github.com/tomasbjerre/violations-lib/commit/943154cb27cfd1e) Tomas Bjerre *2016-12-21 16:46:56*


## 1.20
### No issue

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ It supports:
* [_JSHint_](http://jshint.com/)
* _Lint_ A common XML format, used by different linters.
* [_JCReport_](https://github.com/jCoderZ/fawkez/wiki/JcReport)
* [_MyPy_](https://pypi.python.org/pypi/mypy-lang)
* [_PerlCritic_](https://github.com/Perl-Critic)
* [_PiTest_](http://pitest.org/)
* [_PyDocStyle_](https://pypi.python.org/pypi/pydocstyle)
* [_PyLint_](https://www.pylint.org/)
* [_PMD_](https://pmd.github.io/)
* [_ReSharper_](https://www.jetbrains.com/resharper/)
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/se/bjurr/violations/lib/parsers/MyPyParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package se.bjurr.violations.lib.parsers;

import static java.lang.Integer.parseInt;
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.Violation.violationBuilder;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getLines;
import static se.bjurr.violations.lib.reports.Reporter.MYPY;

import java.util.ArrayList;
import java.util.List;

import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

public class MyPyParser implements ViolationsParser {

@Override
public List<Violation> parseReportOutput(String reportContent) throws Exception {
List<Violation> violations = new ArrayList<>();
List<List<String>> partsPerLine = getLines(reportContent, "^(.*):(\\d+): (.*): (.*)$");
for (List<String> parts : partsPerLine) {
String fileName = parts.get(1);
Integer lineNumber = 0;
if (!parts.get(2).isEmpty()) {
lineNumber = parseInt(parts.get(2));
}
String severity = parts.get(3);
String message = parts.get(4);
violations.add(//
violationBuilder()//
.setReporter(MYPY)//
.setStartLine(lineNumber)//
.setFile(fileName)//
.setSeverity(toSeverity(severity))//
.setMessage(message)//
.build()//
);
}
return violations;
}

public SEVERITY toSeverity(String severity) {
if (severity.equalsIgnoreCase("error")) {
return ERROR;
}
return INFO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package se.bjurr.violations.lib.parsers;

import static java.lang.Integer.parseInt;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getParts;
import static se.bjurr.violations.lib.reports.Reporter.PYDOCSTYLE;

import java.util.ArrayList;
import java.util.List;

import se.bjurr.violations.lib.model.Violation;

public class PyDocStyleParser implements ViolationsParser {

@Override
public List<Violation> parseReportOutput(String string) throws Exception {
List<Violation> violations = new ArrayList<>();
boolean fileLine = true;
List<String> lines = ViolationParserUtils.getLines(string);
String filename = null;
Integer line = null;
for (String inputLine : lines) {
if (fileLine) {
List<String> parts = getParts(inputLine, "([^:]*)", "(\\d+)");
filename = parts.get(0);
line = parseInt(parts.get(1));
} else {
List<String> parts = getParts(inputLine, "([^:]*)", ":(.*)");
String rule = parts.get(0);
String message = parts.get(1);

violations.add(//
violationBuilder()//
.setReporter(PYDOCSTYLE)//
.setStartLine(line)//
.setFile(filename)//
.setRule(rule)//
.setSeverity(ERROR)//
.setMessage(message)//
.build()//
);
}
fileLine = !fileLine;
}
return violations;
}
}
4 changes: 4 additions & 0 deletions src/main/java/se/bjurr/violations/lib/reports/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import se.bjurr.violations.lib.parsers.JCReportParser;
import se.bjurr.violations.lib.parsers.JSHintParser;
import se.bjurr.violations.lib.parsers.LintParser;
import se.bjurr.violations.lib.parsers.MyPyParser;
import se.bjurr.violations.lib.parsers.PMDParser;
import se.bjurr.violations.lib.parsers.PerlCriticParser;
import se.bjurr.violations.lib.parsers.PiTestParser;
import se.bjurr.violations.lib.parsers.PyDocStyleParser;
import se.bjurr.violations.lib.parsers.PyLintParser;
import se.bjurr.violations.lib.parsers.ResharperParser;
import se.bjurr.violations.lib.parsers.SimianParser;
Expand All @@ -50,9 +52,11 @@ public enum Reporter {
JCREPORT(new JCReportParser()), //
JSHINT(new JSHintParser()), //
LINT(new LintParser()), //
MYPY(new MyPyParser()), //
PERLCRITIC(new PerlCriticParser()), //
PITEST(new PiTestParser()), //
PMD(new PMDParser()), //
PYDOCSTYLE(new PyDocStyleParser()), //
PYLINT(new PyLintParser()), //
RESHARPER(new ResharperParser()), //
SIMIAN(new SimianParser()), //
Expand Down
58 changes: 58 additions & 0 deletions src/test/java/se/bjurr/violations/lib/MyPyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package se.bjurr.violations.lib;

import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.violations.lib.TestUtils.getRootFolder;
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.reports.Reporter.MYPY;

import java.util.List;

import org.junit.Test;

import se.bjurr.violations.lib.model.Violation;

/**
* Created by matthew on 27/04/16.
*/
public class MyPyTest {

@Test
public void testThatViolationsCanBeParsed() {

String rootFolder = getRootFolder();

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

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

assertThat(actual.get(0))//
.isEqualTo(//
violationBuilder()//
.setReporter(MYPY)//
.setFile("fs/cs/backend/log.py") //
.setStartLine(16)//
.setMessage("\"LogRecord\" has no attribute \"user_uuid\"") //
.setSeverity(ERROR) //
.build() //
);

assertThat(actual.get(1))//
.isEqualTo(//
violationBuilder()//
.setReporter(MYPY)//
.setFile("fs/cs/backend/log.py") //
.setStartLine(17)//
.setMessage("\"LogRecord\" has no attribute \"tenant_id\"") //
.setSeverity(ERROR) //
.build() //
);

}
}
72 changes: 72 additions & 0 deletions src/test/java/se/bjurr/violations/lib/PyDocStyleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package se.bjurr.violations.lib;

import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.violations.lib.TestUtils.getRootFolder;
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.reports.Reporter.PYDOCSTYLE;

import java.util.List;

import org.junit.Test;

import se.bjurr.violations.lib.model.Violation;

/**
* Created by matthew on 27/04/16.
*/
public class PyDocStyleTest {

@Test
public void testThatViolationsCanBeParsed() {

String rootFolder = getRootFolder();

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

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

assertThat(actual.get(0))//
.isEqualTo(//
violationBuilder()//
.setReporter(PYDOCSTYLE)//
.setFile("fs/csm/admin_api/ui_api.py") //
.setStartLine(1) //
.setRule("D100") //
.setMessage("Missing docstring in public module") //
.setSeverity(ERROR) //
.build() //
);

assertThat(actual.get(1))//
.isEqualTo(//
violationBuilder()//
.setReporter(PYDOCSTYLE)//
.setFile("fs/csm/admin_api/main.py") //
.setStartLine(1) //
.setRule("D100") //
.setMessage("Missing docstring in public module") //
.setSeverity(ERROR) //
.build() //
);

assertThat(actual.get(20))//
.isEqualTo(//
violationBuilder()//
.setReporter(PYDOCSTYLE)//
.setFile("fs/csm/admin_api/auth.py") //
.setStartLine(73) //
.setRule("D101") //
.setMessage("Missing docstring in public class") //
.setSeverity(ERROR) //
.build() //
);

}
}
8 changes: 8 additions & 0 deletions src/test/resources/mypy/mypy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fs/cs/backend/log.py: note: In member "filter" of class "CsLogFilter":
fs/cs/backend/log.py:16: error: "LogRecord" has no attribute "user_uuid"
fs/cs/backend/log.py:17: error: "LogRecord" has no attribute "tenant_id"
fs/cs/backend/errorhandler.py: note: In member "__init__" of class "CsErrorHandler":
fs/cs/backend/errorhandler.py:16: error: The return type of "__init__" must be None
fs/cs/backend/api.py: note: At top level:
fs/cs/backend/api.py:23: error: ContextManager[Any] not callable
tests/test_schema.py:864: error: Name 'test_nested_only_and_exclude' already defined
66 changes: 66 additions & 0 deletions src/test/resources/pydocstyle/pydocstyle.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
fs/csm/admin_api/ui_api.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/main.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/dao.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/dao.py:8 in public class `Dao`:
D101: Missing docstring in public class
fs/csm/admin_api/admin_api.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/admin_api.py:34 in public function `x_debug_check`:
D103: Missing docstring in public function
fs/csm/admin_api/admin_api.py:40 in public class `NewNodeSchema`:
D101: Missing docstring in public class
fs/csm/admin_api/admin_api.py:227 in public class `NewChildNodeSchema`:
D101: Missing docstring in public class
fs/csm/admin_api/admin_api.py:463 in public class `NewParentNodeSchema`:
D101: Missing docstring in public class
fs/csm/admin_api/admin_api.py:614 in public class `PatchNodeSchema`:
D101: Missing docstring in public class
fs/csm/admin_api/settings.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/settings.py:12 in public class `SettingsService`:
D101: Missing docstring in public class
fs/csm/admin_api/settings.py:14 in public method `try_create_root_node`:
D102: Missing docstring in public method
fs/csm/admin_api/settings.py:26 in public method `try_create_child_node`:
D102: Missing docstring in public method
fs/csm/admin_api/settings.py:43 in public method `try_create_parent_node`:
D102: Missing docstring in public method
fs/csm/admin_api/sphinx.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/auth.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/auth.py:20 in public method `__init__`:
D102: Missing docstring in public method
fs/csm/admin_api/auth.py:25 in public method `__str__`:
D105: Missing docstring in magic method
fs/csm/admin_api/auth.py:38 in public method `authorize`:
D102: Missing docstring in public method
fs/csm/admin_api/auth.py:73 in public class `OAuth2Resolver`:
D101: Missing docstring in public class
fs/csm/admin_api/auth.py:126 in public class `AdminApiResolver`:
D101: Missing docstring in public class
fs/csm/admin_api/auth.py:128 in public method `__init__`:
D102: Missing docstring in public method
fs/csm/admin_api/auth.py:131 in public method `configure`:
D102: Missing docstring in public method
fs/csm/admin_api/auth.py:134 in public method `auth`:
D102: Missing docstring in public method
fs/csm/admin_api/auth.py:137 in public method `resolve`:
D102: Missing docstring in public method
fs/csm/admin_api/__init__.py:1 at module level:
D104: Missing docstring in public package
fs/csm/admin_api/application.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/application.py:46 in public function `build_app`:
D103: Missing docstring in public function
fs/csm/admin_api/wsgi.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/test/conftest.py:1 at module level:
D100: Missing docstring in public module
fs/csm/admin_api/test/conftest.py:18 in public function `admin_api_wsgi`:
D103: Missing docstring in public function
fs/csm/admin_api/test/__init__.py:1 at module level:
D104: Missing docstring in public package

0 comments on commit acfe331

Please sign in to comment.