Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locationChunks in CppCheck are reported as individual violations #54

Closed
uhafner opened this issue Jan 22, 2019 · 9 comments
Closed

locationChunks in CppCheck are reported as individual violations #54

uhafner opened this issue Jan 22, 2019 · 9 comments

Comments

@uhafner
Copy link
Contributor

uhafner commented Jan 22, 2019

I'm using your CppCheck parser in Jenkins Warnings plugin to read cppcheck files. In your parser you are converting each "location" of the original error structure to a violation. Actually each error should be converted to one violation only. Your violations should also provide a concept of multiple locations per violation (see SonarQube or Warning Plugin for an example).

See original Jenkins bug report.

@uhafner
Copy link
Contributor Author

uhafner commented Jan 23, 2019

See discussion in https://issues.jenkins-ci.org/browse/JENKINS-55733.

@uhafner uhafner closed this as completed Jan 23, 2019
@uhafner uhafner reopened this Feb 7, 2019
@uhafner
Copy link
Contributor Author

uhafner commented Feb 7, 2019

The discussion in the Jenkins issue seems to indicate, that each toplevel warning in the issue is the thing that should be counted.

@uhafner
Copy link
Contributor Author

uhafner commented Feb 20, 2019

Do you think this is feasible? This will require changes in the API.

@tomasbjerre
Copy link
Owner

tomasbjerre commented Feb 20, 2019

This library finds the id of each error and uses that as "rule" which is available on each Violation. Which means you can transform the list from the lib to a map of with one list per error. Does this help?

    final List<Violation> violationsList =
        violationsApi() //
            .withPattern(".*/cppcheck/example1\\.xml$") //
            .inFolder(rootFolder) //
            .findAll(CPPCHECK) //
            .violations();

    final Map<String, List<Violation>> violationsPerRule =
        violationsList
            .stream() //
            .collect(Collectors.groupingBy(Violation::getRule));
    assertThat(violationsPerRule) //
        .hasSize(2);
    assertThat(violationsPerRule.get("redundantAssignment")) //
        .hasSize(2);

@uhafner
Copy link
Contributor Author

uhafner commented Feb 21, 2019

I think that will work. Thanks for the help!

@uhafner
Copy link
Contributor Author

uhafner commented Feb 23, 2019

After thinking (or coding) it a little bit further I think that it does not work this way. The problem is that we can have multiple error tags using the same id (actually a bad name, id means rule id, it is not unique in the error tag).

tomasbjerre added a commit that referenced this issue Feb 24, 2019
@tomasbjerre
Copy link
Owner

Perhaps a group attribute can solve this?

    final List<Violation> violationsList =
        violationsApi() //
            .withPattern(".*/cppcheck/example1\\.xml$") //
            .inFolder(rootFolder) //
            .findAll(CPPCHECK) //
            .violations();

    final Map<String, List<Violation>> violationsPerGroupMap =
        violationsList
            .stream() //
            .collect(Collectors.groupingBy(Violation::getGroup));
    assertThat(violationsPerGroupMap) //
        .as("There are 2 error tags and there should be 2 groups identified.") //
        .hasSize(2);

So that in this example violationsPerGroupMap is a map with a key for each error tag and a value with a list of all location tags within that error tag.

@uhafner
Copy link
Contributor Author

uhafner commented Feb 24, 2019

Ok, that should work now 👍

@uhafner
Copy link
Contributor Author

uhafner commented Feb 26, 2019

Verified in jenkinsci/analysis-model@5e28d1b.

@uhafner uhafner closed this as completed Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants