Many `self` reads are synthesised from method calls with an implicit
`self` receiver. Synthesised nodes have no `toGenerated` result, which
the default definition of `isCapturedAccess` uses to determine if a
variable's scope matches the access's scope.
Hence we override the definition to properly identify accesses like the
call `puts` (below) as captured reads of a `self` variable defined in a
parent scope.
In other words, `puts x` is short for `self.puts x` and the `self`
refers to its value in the scope of the module `Foo`.
```ruby
module Foo
MY_PROC = -> (x) { puts x }
end
```
We also have to update the SSA `SelfDefinition` to exclude captured
`self` variables.
Ruby analysis support for CodeQL
This open-source repository contains the extractor, CodeQL libraries, and queries that power Ruby support in LGTM and the other CodeQL products that GitHub makes available to its customers worldwide.
It contains two major components:
- an extractor, written in Rust, that parses Ruby source code and converts it into a database that can be queried using CodeQL.
- static analysis libraries and queries written in CodeQL that can be used to analyze such a database to find coding mistakes or security vulnerabilities.
The goal of this project is to provide comprehensive static analysis support for Ruby in CodeQL.
For the queries and libraries that power CodeQL support for other languages, visit the CodeQL repository.
Installation
Simply clone this repository. There are no external dependencies.
If you want to use the CodeQL extension for Visual Studio Code, import this repository into your VS Code workspace.
Usage
To analyze a Ruby codebase, either use the CodeQL command-line interface to create a database yourself, or download a pre-built database from LGTM.com. You can then run any of the queries contained in this repository either on the command line or using the VS Code extension.
Note that the lgtm.com branch of this repository corresponds to the version of the queries that is currently deployed on LGTM.com. The main branch may contain changes that have not been deployed yet, so you may need to upgrade databases downloaded from LGTM.com before running queries on them.
Contributions
Contributions are welcome! Please see our contribution guidelines and our code of conduct for details on how to participate in our community.
Licensing
The code in this repository is licensed under the MIT license.