Skip to content

Commit ae40b0a

Browse files
authored
Merge pull request github#11419 from github/felicitymay-8441-query-guides-javascript
LGTM deprecation: updates to CodeQL for JavaScript articles
2 parents 8eeba92 + 7e5a9fb commit ae40b0a

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

docs/codeql/codeql-language-guides/codeql-for-javascript.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Experiment and learn how to write effective and efficient queries for CodeQL dat
1818
abstract-syntax-tree-classes-for-working-with-javascript-and-typescript-programs
1919
data-flow-cheat-sheet-for-javascript
2020

21-
- :doc:`Basic query for JavaScript code <basic-query-for-javascript-code>`: Learn to write and run a simple CodeQL query using LGTM.
21+
- :doc:`Basic query for JavaScript code <basic-query-for-javascript-code>`: Learn to write and run a simple CodeQL query.
2222

2323
- :doc:`CodeQL library for JavaScript <codeql-library-for-javascript>`: When you're analyzing a JavaScript program, you can make use of the large collection of classes in the CodeQL library for JavaScript.
2424

docs/codeql/codeql-language-guides/codeql-library-for-javascript.rst

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Textual level
4343

4444
At its most basic level, a JavaScript code base can simply be viewed as a collection of files organized into folders, where each file is composed of zero or more lines of text.
4545

46-
Note that the textual content of a program is not included in the CodeQL database unless you specifically request it during extraction. In particular, databases on LGTM (also known as "snapshots") do not normally include textual information.
46+
Note that the textual content of a program is not included in the CodeQL database unless you specifically request it during extraction.
4747

4848
Files and folders
4949
^^^^^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ For example, the following query computes, for each folder, the number of JavaSc
7777
from Folder d
7878
select d.getRelativePath(), count(File f | f = d.getAFile() and f.getExtension() = "js")
7979
80-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/1506075865985/>`__. When you run the query on most projects, the results include folders that contain files with a ``js`` extension and folders that don't.
80+
When you run the query on most projects, the results include folders that contain files with a ``js`` extension and folders that don't.
8181

8282
Locations
8383
^^^^^^^^^
@@ -138,7 +138,7 @@ As an example of a query operating entirely on the lexical level, consider the f
138138
where comma.getNextToken() instanceof CommaToken
139139
select comma, "Omitted array elements are bad style."
140140
141-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/659662177/>`__. If the query returns no results, this pattern isn't used in the projects that you analyzed.
141+
If the query returns no results, this pattern isn't used in the projects that you analyzed.
142142

143143
You can use predicate ``Locatable.getFirstToken()`` and ``Locatable.getLastToken()`` to access the first and last token (if any) belonging to an element with a source location.
144144

@@ -179,8 +179,6 @@ As an example of a query using only lexical information, consider the following
179179
from HtmlLineComment c
180180
select c, "Do not use HTML comments."
181181
182-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/686330023/>`__. When we ran this query on the *mozilla/pdf.js* project in LGTM.com, we found three HTML comments.
183-
184182
Syntactic level
185183
~~~~~~~~~~~~~~~
186184

@@ -230,7 +228,7 @@ The `TopLevel <https://codeql.github.com/codeql-standard-libraries/javascript/se
230228

231229
Note
232230

233-
By default, LGTM filters out alerts in minified top-levels, since they are often hard to interpret. When writing your own queries in the LGTM query console, this filtering is *not* done automatically, so you may want to explicitly add a condition of the form ``and not e.getTopLevel().isMinified()`` or similar to your query to exclude results in minified code.
231+
By default, GitHub code scanning filters out alerts in minified top-levels, since they are often hard to interpret. When you write your own queries in Visual Studio Code, this filtering is *not* done automatically, so you may want to explicitly add a condition of the form ``and not e.getTopLevel().isMinified()`` or similar to your query to exclude results in minified code.
234232

235233
Statements and expressions
236234
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -351,8 +349,6 @@ As an example of how to use expression AST nodes, here is a query that finds exp
351349
where add = shift.getAnOperand()
352350
select add, "This expression should be bracketed to clarify precedence rules."
353351
354-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/690010024/>`__. When we ran this query on the *meteor/meteor* project in LGTM.com, we found many results where precedence could be clarified using brackets.
355-
356352
Functions
357353
^^^^^^^^^
358354

@@ -373,8 +369,6 @@ As an example, here is a query that finds all expression closures:
373369
where fe.getBody() instanceof Expr
374370
select fe, "Use arrow expressions instead of expression closures."
375371
376-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/668510056/>`__. None of the LGTM.com demo projects uses expression closures, but you may find this query gets results on other projects.
377-
378372
As another example, this query finds functions that have two parameters that bind the same variable:
379373

380374
.. code-block:: ql
@@ -388,8 +382,6 @@ As another example, this query finds functions that have two parameters that bin
388382
p.getAVariable() = q.getAVariable()
389383
select fun, "This function has two parameters that bind the same variable."
390384
391-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/673860037/>`__. None of the LGTM.com demo projects has functions where two parameters bind the same variable.
392-
393385
Classes
394386
^^^^^^^
395387

@@ -444,7 +436,7 @@ Here is an example of a query to find declaration statements that declare the sa
444436
not ds.getTopLevel().isMinified()
445437
select ds, "Variable " + v.getName() + " is declared both $@ and $@.", d1, "here", d2, "here"
446438
447-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/668700496/>`__. This is not a common problem, so you may not find any results in your own projects. The *angular/angular.js* project on LGTM.com has one instance of this problem at the time of writing.
439+
This is not a common problem, so you may not find any results in your own projects.
448440

