Note: This documentation is for the legacy command-line tool odasa.
The final version was released in May 2020. Support for this tool expires in May 2021.

For documentation on the new generation CodeQL CLI, see CodeQL CLI .
In particular, you may find the Notes for legacy QL CLI users useful in planning your migration.

Skip to end of metadata
Go to start of metadata

This topic describes how to use query directives to assign a threshold to a metric query, so that it reports an alert.


Metric queries calculate a numerical result related to a particular property of the project that you are analyzing. For example, metric queries can calculate the size of your project by counting the number of lines of code, the number of comments or the number of statements. You can also use metric queries to measure the complexity of a function by calculating, for example, the number of execution paths through it. Metrics generate alerts when you set appropriate thresholds for the results, using Query directives. Metric alerts are typically used to indicate problems or highlight bad coding practise. For further information on the built in metrics and alerts, see Built-in queries.

Defining thresholds using conversion directives

You can generate alerts using metric queries, using a conversion directive. A conversion directive is a type of query directive that defines the conditions that the result output of a metric query must meet in order to generate an alert. Metric queries support the following conversion directives:




<number>@recommendation-from 3.4

All values higher than or equal to the value will generate an alert (type recommendation)


<number>@recommendation-to 3.3

All values lower than or equal to the value will generate an alert (type recommendation)


<number>@warning-from 5

All values higher than or equal to the value will generate an alert (type warning)


<number>@warning-to 4

All values less than or equal to the value will generate an alert (type warning)


<number>@error-from 2

All values higher than or equal to the value will generate an alert (type error)


<number>@error-from 1.9
All values less than or equal to x will generate an alert (type error)


Query directives must be defined immediately after the metric query that they act on, and each directive must appear on a separate line. There are several examples in the standard query suites, where conversion directives are used to convert metrics to alerts. In the example below, some of the the standard maintainability metrics for Python have thresholds defined, in order to generate alerts:

Examples of metrics used as rules
+ semmlecode-python-queries/Metrics/FLinesOfCode.ql: /Maintainability/Size
    @warning-from 500
+ semmlecode-python-queries/Metrics/FFunctionsAndMethods.ql: /Maintainability/Size
    @warning-from 60
+ semmlecode-python-queries/Metrics/FClasses.ql: /Maintainability/Size
    @warning-from 10

When you analyze a snapshot using metric queries that are subject to thresholds, formatted alerts (which include a warning message and an output value for the metric) will be reported where appropriate. As with normal alerts, you can integrate the results into a code review tool as part of your revision assessment process.


  • No labels