qtil
advanced-security/qtil-swift 0.0.3
Search

Module QlFormat

A module that offers a way of formatting CodeQL query messages in a consistent way, with varying numbers of placeholders, via a template-like syntax. This module is useful for writing more user-friendly messages for certain types of queries, with a cleaner query implementation.

Typically, this module should not be instantiated by library consumers directly, but rather should be imported from the language specific qtil pack, such as qtil-cpp or qtil-java.

To add support for a new language, you can create a module that implements the LocatableConfig module signature, that defines the Locatable class for that language.

QlFormat can be used as follows:

import qtil.Cpp // or qtil.Java, etc.

// Define a problem predicate for a Locatable and a Qtil::Template:
predicate problem(Locatable elem, Qtil::Template template) {
  exists(Variable var, FunctionCall fc |
    var = elem and
    fc = var.getInitializer().getAChild*() and
    template = Qtil::tpl("Initializer of variable '{name}' calls {fn}.")
      .text("name", var.getName())
      .link("fn", fc.getFunction().getName(), fc.getFunction())
  )
}

// Import the Problem::Query module:
import Qtil::Problem<problem/2>::Query

The resulting query results will insert the variable name into the alert message, and insert a placeholder link from the function name to the function itself.

Import path

import qtil.format.QLFormat

Predicates

tpl

A function to create a template string with the given format.

Classes

Template

A template class that allows for creating formatted strings with links and text replacements.

Modules

Problem

A module that allows the creation of “problems” with Template strings, and exposes a submodule Query to turn those problems into query results.

Parameters