You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a guided introduction to CodeQL, we've created a `CodeQL template [Beta]<https://github.com/codespaces/new?template_repository=github/codeql-codespaces-template>`__ in GitHub Codespaces. You can use this template to test CodeQL concepts. However, if you would like to run CodeQL queries on code, you will need to install the CodeQL extension in Visual Studio Code. For instructions, see ":ref:`Setting up CodeQL in Visual Studio Code <setting-up-codeql-in-visual-studio-code>`."
Copy file name to clipboardExpand all lines: docs/codeql/writing-codeql-queries/introduction-to-ql.rst
+6-16Lines changed: 6 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,12 +14,12 @@ QL is a logic programming language, so it is built up of logical formulas. QL us
14
14
15
15
QL also supports recursion and aggregates. This allows you to write complex recursive queries using simple QL syntax and directly use aggregates such as ``count``, ``sum``, and ``average``.
You can try out the following examples and exercises using :ref:`CodeQL for VS Code <codeql-for-visual-studio-code>`, or you can run them in GitHub Codespaces using the `CodeQL template <https://github.com/codespaces/new?template_repository=github/codeql-codespaces-template>`__. This will open a GitHub Codespaces environment preconfigured to run CodeQL queries.
21
-
22
-
Once you open the GitHub Codespaces template, follow the instructions in the README to take a code tour and learn how to run queries in the workspace.
22
+
You can try out the following examples and exercises using :ref:`CodeQL for VS Code <codeql-for-visual-studio-code>`.
23
23
24
24
Here is an example of a basic query:
25
25
@@ -94,8 +94,6 @@ The exercises above all show queries with exactly one result, but in fact many q
To simplify the query, we can introduce a class ``SmallInt`` representing the integers between 1 and 10. We can also define a predicate ``square()`` on integers in that class. Defining classes and predicates in this way makes it easy to reuse code without having to repeat it every time.
100
98
101
99
.. code-block:: ql
@@ -109,8 +107,6 @@ To simplify the query, we can introduce a class ``SmallInt`` representing the in
@@ -130,9 +126,7 @@ To import the CodeQL library for a specific programming language, type ``import
130
126
where count(f.getAnArg()) > 7
131
127
select f
132
128
133
-
➤ The ``from`` clause defines a variable ``f`` representing a Python function. The ``where`` part limits the functions ``f`` to those with more than 7 arguments. Finally, the ``select`` clause lists these functions.
The ``from`` clause defines a variable ``f`` representing a Python function. The ``where`` part limits the functions ``f`` to those with more than 7 arguments. Finally, the ``select`` clause lists these functions.
136
130
137
131
.. code-block:: ql
138
132
@@ -142,9 +136,7 @@ To import the CodeQL library for a specific programming language, type ``import
142
136
where c.getText().regexpMatch("(?si).*\\bTODO\\b.*")
143
137
select c
144
138
145
-
➤ The ``from`` clause defines a variable ``c`` representing a JavaScript comment. The ``where`` part limits the comments ``c`` to those containing the word ``"TODO"``. The ``select`` clause lists these comments.
The ``from`` clause defines a variable ``c`` representing a JavaScript comment. The ``where`` part limits the comments ``c`` to those containing the word ``"TODO"``. The ``select`` clause lists these comments.
148
140
149
141
.. code-block:: ql
150
142
@@ -154,9 +146,7 @@ To import the CodeQL library for a specific programming language, type ``import
154
146
where not exists(p.getAnAccess())
155
147
select p
156
148
157
-
➤ The ``from`` clause defines a variable ``p`` representing a Java parameter. The ``where`` clause finds unused parameters by limiting the parameters ``p`` to those which are not accessed. Finally, the ``select`` clause lists these parameters.
The ``from`` clause defines a variable ``p`` representing a Java parameter. The ``where`` clause finds unused parameters by limiting the parameters ``p`` to those which are not accessed. Finally, the ``select`` clause lists these parameters.
0 commit comments