Skip to content

Commit a9f2e52

Browse files
authored
Merge pull request #10376 from hvitved/ruby/no-ast-by-default
Ruby: Do not expose AST layer through `ruby.qll`
2 parents e53382c + c6cd2d6 commit a9f2e52

File tree

178 files changed

+192
-184
lines changed

Some content is hidden

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

178 files changed

+192
-184
lines changed

.github/workflows/ruby-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ jobs:
197197
- name: Prepare test files
198198
shell: bash
199199
run: |
200-
echo "import ruby select count(File f)" > "test.ql"
200+
echo "import codeql.ruby.AST select count(File f)" > "test.ql"
201201
echo "| 4 |" > "test.expected"
202202
echo 'name: sample-tests
203203
version: 0.0.0

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Running the query
3636

3737
.. code-block:: ql
3838
39-
import ruby
39+
import codeql.ruby.AST
4040
4141
from IfExpr ifexpr
4242
where
@@ -80,7 +80,7 @@ After the initial ``import`` statement, this simple query comprises three parts
8080
+---------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------+
8181
| Query part | Purpose | Details |
8282
+===============================================================+===================================================================================================================+========================================================================================================================+
83-
| ``import ruby`` | Imports the standard CodeQL libraries for Ruby. | Every query begins with one or more ``import`` statements. |
83+
| ``import codeql.ruby.AST`` | Imports the standard CodeQL AST libraries for Ruby. | Every query begins with one or more ``import`` statements. |
8484
+---------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------+
8585
| ``from IfExpr ifexpr`` | Defines the variables for the query. | We use: an ``IfExpr`` variable for ``if`` expressions. |
8686
| | Declarations are of the form: | |

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ library by beginning your query with:
1818

1919
.. code-block:: ql
2020
21-
import ruby
21+
import codeql.ruby.AST
2222
2323
The CodeQL libraries model various aspects of Ruby code, depending on the type of query you want to write.
2424
For example the abstract syntax tree (AST) library is used for locating program elements, to match syntactic
@@ -138,7 +138,7 @@ The following example lists all methods in the class `ApiController`:
138138

139139
.. code-block:: ql
140140
141-
import ruby
141+
import codeql.ruby.AST
142142
143143
from ClassDeclaration m
144144
where m.getName() = "ApiController"
@@ -223,7 +223,7 @@ Example
223223

224224
.. code-block:: ql
225225
226-
import ruby
226+
import codeql.ruby.AST
227227
228228
from Method m
229229
where m.getName() = "show"
@@ -274,7 +274,7 @@ The following example finds all literals that are returned by a `return` stateme
274274

275275
.. code-block:: ql
276276
277-
import ruby
277+
import codeql.ruby.AST
278278
279279
from ReturnStmt return, Literal lit
280280
where lit.getParent() = return
@@ -421,7 +421,7 @@ The following example finds "chained assignments" (of the form ``A=B=C``):
421421

422422
.. code-block:: ql
423423
424-
import ruby
424+
import codeql.ruby.AST
425425
426426
from Assignment op
427427
where op.getRightOperand() instanceof Assignment
@@ -460,7 +460,7 @@ The following example finds all method calls to a method called `delete`.
460460

461461
.. code-block:: ql
462462
463-
import ruby
463+
import codeql.ruby.AST
464464
465465
from MethodCall call
466466
where call.getMethodName() = "delete"
@@ -517,7 +517,7 @@ The following example finds `if`-expressions that are missing a `then` branch.
517517

518518
.. code-block:: ql
519519
520-
import ruby
520+
import codeql.ruby.AST
521521
522522
from IfExpr expr
523523
where not exists(expr.getThen())
@@ -559,7 +559,7 @@ The following example finds all class variables in the class `StaticController`:
559559

560560
.. code-block:: ql
561561
562-
import ruby
562+
import codeql.ruby.AST
563563
564564
from ClassDeclaration cd, ClassVariable v
565565
where
@@ -612,7 +612,7 @@ The following example finds writes to class variables in the class `StaticContro
612612

613613
.. code-block:: ql
614614
615-
import ruby
615+
import codeql.ruby.AST
616616
617617
from ClassVariableWriteAccess write, ClassDeclaration cd, ClassVariable v
618618
where

ruby/ql/examples/snippets/emptythen.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* statement
1212
*/
1313

14-
import ruby
14+
import codeql.ruby.AST
1515

1616
from IfExpr i
1717
where not exists(i.getThen().getAChild())

ruby/ql/lib/Customizations.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
* to model frameworks that are not covered by the standard library.
1010
*/
1111

12-
import ruby
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: breaking
3+
---
4+
* `import ruby` no longer brings the standard Ruby AST library into scope; it instead brings a module `Ast` into scope, which must be imported. Alternatively, it is also possible to import `codeql.ruby.AST`.

ruby/ql/lib/codeql/ruby/AST.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ private import ast.internal.AST
1717
private import ast.internal.Scope
1818
private import ast.internal.Synthesis
1919
private import ast.internal.TreeSitter
20+
private import Customizations
2021

2122
cached
2223
private module Cached {

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* directed and labeled; they specify how the components represented by nodes relate to each other.
77
*/
88

9-
private import ruby
9+
private import codeql.ruby.AST
1010
private import codeql.ruby.DataFlow
1111
private import codeql.ruby.typetracking.TypeTracker
1212
private import codeql.ruby.ast.internal.Module

ruby/ql/lib/codeql/ruby/CFG.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** Provides classes representing the control flow graph. */
22

3+
import codeql.Locations
34
import controlflow.ControlFlowGraph
45
import controlflow.CfgNodes as CfgNodes
56
import controlflow.BasicBlocks

ruby/ql/lib/codeql/ruby/DataFlow.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* Provides classes for performing local (intra-procedural) and
3+
* global (inter-procedural) data flow analyses.
4+
*/
5+
6+
import codeql.Locations
7+
18
/**
29
* Provides classes for performing local (intra-procedural) and
310
* global (inter-procedural) data flow analyses.

0 commit comments

Comments
 (0)