Skip to content

Commit c7725ec

Browse files
authored
Merge pull request github#11605 from github/smowton/admin/merge-2.11.5-into-rc38
Merge codeql-cli-2.11.5 into rc/3.8
2 parents 50c85f6 + 3249485 commit c7725ec

File tree

57 files changed

+1083
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1083
-418
lines changed

docs/codeql/codeql-language-guides/basic-query-for-cpp-code.rst

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Basic query for C and C++ code
44
==============================
55

6-
Learn to write and run a simple CodeQL query using LGTM.
6+
Learn to write and run a simple CodeQL query using Visual Studio Code with the CodeQL extension.
7+
8+
.. include:: ../reusables/vs-code-basic-instructions/setup-to-run-queries.rst
79

810
About the query
911
---------------
@@ -14,62 +16,33 @@ The query we're going to run performs a basic search of the code for ``if`` stat
1416
1517
if (error) { }
1618
17-
Running the query
18-
-----------------
19-
20-
#. In the main search box on LGTM.com, search for the project you want to query. For tips, see `Searching <https://lgtm.com/help/lgtm/searching>`__.
21-
22-
#. Click the project in the search results.
23-
24-
#. Click **Query this project**.
25-
26-
This opens the query console. (For information about using this, see `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.)
27-
28-
.. pull-quote::
19+
.. include:: ../reusables/vs-code-basic-instructions/find-database.rst
2920

30-
Note
21+
Running a quick query
22+
---------------------
3123

32-
Alternatively, you can go straight to the query console by clicking **Query console** (at the top of any page), selecting **C/C++** from the **Language** drop-down list, then choosing one or more projects to query from those displayed in the **Project** drop-down list.
24+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-1.rst
3325

34-
#. Copy the following query into the text box in the query console:
26+
#. In the quick query tab, delete ``select ""`` and paste the following query beneath the import statement ``import cpp``.
3527

3628
.. code-block:: ql
3729
38-
import cpp
39-
4030
from IfStmt ifstmt, BlockStmt block
4131
where ifstmt.getThen() = block and
4232
block.getNumStmt() = 0
4333
select ifstmt, "This 'if' statement is redundant."
4434
45-
LGTM checks whether your query compiles and, if all is well, the **Run** button changes to green to indicate that you can go ahead and run the query.
46-
47-
#. Click **Run**.
48-
49-
The name of the project you are querying, and the ID of the most recently analyzed commit to the project, are listed below the query box. To the right of this is an icon that indicates the progress of the query operation:
50-
51-
.. image:: ../images/query-progress.png
52-
:align: center
53-
54-
.. pull-quote::
55-
56-
Note
35+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-2.rst
5736

58-
Your query is always run against the most recently analyzed commit to the selected project.
37+
.. image:: ../images/codeql-for-visual-studio-code/basic-cpp-query-results-1.png
38+
:align: center
5939

60-
The query will take a few moments to return results. When the query completes, the results are displayed below the project name. The query results are listed in two columns, corresponding to the two expressions in the ``select`` clause of the query. The first column corresponds to the expression ``ifstmt`` and is linked to the location in the source code of the project where ``ifstmt`` occurs. The second column is the alert message.
40+
If any matching code is found, click a link in the ``ifstmt`` column to open the file and highlight the matching ``if`` statement.
6141

62-
➤ `Example query results <https://lgtm.com/query/4242591143131494898/>`__
42+
.. image:: ../images/codeql-for-visual-studio-code/basic-cpp-query-results-2.png
43+
:align: center
6344

64-
.. pull-quote::
65-
66-
Note
67-
68-
An ellipsis (…) at the bottom of the table indicates that the entire list is not displayed—click it to show more results.
69-
70-
#. If any matching code is found, click a link in the ``ifstmt`` column to view the ``if`` statement in the code viewer.
71-
72-
The matching ``if`` statement is highlighted with a yellow background in the code viewer. If any code in the file also matches a query from the standard query library for that language, you will see a red alert message at the appropriate point within the code.
45+
.. include:: ../reusables/vs-code-basic-instructions/note-store-quick-query.rst
7346

7447
About the query structure
7548
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -120,7 +93,7 @@ In this case, identifying the ``if`` statement with the empty ``then`` branch as
12093

12194
To exclude ``if`` statements that have an ``else`` branch:
12295

123-
#. Extend the ``where`` clause to include the following extra condition:
96+
#. Edit your query and extend the ``where`` clause to include the following extra condition:
12497

12598
.. code-block:: ql
12699
@@ -134,14 +107,24 @@ To exclude ``if`` statements that have an ``else`` branch:
134107
block.getNumStmt() = 0 and
135108
not ifstmt.hasElse()
136109
137-
#. Click **Run**.
110+
#. Re-run the query.
138111

139112
There are now fewer results because ``if`` statements with an ``else`` branch are no longer reported.
140113

141-
➤ `See this in the query console <https://lgtm.com/query/1899933116489579248/>`__
142-
143114
Further reading
144115
---------------
145116

146117
.. include:: ../reusables/cpp-further-reading.rst
147118
.. include:: ../reusables/codeql-ref-tools-further-reading.rst
119+
120+
.. Article-specific substitutions for the reusables used in docs/codeql/reusables/vs-code-basic-instructions
121+
122+
.. |language-text| replace:: C/C++
123+
124+
.. |language-code| replace:: ``cpp``
125+
126+
.. |example-url| replace:: https://github.com/protocolbuffers/protobuf
127+
128+
.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-cpp.png
129+
130+
.. |result-col-1| replace:: The first column corresponds to the expression ``ifstmt`` and is linked to the location in the source code of the project where ``ifstmt`` occurs.

docs/codeql/codeql-language-guides/basic-query-for-csharp-code.rst

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Basic query for C# code
44
=======================
55

6-
Learn to write and run a simple CodeQL query using LGTM.
6+
Learn to write and run a simple CodeQL query using Visual Studio Code with the CodeQL extension.
7+
8+
.. include:: ../reusables/vs-code-basic-instructions/setup-to-run-queries.rst
79

810
About the query
911
---------------
@@ -14,62 +16,33 @@ The query we're going to run performs a basic search of the code for ``if`` stat
1416
1517
if (error) { }
1618
17-
Running the query
18-
-----------------
19-
20-
#. In the main search box on LGTM.com, search for the project you want to query. For tips, see `Searching <https://lgtm.com/help/lgtm/searching>`__.
21-
22-
#. Click the project in the search results.
23-
24-
#. Click **Query this project**.
25-
26-
This opens the query console. (For information about using this, see `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.)
27-
28-
.. pull-quote::
19+
.. include:: ../reusables/vs-code-basic-instructions/find-database.rst
2920

30-
Note
21+
Running a quick query
22+
---------------------
3123

32-
Alternatively, you can go straight to the query console by clicking **Query console** (at the top of any page), selecting **C#** from the **Language** drop-down list, then choosing one or more projects to query from those displayed in the **Project** drop-down list.
24+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-1.rst
3325

34-
#. Copy the following query into the text box in the query console:
26+
#. In the quick query tab, delete ``select ""`` and paste the following query beneath the import statement ``import csharp``.
3527

3628
.. code-block:: ql
3729
38-
import csharp
39-
4030
from IfStmt ifstmt, BlockStmt block
4131
where ifstmt.getThen() = block and
4232
block.isEmpty()
4333
select ifstmt, "This 'if' statement is redundant."
4434
45-
LGTM checks whether your query compiles and, if all is well, the **Run** button changes to green to indicate that you can go ahead and run the query.
46-
47-
#. Click **Run**.
48-
49-
The name of the project you are querying, and the ID of the most recently analyzed commit to the project, are listed below the query box. To the right of this is an icon that indicates the progress of the query operation:
50-
51-
.. image:: ../images/query-progress.png
52-
:align: center
53-
54-
.. pull-quote::
35+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-2.rst
5536

56-
Note
37+
.. image:: ../images/codeql-for-visual-studio-code/basic-csharp-query-results-1.png
38+
:align: center
5739

58-
Your query is always run against the most recently analyzed commit to the selected project.
40+
If any matching code is found, click a link in the ``ifstmt`` column to open the file and highlight the matching ``if`` statement.
5941

60-
The query will take a few moments to return results. When the query completes, the results are displayed below the project name. The query results are listed in two columns, corresponding to the two expressions in the ``select`` clause of the query. The first column corresponds to the expression ``ifstmt`` and is linked to the location in the source code of the project where ``ifstmt`` occurs. The second column is the alert message.
42+
.. image:: ../images/codeql-for-visual-studio-code/basic-csharp-query-results-2.png
43+
:align: center
6144

62-
➤ `Example query results <https://lgtm.com/query/1214010107827821393/>`__
63-
64-
.. pull-quote::
65-
66-
Note
67-
68-
An ellipsis (…) at the bottom of the table indicates that the entire list is not displayed—click it to show more results.
69-
70-
#. If any matching code is found, click a link in the ``ifstmt`` column to view the ``if`` statement in the code viewer.
71-
72-
The matching ``if`` statement is highlighted with a yellow background in the code viewer. If any code in the file also matches a query from the standard query library for that language, you will see a red alert message at the appropriate point within the code.
45+
.. include:: ../reusables/vs-code-basic-instructions/note-store-quick-query.rst
7346

7447
About the query structure
7548
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -139,14 +112,23 @@ To exclude ``if`` statements that have an ``else`` branch:
139112
block.isEmpty() and
140113
not exists(ifstmt.getElse())
141114
142-
#. Click **Run**.
115+
#. Re-run the query.
143116

144117
There are now fewer results because ``if`` statements with an ``else`` branch are no longer included.
145118

146-
➤ `See this in the query console <https://lgtm.com/query/6233102733683510530/>`__
147-
148119
Further reading
149120
---------------
150121

151122
.. include:: ../reusables/csharp-further-reading.rst
152123
.. include:: ../reusables/codeql-ref-tools-further-reading.rst
124+
125+
.. Article-specific substitutions for the reusables used in docs/codeql/reusables/vs-code-basic-instructions
126+
.. |language-text| replace:: C#
127+
128+
.. |language-code| replace:: ``csharp``
129+
130+
.. |example-url| replace:: https://github.com/PowerShell/PowerShell
131+
132+
.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-csharp.png
133+
134+
.. |result-col-1| replace:: The first column corresponds to the expression ``ifstmt`` and is linked to the location in the source code of the project where ``ifstmt`` occurs.

docs/codeql/codeql-language-guides/basic-query-for-go-code.rst

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Basic query for Go code
44
=======================
55

6-
Learn to write and run a simple CodeQL query using LGTM.
6+
Learn to write and run a simple CodeQL query using Visual Studio Code with the CodeQL extension.
7+
8+
.. include:: ../reusables/vs-code-basic-instructions/setup-to-run-queries.rst
79

810
About the query
911
---------------
@@ -22,64 +24,35 @@ This is problematic because the receiver argument is passed by value, not by ref
2224
2325
For further information on using methods on values or pointers in Go, see the `Go FAQ <https://golang.org/doc/faq#methods_on_values_or_pointers>`__.
2426

25-
Running the query
26-
-----------------
27-
28-
#. In the main search box on LGTM.com, search for the project you want to query. For tips, see `Searching <https://lgtm.com/help/lgtm/searching>`__.
29-
30-
#. Click the project in the search results.
31-
32-
#. Click **Query this project**.
33-
34-
This opens the query console. (For information about using this, see `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.)
35-
36-
.. pull-quote::
27+
.. include:: ../reusables/vs-code-basic-instructions/find-database.rst
3728

38-
Note
29+
Running a quick query
30+
---------------------
3931

40-
Alternatively, you can go straight to the query console by clicking **Query console** (at the top of any page), selecting **Go** from the **Language** drop-down list, then choosing one or more projects to query from those displayed in the **Project** drop-down list.
32+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-1.rst
4133

42-
#. Copy the following query into the text box in the query console:
34+
#. In the quick query tab, delete ``select ""`` and paste the following query beneath the import statement ``import go``.
4335

4436
.. code-block:: ql
4537
46-
import go
47-
4838
from Method m, Variable recv, Write w, Field f
4939
where
5040
recv = m.getReceiver() and
5141
w.writesField(recv.getARead(), f, _) and
5242
not recv.getType() instanceof PointerType
5343
select w, "This update to " + f + " has no effect, because " + recv + " is not a pointer."
5444
55-
LGTM checks whether your query compiles and, if all is well, the **Run** button changes to green to indicate that you can go ahead and run the query.
56-
57-
#. Click **Run**.
58-
59-
The name of the project you are querying, and the ID of the most recently analyzed commit to the project, are listed below the query box. To the right of this is an icon that indicates the progress of the query operation:
60-
61-
.. image:: ../images/query-progress.png
62-
:align: center
63-
64-
.. pull-quote::
65-
66-
Note
45+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-2.rst
6746

68-
Your query is always run against the most recently analyzed commit to the selected project.
47+
.. image:: ../images/codeql-for-visual-studio-code/basic-go-query-results-1.png
48+
:align: center
6949

70-
The query will take a few moments to return results. When the query completes, the results are displayed below the project name. The query results are listed in two columns, corresponding to the two expressions in the ``select`` clause of the query. The first column corresponds to ``w``, which is the location in the source code where the receiver ``recv`` is modified. The second column is the alert message.
50+
If any matching code is found, click a link in the ``w`` column to open the file and highlight the matching location.
7151

72-
➤ `Example query results <https://lgtm.com/query/6221190009056970603/>`__
52+
.. image:: ../images/codeql-for-visual-studio-code/basic-go-query-results-2.png
53+
:align: center
7354

74-
.. pull-quote::
75-
76-
Note
77-
78-
An ellipsis (…) at the bottom of the table indicates that the entire list is not displayed—click it to show more results.
79-
80-
#. If any matching code is found, click a link in the ``w`` column to view it in the code viewer.
81-
82-
The matching ``w`` is highlighted with a yellow background in the code viewer. If any code in the file also matches a query from the standard query library for that language, you will see a red alert message at the appropriate point within the code.
55+
.. include:: ../reusables/vs-code-basic-instructions/note-store-quick-query.rst
8356

8457
About the query structure
8558
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -140,14 +113,24 @@ To exclude these values:
140113
not recv.getType() instanceof PointerType and
141114
not exists(ReturnStmt ret | ret.getExpr() = recv.getARead().asExpr())
142115
143-
#. Click **Run**.
116+
#. Re-run the query.
144117

145118
There are now fewer results because value methods that return their receiver variable are no longer reported.
146119

147-
➤ `See this in the query console <https://lgtm.com/query/9110448975027954322/>`__
148-
149120
Further reading
150121
---------------
151122

152123
.. include:: ../reusables/go-further-reading.rst
153124
.. include:: ../reusables/codeql-ref-tools-further-reading.rst
125+
126+
.. Article-specific substitutions for the reusables used in docs/codeql/reusables/vs-code-basic-instructions
127+
128+
.. |language-text| replace:: Go
129+
130+
.. |language-code| replace:: ``go``
131+
132+
.. |example-url| replace:: https://github.com/go-gorm/gorm
133+
134+
.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-go.png
135+
136+
.. |result-col-1| replace:: The first column corresponds to ``w``, which is the location in the source code where the receiver ``recv`` is modified.

0 commit comments

Comments
 (0)