GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Simplify Report API · Issue #1962 · pmd/pmd

[core] Simplify Report API #1962

New issue
Copy link
New issue
Copy link
Closed
#2680
Closed
[core] Simplify Report API#1962
#2680
Copy link
Milestone
6.27.0

Description

@oowekyala
oowekyala
opened on Aug 4, 2019
Issue body actions

Summary of discussion with @pzygielo on #1960:

  • Report::size/getNumViolations needs a comment because it's the size of the iterator
  • Report::isEmpty doesn't necessarily mean that there are some violations, which is counter-intuitive (it considers violations and processing errors).

So maybe isEmpty is badly named. However it looks like the issue is a bit bigger. The isEmpty method is useless on its own, as it doesn't say anything about either the size of iterator() or of errors(), since the results are merged. It also doesn't take config errors into account which undermines its only usefulness (maybe checking that there is nothing to report, but with this implementation there can still be config errors). So you can't derive anything useful from a method call to isEmpty and will need another check (either hasErrors, or hasNext on the iterator, or a zero size() check).

So probably, isEmpty shouldn't even exist. But maybe the problem is even bigger.
The Report class appears to try being three lists at a time, as evidenced by the following methods:

  • boolean isEmpty()
  • boolean hasErrors()
  • boolean hasConfigErrors()
  • (notice no hasViolations)
  • Iterator<RuleViolation> iterator()
  • Iterator<ProcessingError> errors()
  • Iterator<ConfigurationError> configErrors()
  • int size()
  • (notice no numErrors or numConfigErrors)

I shouldn't be mentioning the ReportTree and Metric methods, because they're supposed to be deprecated, but they aren't for now so let's just make a list to deprecate them later:

  • treeIterator(), treeIsEmpty(), treeSize()
  • metrics(), hasMetrics()

So Report attempts to be 5 collections at a time and does a meh job of it, because the API is assymmetric and very rudimentary.

I think making Report expose those collections independently would be a big upgrade to that API. We could replace all the above-mentioned methods by just

  • List<RuleViolation> getViolations()
  • List<ProcessingError> getProcessingErrors()
  • List<ConfigurationError> getConfigErrors()

This would reduce greatly the API surface we have to maintain while improving the API available to users. Besides, since Report is implemented with Lists internally, it would be trivial to implement.

Making this change would supersede #1960

Should we do that?

Activity

  1. oowekyala
    added this to the 7.0.0 milestone on Aug 4, 2019
  2. adangel commented on Aug 10, 2019

    @adangel
    adangel
    on Aug 10, 2019
    Member
    More actions

    I think, this makes sense. However, this is just a very tiny part of the API and I don't know yet, whether this fits into the bigger picture of "Programmatic API" (https://github.com/pmd/pmd/wiki/PMD-7.0.0).

  3. jsotuyod commented on Aug 18, 2019

    @jsotuyod
    jsotuyod
    on Aug 18, 2019
    Member
    More actions

    I support the proposed refactor. We should make sure the returned collections are read-only.

    I also think the current logic to apply // NOPMD suppressions should be removed from Report, and have it in the same place were we apply @SuppressWarnings suppressions.

  4. oowekyala commented on Aug 19, 2019

    @oowekyala
    oowekyala
    on Aug 19, 2019
    MemberAuthor
    More actions

    @jsotuyod Cool

    I also think the current logic to apply // NOPMD suppressions should be removed from Report, and have it in the same place were we apply @SuppressWarnings suppressions.

    In fact I recently did something to simplify violation suppression. It removes a lot of duplication and treats // NOPMD, @SuppressWarnings, violationSuppressXPath and violationSuppressRegex uniformly (they're extensible too) for very little trouble. This also might improve reports, which for now only consider that violations may be suppressed through comment or annotation...

    Eg

    pmd/pmd-core/src/main/java/net/sourceforge/pmd/renderers/HTMLRenderer.java

    Line 177 in fac5604

    + "<th>File</th><th>Line</th><th>Rule</th><th>NOPMD or Annotation</th><th>Reason</th></tr>" + PMD.EOL);

    The current version I have depends on #1927 though

  5. adangel
    modified the milestones: 7.0.0, 6.27.0 on Aug 2, 2020
  6. adangel
    closed this as completedin 0f4b118on Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.27.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.