449441
Notice the use of ``not ... isMinified()`` here and in the next few queries. This excludes any results found in minified code. If you delete ``and not ds.getTopLevel().isMinified()`` and re-run the query, two results in minified code in the *meteor/meteor* project are reported.
450442

@@ -471,8 +463,6 @@ As an example of a query involving properties, consider the following query that
471463
not oe.getTopLevel().isMinified()
472464
select oe, "Property " + p1.getName() + " is defined both $@ and $@.", p1, "here", p2, "here"
473465
474-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/660700064/>`__. Many projects have a few instances of object expressions with two identically named properties.
475-
476466
Modules
477467
^^^^^^^
478468

@@ -537,7 +527,7 @@ As an example, consider the following query which finds distinct function declar
537527
not g.getTopLevel().isMinified()
538528
select f, g
539529
540-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/667290067/>`__. Some projects declare conflicting functions of the same name and rely on platform-specific behavior to disambiguate the two declarations.
530+
Some projects declare conflicting functions of the same name and rely on platform-specific behavior to disambiguate the two declarations.
541531

542532
Control flow
543533
~~~~~~~~~~~~
@@ -574,7 +564,7 @@ As an example of an analysis using basic blocks, ``BasicBlock.isLiveAtEntry(v, u
574564
not f.getStartBB().isLiveAtEntry(gv, _)
575565
select f, "This function uses " + gv + " like a local variable."
576566
577-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/686320048/>`__. Many projects have some variables which look as if they were intended to be local.
567+
Many projects have some variables which look as if they were intended to be local.
578568

579569
Data flow
580570
~~~~~~~~~
@@ -599,8 +589,6 @@ As an example, the following query finds definitions of local variables that are
599589
not exists (VarUse use | def = use.getADef())
600590
select def, "Dead store of local variable."
601591
602-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/2086440429/>`__. Many projects have some examples of useless assignments to local variables.
603-
604592
SSA
605593
^^^
606594

@@ -642,8 +630,6 @@ For example, here is a query that finds all invocations of a method called ``sen
642630
send.getMethodName() = "send"
643631
select send
644632
645-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/1506058347056/>`__. The query finds HTTP response sends in the `AMP HTML <https://lgtm.com/projects/g/ampproject/amphtml>`__ project.
646-
647633
Note that the data flow modeling in this library is intraprocedural, that is, flow across function calls and returns is *not* modeled. Likewise, flow through object properties and global variables is not modeled.
648634

649635
Type inference
@@ -707,8 +693,6 @@ As an example of a call-graph-based query, here is a query to find invocations f
707693
not exists(invk.getACallee())
708694
select invk, "Unable to find a callee for this invocation."
709695
710-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/3260345690335671362/>`__
711-
712696
Inter-procedural data flow
713697
~~~~~~~~~~~~~~~~~~~~~~~~~~
714698

@@ -843,7 +827,7 @@ As an example of the use of these classes, here is a query that counts for every
843827
from NodeModule m
844828
select m, count(m.getAnImportedModule())
845829
846-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/659662207/>`__. When you analyze a project, for each module you can see how many other modules it imports.
830+
When you analyze a project, for each module you can see how many other modules it imports.
847831

848832
NPM
849833
^^^
@@ -872,8 +856,6 @@ As an example of the use of these classes, here is a query that identifies unuse
872856
not exists (Require req | req.getTopLevel() = pkg.getAModule() | name = req.getImportedPath().getValue())
873857
select deps, "Unused dependency '" + name + "'."
874858
875-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/666680077/>`__. It is not uncommon for projects to have some unused dependencies.
876-
877859
React
878860
^^^^^
879861

@@ -899,8 +881,6 @@ For example, here is a query to find SQL queries that use string concatenation (
899881
where ss instanceof AddExpr
900882
select ss, "Use templating instead of string concatenation."
901883
902-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/1506076336224/>`__, showing two (benign) results on `strong-arc <https://lgtm.com/projects/g/strongloop/strong-arc/>`__.
903-
904884
Miscellaneous
905885
~~~~~~~~~~~~~
906886

@@ -965,8 +945,6 @@ As an example, here is a query that finds ``@param`` tags that do not specify th
965945
not exists(t.getName())
966946
select t, "@param tag is missing name."
967947
968-
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/673060054/>`__. Of the LGTM.com demo projects analyzed, only *Semantic-Org/Semantic-UI* has an example where the ``@param`` tag omits the name.
969-
970948
For full details on these and other classes representing JSDoc comments and type expressions, see `the API documentation <https://codeql.github.com/codeql-standard-libraries/javascript/semmle/javascript/JSDoc.qll/module.JSDoc.html>`__.
971949

972950
JSX

0 commit comments

Comments
 (0)