About the QL language
QL is a declarative, object-oriented query language, optimized to analyze hierarchical data structures, in particular, databases representing source code. Since QL treats code as data, you can use simple QL queries to explore your code quickly and accurately. The basic syntax for a QL query will look familiar to anyone who has used SQL, but is used somewhat differently.
Its result is just the string
More complicated queries typically follow the following structure:
For example, the following query computes the number 42:
QL code can contain C-style comments. An end-of-line comment is introduced by "
//", and a (possibly multiline) delimited comment is introduced by "
/*" and terminated by "
The rules and metrics used by Semmle analysis are written using QL. This ensures that they can be extended or revised easily to keep up with changes in definitions of best coding practice. Every Semmle release includes improvements to existing rules as we work towards the ultimate goal of 100% precision. For details of the standard rules implemented by QL queries supplied by Semmle, see Semmle standard rules.
You can also write your own queries to identify code that breaks your team's guidelines for best practice or customize the default rules to accommodate a new framework.
If you are new to QL and want to start learning the language, see Learning QL.
This page gives an overview of available learning resources. These include introductory tutorials, practical suggestions for writing queries, and comprehensive reference topics.
There are a number of tools you can use to write and run QL queries locally and see the results of analyses:
- QL plugins and extensions—Plugins that allow you to easily integrate QL into your IDE.
- QL command-line tools—A collection of commands that let you analyze projects using QL queries.
For more background information about the QL language and how Semmle's analysis works, see the following topics:
- What is in a snapshot?—An overview of the process of how a snapshot is generated from source code.
- Introduction to QL—A technical introduction to QL, with references to related academic papers.
- Advanced topics—A list of topics on advanced uses of QL.
For any questions or feedback relating to documentation, please contact firstname.lastname@example.org. For any other support issues, please contact your organization's email@example.com email address. Using your organization's support address ensures that your message will be received as soon as possible by a member of our support team, even when the staff that you normally speak to are out of the office or on holiday.