Skip to content

Commit

Permalink
Allowing noise in Flake8 parser #69
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jun 7, 2019
1 parent 8d9a2d5 commit 1ab666f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 18 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@

Changelog of Violations lib.

## Unreleased
### No issue

**doc**


[8d9a2d5c16852f2](https://github.com/tomasbjerre/violations-lib/commit/8d9a2d5c16852f2) Tomas Bjerre *2019-06-01 13:41:05*

**doc**


[b9720430d4db962](https://github.com/tomasbjerre/violations-lib/commit/b9720430d4db962) Tomas Bjerre *2019-06-01 13:16:48*

**doc**


[09670621f7e77fe](https://github.com/tomasbjerre/violations-lib/commit/09670621f7e77fe) Tomas Bjerre *2019-06-01 10:30:52*

**doc**


[9697bfaefe75836](https://github.com/tomasbjerre/violations-lib/commit/9697bfaefe75836) Tomas Bjerre *2019-05-30 20:28:12*


## 1.92
### GitHub [#68](https://github.com/tomasbjerre/violations-lib/issues/68) cpplint parser does not recognize any violations from cpplint report

Expand Down
25 changes: 15 additions & 10 deletions src/main/java/se/bjurr/violations/lib/parsers/Flake8Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@
public class Flake8Parser implements ViolationsParser {

@Override
public List<Violation> parseReportOutput(String string) throws Exception {
List<Violation> violations = new ArrayList<>();
List<List<String>> partsPerLine =
public List<Violation> parseReportOutput(final String string) throws Exception {
final List<Violation> violations = new ArrayList<>();
final List<List<String>> partsPerLine =
getLines(string, "([^:]*):(\\d+)?:?(\\d+)?:? \\[?(\\D+)(\\d*)\\]? (.*)");
for (List<String> parts : partsPerLine) {
String filename = parts.get(1);
Integer line = parseInt(parts.get(2));
for (final List<String> parts : partsPerLine) {
final String filename = parts.get(1);
Integer line = null;
try {
line = parseInt(parts.get(2));
} catch (final Exception e) {
continue;
}
Integer column = null;
if (!isNullOrEmpty(parts.get(3))) {
column = parseInt(parts.get(3));
}
String severity = parts.get(4);
String rule = parts.get(5);
String message = parts.get(6);
final String severity = parts.get(4);
final String rule = parts.get(5);
final String message = parts.get(6);
violations.add( //
violationBuilder() //
.setParser(FLAKE8) //
Expand Down Expand Up @@ -65,7 +70,7 @@ public List<Violation> parseReportOutput(String string) throws Exception {
* further processing.
* </pre>
*/
public SEVERITY toSeverity(String severity) {
public SEVERITY toSeverity(final String severity) {
if (severity.equalsIgnoreCase("E") || severity.equalsIgnoreCase("F")) {
return ERROR;
}
Expand Down
35 changes: 27 additions & 8 deletions src/test/java/se/bjurr/violations/lib/Flake8Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testThatViolationsCanBeParsed() {
) //
.hasSize(17);

Violation violation9 = actual.get(9);
final Violation violation9 = actual.get(9);
assertThat(violation9.getMessage()) //
.isEqualTo("test with F");
assertThat(violation9.getFile()) //
Expand All @@ -50,23 +50,23 @@ public void testThatViolationsCanBeParsed() {
assertThat(violation9.getSeverity()) //
.isEqualTo(ERROR);

Violation violation10 = actual.get(10);
final Violation violation10 = actual.get(10);
assertThat(violation10.getMessage()) //
.isEqualTo("test with W");
assertThat(violation10.getFile()) //
.isEqualTo("__fake__.py");
assertThat(violation10.getSeverity()) //
.isEqualTo(WARN);

Violation violation11 = actual.get(11);
final Violation violation11 = actual.get(11);
assertThat(violation11.getMessage()) //
.isEqualTo("test with C");
assertThat(violation11.getFile()) //
.isEqualTo("__fake__.py");
assertThat(violation11.getSeverity()) //
.isEqualTo(INFO);

Violation violation16 = actual.get(16);
final Violation violation16 = actual.get(16);
assertThat(violation16.getMessage()) //
.isEqualTo("expected 2 blank lines, found 1");
assertThat(violation16.getFile()) //
Expand Down Expand Up @@ -99,7 +99,7 @@ public void testThatViolationsCanBeParsedWithStartingDots() {
assertThat(actual) //
.hasSize(2);

Violation violation0 = actual.get(0);
final Violation violation0 = actual.get(0);
assertThat(violation0.getMessage()) //
.isEqualTo("line too long (143 > 120 characters)");
assertThat(violation0.getFile()) //
Expand All @@ -111,7 +111,7 @@ public void testThatViolationsCanBeParsedWithStartingDots() {
assertThat(violation0.getSeverity()) //
.isEqualTo(ERROR);

Violation violation1 = actual.get(1);
final Violation violation1 = actual.get(1);
assertThat(violation1.getMessage()) //
.isEqualTo("no newline at end of file");
assertThat(violation1.getFile()) //
Expand All @@ -138,7 +138,7 @@ public void testThatViolationsCanBeParsedWithAnsibleLint() {
assertThat(actual) //
.hasSize(8);

Violation violation0 = actual.get(0);
final Violation violation0 = actual.get(0);
assertThat(violation0.getMessage()) //
.isEqualTo("Commands should not change things if nothing needs doing");
assertThat(violation0.getFile()) //
Expand All @@ -150,12 +150,31 @@ public void testThatViolationsCanBeParsedWithAnsibleLint() {
assertThat(violation0.getStartLine()) //
.isEqualTo(25);

Violation violation7 = actual.get(7);
final Violation violation7 = actual.get(7);
assertThat(violation7.getMessage()) //
.isEqualTo("This line is just added to test W");
assertThat(violation7.getRule()) //
.isEqualTo("WANSIBLE0012");
assertThat(violation7.getSeverity()) //
.isEqualTo(WARN);
}

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

final List<Violation> actual =
violationsApi() //
.withPattern(".*/flake8/flake8-failure\\.log$") //
.inFolder(rootFolder) //
.findAll(FLAKE8) //
.violations();

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

final Violation violation0 = actual.get(0);
assertThat(violation0.getMessage()) //
.startsWith("HOME=/var/jenkins_home/workspace/");
}
}
27 changes: 27 additions & 0 deletions src/test/resources/flake8/flake8-failure.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[2019-06-03T11:15:10.330Z] Running step gcr.io/action-containers/flake8:3.6.0-1 (0) from task Flake8
[Pipeline] sh
[2019-06-03T11:15:10.626Z] + docker run --rm --dns-search google.internal --dns-search spotify.net -w /var/jenkins_home/workspace/tingle_2.2449/workspace/ -e DOCKER_HOST=tcp://10.99.0.1:2375 -e HOME=/var/jenkins_home/workspace/tingle_2.2449 -e COMMIT_SHA=36cd8626f947af1136423ee51d063a611de61eb8 -e BRANCH_NAME=origin/allow-backfills -e ORGANIZATION=white-mouse -e REPOSITORY=message-delivery-view -e GIT_REF=refs/pull/72/merge -e BUILD_ID=abd30790-85f0-11e9-8081-536de80999bc -e CI=true -e _JAVA_OPTIONS=-Duser.home=/var/jenkins_home/workspace/tingle_2.2449 -e FORCE_COLOR=true --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/workspace,target=/var/jenkins_home/workspace/tingle_2.2449/workspace --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449,target=/var/jenkins_home/workspace/tingle_2.2449 --mount type=bind,source=/usr/bin/docker-credential-gcr,target=/usr/bin/docker-credential-gcr --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/.tingle-tmp/white-mouse_message-delivery-view_abd30790-85f0-11e9-8081-536de80999bc.710397465,target=/etc/build-secrets --mount type=bind,source=/etc/ssl/certs/ca-certificates.crt,target=/etc/ssl/certs/ca-certificates.crt gcr.io/action-containers/flake8:3.6.0-1
[2019-06-03T11:15:11.970Z] ./message-delivery-view/src/main/python/user_unsubscribe_tasks.py:12:65: F821 undefined name 'FALSE'
[Pipeline] }
[2019-06-03T11:15:12.526Z] Failed in branch 0: Flake8
[Pipeline] // parallel
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timeout
[Pipeline] echo
[2019-06-03T11:15:12.549Z] hudson.AbortException: Action{name='gcr.io/action-containers/flake8:3.6.0-1', workspace='/var/jenkins_home/workspace/tingle_2.2449/workspace', workdir='/var/jenkins_home/workspace/tingle_2.2449/workspace/', ignoreErrors=false, args=null, envs=[COMMIT_SHA:36cd8626f947af1136423ee51d063a611de61eb8, BRANCH_NAME:origin/allow-backfills, ORGANIZATION:white-mouse, REPOSITORY:message-delivery-view, GIT_REF:refs/pull/72/merge, BUILD_ID:abd30790-85f0-11e9-8081-536de80999bc, CI:true, HOME:/var/jenkins_home/workspace/tingle_2.2449, _JAVA_OPTIONS:-Duser.home=/var/jenkins_home/workspace/tingle_2.2449, FORCE_COLOR:true], envFiles=[], entryPointOverride=null} failed! See errors above.
[Pipeline] stage
[Pipeline] { (Build reports)
[Pipeline] sh
[2019-06-03T11:15:12.907Z] + docker run -w /var/jenkins_home/workspace/tingle_2.2449/workspace -e DOCKER_HOST=tcp://10.99.0.1:2375 -e HOME=/var/jenkins_home/workspace/tingle_2.2449/workspace -e GOOGLE_APPLICATION_CREDENTIALS=/.application_default_credentials.json -e TERM=xterm-256color -e NPM_CONFIG_REGISTRY=https://artifactory.spotify.net/artifactory/api/npm/virtual-npm --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/workspace,target=/var/jenkins_home/workspace/tingle_2.2449/workspace --mount type=bind,source=/etc/spotify/secrets/build-agent_gcloud.json,target=/.application_default_credentials.json,readonly --mount type=bind,source=/usr/bin/docker-credential-gcr,target=/usr/bin/docker-credential-gcr --mount type=bind,source=/etc/ssl/certs/ca-certificates.crt,target=/etc/ssl/certs/ca-certificates.crt --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/.tingle-tmp/white-mouse_message-delivery-view_abd30790-85f0-11e9-8081-536de80999bc.710397465,target=/etc/build-secrets gcr.io/action-containers/gcloud:207.0.0-1 auth activate-service-account --key-file=/.application_default_credentials.json
[2019-06-03T11:15:15.391Z] Activated service account credentials for: [build-agent@xpn-tingle-1.iam.gserviceaccount.com]
[2019-06-03T11:15:15.942Z] + docker run -w /var/jenkins_home/workspace/tingle_2.2449/workspace -e DOCKER_HOST=tcp://10.99.0.1:2375 -e HOME=/var/jenkins_home/workspace/tingle_2.2449/workspace -e GOOGLE_APPLICATION_CREDENTIALS=/.application_default_credentials.json -e TERM=xterm-256color -e NPM_CONFIG_REGISTRY=https://artifactory.spotify.net/artifactory/api/npm/virtual-npm --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/workspace,target=/var/jenkins_home/workspace/tingle_2.2449/workspace --mount type=bind,source=/etc/spotify/secrets/build-agent_gcloud.json,target=/.application_default_credentials.json,readonly --mount type=bind,source=/usr/bin/docker-credential-gcr,target=/usr/bin/docker-credential-gcr --mount type=bind,source=/etc/ssl/certs/ca-certificates.crt,target=/etc/ssl/certs/ca-certificates.crt --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/.tingle-tmp/white-mouse_message-delivery-view_abd30790-85f0-11e9-8081-536de80999bc.710397465,target=/etc/build-secrets gcr.io/action-containers/gcloud:207.0.0-1 auth configure-docker --quiet
[2019-06-03T11:15:18.426Z] gcloud credential helpers already registered correctly.
[2019-06-03T11:15:18.977Z] + docker run -w /var/jenkins_home/workspace/tingle_2.2449/workspace -e DOCKER_HOST=tcp://10.99.0.1:2375 -e HOME=/var/jenkins_home/workspace/tingle_2.2449/workspace -e GOOGLE_APPLICATION_CREDENTIALS=/.application_default_credentials.json -e TERM=xterm-256color -e NPM_CONFIG_REGISTRY=https://artifactory.spotify.net/artifactory/api/npm/virtual-npm --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/workspace,target=/var/jenkins_home/workspace/tingle_2.2449/workspace --mount type=bind,source=/etc/spotify/secrets/build-agent_gcloud.json,target=/.application_default_credentials.json,readonly --mount type=bind,source=/usr/bin/docker-credential-gcr,target=/usr/bin/docker-credential-gcr --mount type=bind,source=/etc/ssl/certs/ca-certificates.crt,target=/etc/ssl/certs/ca-certificates.crt --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/.tingle-tmp/white-mouse_message-delivery-view_abd30790-85f0-11e9-8081-536de80999bc.710397465,target=/etc/build-secrets gcr.io/action-containers/bash:0.1 -c 'docker-credential-gcr configure-docker'
[2019-06-03T11:15:19.888Z] + docker run -w /var/jenkins_home/workspace/tingle_2.2449/workspace -e DOCKER_HOST=tcp://10.99.0.1:2375 -e HOME=/var/jenkins_home/workspace/tingle_2.2449/workspace -e GOOGLE_APPLICATION_CREDENTIALS=/.application_default_credentials.json -e TERM=xterm-256color -e NPM_CONFIG_REGISTRY=https://artifactory.spotify.net/artifactory/api/npm/virtual-npm --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/workspace,target=/var/jenkins_home/workspace/tingle_2.2449/workspace --mount type=bind,source=/etc/spotify/secrets/build-agent_gcloud.json,target=/.application_default_credentials.json,readonly --mount type=bind,source=/usr/bin/docker-credential-gcr,target=/usr/bin/docker-credential-gcr --mount type=bind,source=/etc/ssl/certs/ca-certificates.crt,target=/etc/ssl/certs/ca-certificates.crt --mount type=bind,source=/var/jenkins_home/workspace/tingle_2.2449/.tingle-tmp/white-mouse_message-delivery-view_abd30790-85f0-11e9-8081-536de80999bc.710397465,target=/etc/build-secrets gcr.io/action-containers/bash:0.1 -c 'cp /.application_default_credentials.json .config/gcloud/application_default_credentials.json'
[Pipeline] stage
[Pipeline] { (Archiving artifacts in GCS)
[Pipeline] sh
[2019-06-03T11:15:21.632Z] DEBUG:build-artifacts:skipping file 'scalastyle-config.xml'
[2019-06-03T11:15:21.632Z] DEBUG:build-artifacts:inclusions: {'artifact-archive/.*', 'jacoco\\.exec', 'cobertura/coverage\\.xml', 'findbugsXml\\.xml', 'pom\\.xml', 'bazel-testlogs/test.xml', 'tox\\.ini', 'test-results/.*\\.xml', 'surefire-reports/.*\\.xml', 'cobertura\\.xml', 'spotbugsXml\\.xml', 'build-info\\.yaml', 'test-reports/.*\\.xml', 'coverage/cobertura-coverage\\.xml', 'target/site/.*', 'combined_junit.xml', 'build-info-effective\\.yaml', 'lighthouse-report\\.json', 'junit\\.xml', 'checkstyle-result\\.xml', 'target/site/whitesource/.*', '_library_version', 'failsafe-reports/.*\\.xml'}

0 comments on commit 1ab666f

Please sign in to comment.