Skip to content

Commit 1142b77

Browse files
committed
Update articles for other languages
1 parent 0def31a commit 1142b77

19 files changed

+119
-186
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ To exclude ``if`` statements that have an ``else`` branch:
112112
block.isEmpty() and
113113
not exists(ifstmt.getElse())
114114
115-
#. Click **Run**.
115+
#. Re-run the query.
116116

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ To exclude these values:
113113
not recv.getType() instanceof PointerType and
114114
not exists(ReturnStmt ret | ret.getExpr() = recv.getARead().asExpr())
115115
116-
#. Click **Run**.
116+
#. Re-run the query.
117117

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

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

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,65 +31,36 @@ or Kotlin code such as:
3131
In either case, replacing ``s.equals("")`` with ``s.isEmpty()``
3232
would be more efficient.
3333

34-
Running the query
35-
-----------------
34+
.. include:: ../reusables/vs-code-basic-instructions/find-database.rst
3635

37-
#. 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>`__.
36+
Running a quick query
37+
---------------------
3838

39-
#. Click the project in the search results.
39+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-1.rst
4040

41-
#. Click **Query this project**.
42-
43-
This opens the query console. (For information about using this, see `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.)
44-
45-
.. pull-quote::
46-
47-
Note
48-
49-
Alternatively, you can go straight to the query console by clicking **Query console** (at the top of any page), selecting **Java** from the **Language** drop-down list, then choosing one or more projects to query from those displayed in the **Project** drop-down list.
50-
51-
#. Copy the following query into the text box in the query console:
41+
#. In the quick query tab, delete ``select ""`` and paste the following query beneath the import statement ``import java``.
5242

5343
.. code-block:: ql
5444
55-
import java
56-
57-
from MethodAccess ma
58-
where
59-
ma.getMethod().hasName("equals") and
60-
ma.getArgument(0).(StringLiteral).getValue() = ""
61-
select ma, "This comparison to empty string is inefficient, use isEmpty() instead."
45+
from MethodAccess ma
46+
where
47+
ma.getMethod().hasName("equals") and
48+
ma.getArgument(0).(StringLiteral).getValue() = ""
49+
select ma, "This comparison to empty string is inefficient, use isEmpty() instead."
6250
6351
Note that CodeQL treats Java and Kotlin as part of the same language, so even though this query starts with ``import java``, it will work for both Java and Kotlin code.
6452

65-
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.
66-
67-
#. Click **Run**.
68-
69-
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:
70-
71-
.. image:: ../images/query-progress.png
72-
:align: center
73-
74-
.. pull-quote::
53+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-2.rst
7554

76-
Note
55+
.. image:: ../images/codeql-for-visual-studio-code/basic-java-query-results-1.png
56+
:align: center
7757

78-
Your query is always run against the most recently analyzed commit to the selected project.
58+
If any matching code is found, click a link in the ``ma`` column to view the ``.equals`` expression in the code viewer.
7959

80-
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 ``ma`` and is linked to the location in the source code of the project where ``ma`` occurs. The second column is the alert message.
60+
basic-java-query-results-2.png
61+
:align: center
8162

82-
➤ `Example query results <https://lgtm.com/query/6863787472564633674/>`__
83-
84-
.. pull-quote::
85-
86-
Note
87-
88-
An ellipsis (…) at the bottom of the table indicates that the entire list is not displayed—click it to show more results.
89-
90-
#. If any matching code is found, click a link in the ``ma`` column to view the ``.equals`` expression in the code viewer.
91-
92-
The matching ``.equals`` expression 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.
63+
.. include:: ../reusables/vs-code-basic-instructions/note-store-quick-query.rst
9364

9465
About the query structure
9566
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -150,14 +121,24 @@ In this case, it is not possible to simply use ``o.isEmpty()`` instead, as ``o``
150121
ma.getMethod().hasName("equals") and
151122
ma.getArgument(0).(StringLiteral).getValue() = ""
152123
153-
#. Click **Run**.
124+
#. Re-run the query.
154125

155126
There are now fewer results because ``.equals`` expressions with different types are no longer included.
156127

157-
➤ `See this in the query console <https://lgtm.com/query/3716567543394265485/>`__
158-
159128
Further reading
160129
---------------
161130

162131
.. include:: ../reusables/java-further-reading.rst
163132
.. include:: ../reusables/codeql-ref-tools-further-reading.rst
133+
134+
.. Article-specific substitutions for the reusables used in docs/codeql/reusables/vs-code-basic-instructions
135+
136+
.. |language-text| replace:: Java
137+
138+
.. |language-code| replace:: ``java``
139+
140+
.. |example-url| replace:: hhttps://github.com/apache/activemq
141+
142+
.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-java.png
143+
144+
.. |result-col-1| replace:: The first column corresponds to the expression ``ma`` and is linked to the location in the source code of the project where ``ma`` occurs.

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

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Basic query for JavaScript 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
---------------
@@ -12,62 +14,33 @@ In JavaScript, any expression can be turned into an expression statement. While
1214

1315
The query you will run finds instances of this problem. The query searches for expressions ``e`` that are pure—that is, their evaluation does not lead to any side effects—but appear as an expression statement.
1416

15-
Running the query
16-
-----------------
17-
18-
#. 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>`__.
19-
20-
#. Click the project in the search results.
21-
22-
#. Click **Query this project**.
23-
24-
This opens the query console. (For information about using this, see `Using the query console <https://lgtm.com/help/lgtm/using-query-console>`__.)
25-
26-
.. pull-quote::
17+
.. include:: ../reusables/vs-code-basic-instructions/find-database.rst
2718

28-
Note
19+
Running a quick query
20+
---------------------
2921

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

32-
#. Copy the following query into the text box in the query console:
24+
#. In the quick query tab, delete ``select ""`` and paste the following query beneath the import statement ``import javascript``.
3325

3426
.. code-block:: ql
3527
36-
import javascript
37-
3828
from Expr e
3929
where e.isPure() and
4030
e.getParent() instanceof ExprStmt
4131
select e, "This expression has no effect."
4232
43-
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.
44-
45-
#. Click **Run**.
46-
47-
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:
48-
49-
.. image:: ../images/query-progress.png
50-
:align: center
51-
52-
.. pull-quote::
53-
54-
Note
33+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-2.rst
5534

56-
Your query is always run against the most recently analyzed commit to the selected project.
35+
.. image:: ../images/codeql-for-visual-studio-code/basic-js-query-results-1.png
36+
:align: center
5737

58-
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 ``e`` and is linked to the location in the source code of the project where ``e`` occurs. The second column is the alert message.
38+
If any matching code is found, click one of the links in the ``e`` column to view the expression in the code viewer.
5939

60-
➤ `Example query results <https://lgtm.com/query/5137013631828816943/>`__
40+
.. image:: ../images/codeql-for-visual-studio-code/basic-js-query-results-2.png
41+
:align: center
6142

62-
.. pull-quote::
63-
64-
Note
65-
66-
An ellipsis (…) at the bottom of the table indicates that the entire list is not displayed—click it to show more results.
67-
68-
#. If any matching code is found, click one of the links in the ``e`` column to view the expression in the code viewer.
69-
70-
The matching 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.
43+
.. include:: ../reusables/vs-code-basic-instructions/note-store-quick-query.rst
7144

7245
About the query structure
7346
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -119,11 +92,14 @@ To remove directives from the results:
11992
e.getParent() instanceof ExprStmt and
12093
not e.getParent() instanceof Directive
12194
122-
#. Click **Run**.
95+
#. Re-run the query.
12396

12497
There are now fewer results as ``use strict`` directives are no longer reported.
12598

126-
The improved query finds several results on the example project including `this result <https://lgtm.com/projects/g/ajaxorg/ace/rev/ad50673d7137c09d1a5a6f0ef83633a149f9e3d1/files/lib/ace/keyboard/vim.js#L320>`__:
99+
The improved query finds several results on the example project including the result below:
100+
101+
.. image:: ../images/codeql-for-visual-studio-code/basic-js-query-results-1.png
102+
:align: center
127103

128104
.. code-block:: javascript
129105
@@ -136,3 +112,15 @@ Further reading
136112

137113
.. include:: ../reusables/javascript-further-reading.rst
138114
.. include:: ../reusables/codeql-ref-tools-further-reading.rst
115+
116+
.. Article-specific substitutions for the reusables used in docs/codeql/reusables/vs-code-basic-instructions
117+
118+
.. |language-text| replace:: JavaScript/TypeScript
119+
120+
.. |language-code| replace:: ``javascript``
121+
122+
.. |example-url| replace:: https://github.com/ajaxorg/ace
123+
124+
.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-js.png
125+
126+
.. |result-col-1| replace:: The first column corresponds to the expression ``e`` and is linked to the location in the source code of the project where ``e`` occurs.

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

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Basic query for Python 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,31 @@ The query we're going to run performs a basic search of the code for ``if`` stat
1416
1517
if error: pass
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+
Running a quick query
20+
---------------------
2921

30-
Note
22+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-1.rst
3123

32-
Alternatively, you can go straight to the query console by clicking **Query console** (at the top of any page), selecting **Python** from the **Language** drop-down list, then choosing one or more projects to query from those displayed in the **Project** drop-down list.
33-
34-
#. Copy the following query into the text box in the query console:
24+
#. In the quick query tab, delete ``select ""`` and paste the following query beneath the import statement ``import python``.
3525

3626
.. code-block:: ql
3727
38-
import python
39-
4028
from If ifstmt, Stmt pass
4129
where pass = ifstmt.getStmt(0) and
4230
pass instanceof Pass
4331
select ifstmt, "This 'if' statement is redundant."
4432
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::
33+
.. include:: ../reusables/vs-code-basic-instructions/run-quick-query-2.rst
5534

56-
Note
35+
.. image:: ../images/codeql-for-visual-studio-code/basic-python-query-results-1.png
36+
:align: center
5737

58-
Your query is always run against the most recently analyzed commit to the selected project.
38+
If any matching code is found, click a link in the ``ifstmt`` column to view the ``if`` statement in the code viewer.
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+
.. image:: ../images/codeql-for-visual-studio-code/basic-python-query-results-2.png
41+
:align: center
6142

62-
➤ `Example query results <https://lgtm.com/query/3592297537117272922/>`__
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.
43+
.. include:: ../reusables/vs-code-basic-instructions/note-store-quick-query.rst
7344

7445
About the query structure
7546
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -133,14 +104,24 @@ To exclude ``if`` statements that have an ``else`` branch:
133104
pass instanceof Pass and
134105
not exists(ifstmt.getOrelse())
135106
136-
#. Click **Run**.
107+
#. Re-run the query.
137108

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

140-
➤ `See this in the query console <https://lgtm.com/query/3424727946018612474/>`__
141-
142111
Further reading
143112
---------------
144113

145114
.. include:: ../reusables/python-further-reading.rst
146115
.. include:: ../reusables/codeql-ref-tools-further-reading.rst
116+
117+
.. Article-specific substitutions for the reusables used in docs/codeql/reusables/vs-code-basic-instructions
118+
119+
.. |language-text| replace:: Python
120+
121+
.. |language-code| replace:: ``python``
122+
123+
.. |example-url| replace:: https://github.com/saltstack/salt
124+
125+
.. |image-quick-query| image:: ../images/codeql-for-visual-studio-code/quick-query-tab-python.png
126+
127+
.. |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.

0 commit comments

Comments
 (0)