Skip to content

Add ranked "and n more" reporting module #26

Description

@MichaelRFairhurst

I just wrote the following:

from IncompleteInitialization init, CheckedField f, int total, int ranked, string suffix
where
  not isExcluded(init, Classes4Package::nonStaticMemberNotInitBeforeUseQuery()) and
  total = count(init.getField()) and
  f =
    rank[ranked](Field candidate |
      candidate = init.getField()
    |
      candidate order by candidate.getName()
    ) and
  ranked <= 3 and
  if total > 1 then suffix = " (and " + (total - 1) + " more)" else suffix = ""
select init, init.getKindStr() + " does not initialize non-static data member $@" + suffix + ".", f,
  f.getName()

And realized this should be part of qtil using a module.

The module should probably look something like:

// signature
signature module LimitResultsConfigSig {
  predicate finding(x, y, string)
  string message(x, y, string remaining);
  string orderBy(x)
  int maxResults()
}

// usage
module LimitIncompleteInitConfig implements LimitResultsConfigSig {
  predicate problem(IncompleteInitialization init, Field f) {
    f = init.getField()
  }
  string message(IncompleteInitialization init, Field f, string remainingStr) {
    result = init.getKindStr() + " does not initialize $@" + remainingStr + "."
  }
  int maxResults() { results = 3 }
  string orderBy(Field f) { result = f.getName() }
}

import LimitResults<LimitIncompleteInitConfig>

This may be implementable in common, or it may need to be implemented in the language packs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions