Skip to content

Commit 958fbc7

Browse files
authored
Merge pull request #316 from github/calumgrant/readme
Update README.md
2 parents 9dedb05 + a95b87d commit 958fbc7

File tree

3 files changed

+144
-30
lines changed

3 files changed

+144
-30
lines changed

CONTRIBUTING.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## Contributing
2+
3+
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
4+
5+
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE).
6+
7+
Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
8+
9+
## Building and testing
10+
11+
See [Developer information](docs/HOWTO.md) for information on building the Ruby extractor. There is no need to rebuild the extractor if you are only developing queries.
12+
13+
1. Install the CodeQL CLI as described in [Getting started with the CodeQL CLI](https://codeql.github.com/docs/codeql-cli/getting-started-with-the-codeql-cli/).
14+
15+
2. Ensure that `<extraction-root>/codeql` is in your `PATH`.
16+
17+
3. Clone this repository into `<extraction-root>/codeql-ruby` and change to this directory.
18+
19+
4. To run all tests in a directory and its subdirectories, run `codeql test run <directory>`, for example `codeql test run ql/test/query-tests/security`.
20+
21+
6. To run an individual test, run `codeql test run <filename>`, where `<filename>` is a `.ql` or `.qlref` file, for example `codeql test run ql/test/query-tests/security/cwe-078/CommandInjection.qlref`.
22+
23+
## Adding a new query
24+
25+
If you have an idea for a query that you would like to share with other CodeQL users, please open a pull request to add it to this repository.
26+
Follow the steps below to help other users understand what your query does, and to ensure that your query is consistent with the other CodeQL queries.
27+
28+
1. **Consult the documentation for query writers**
29+
30+
There is lots of useful documentation to help you write CodeQL queries, ranging from information about query file structure to language-specific tutorials. For more information on the documentation available, see [Writing CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/) and the [CodeQL documentation](https://codeql.github.com/docs).
31+
32+
2. **Format your code correctly**
33+
34+
All of the standard CodeQL queries and libraries are uniformly formatted for clarity and consistency, so we strongly recommend that all contributions follow the same formatting guidelines. If you use the CodeQL extension for Visual Studio Code, you can auto-format your query using the [Format Document command](https://help.semmle.com/codeql/codeql-for-vscode/procedures/about-codeql-for-vscode.html). For more information, see the [QL style guide](https://github.com/github/codeql/blob/main/docs/ql-style-guide.md).
35+
36+
3. **Make sure your query has the correct metadata**
37+
38+
Query metadata is used to identify your query and make sure the query results are displayed properly.
39+
The most important metadata to include are the `@name`, `@description`, and the `@kind`.
40+
Other metadata properties (`@precision`, `@severity`, and `@tags`) are usually added after the query has been reviewed by the maintainers.
41+
For more information on writing query metadata, see the [Query metadata style guide](https://github.com/github/codeql/blob/main/docs/query-metadata-style-guide.md).
42+
43+
4. **Make sure the `select` statement is compatible with the query type**
44+
45+
The `select` statement of your query must be compatible with the query type (determined by the `@kind` metadata property) for alert or path results to be displayed correctly in LGTM and Visual Studio Code.
46+
For more information on `select` statement format, see [About CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/about-codeql-queries/#select-clause) on the [CodeQL documentation](https://codeql.github.com/docs) site.
47+
48+
5. **Write a query help file**
49+
50+
Query help files explain the purpose of your query to other users. Write your query help in a `.qhelp` file and save it in the same directory as your new query.
51+
For more information on writing query help, see the [Query help style guide](https://github.com/github/codeql/blob/main/docs/query-help-style-guide.md).
52+
53+
6. **Maintain backwards compatibility**
54+
55+
The standard CodeQL libraries must evolve in a backwards compatible manner. If any backwards incompatible changes need to be made, the existing API must first be marked as deprecated. This is done by adding a `deprecated` annotation along with a QLDoc reference to the replacement API. Only after at least one full release cycle has elapsed may the old API be removed.
56+
57+
In addition to contributions to our standard queries and libraries, we also welcome contributions of a more experimental nature, which do not need to fulfill all the requirements listed above. See the guidelines for [experimental queries and libraries](ql/docs/experimental.md) for details.
58+
59+
## Resources
60+
61+
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
62+
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
63+
- [GitHub Help](https://help.github.com)
64+
- [A Note About Git Commit Messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)

README.md

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
# Ruby analysis support for CodeQL
22

3-
Under development.
3+
This open-source repository contains the extractor, CodeQL libraries, and queries that power Ruby
4+
support in [LGTM](https://lgtm.com) and the other CodeQL products that [GitHub](https://github.com)
5+
makes available to its customers worldwide.
46

5-
## Building the tools from source
7+
It contains two major components:
8+
- an extractor, written in Rust, that parses Ruby source code and converts it into a database
9+
that can be queried using CodeQL.
10+
- static analysis libraries and queries written in [CodeQL](https://codeql.github.com/docs/) that can be
11+
used to analyze such a database to find coding mistakes or security vulnerabilities.
612

7-
[Install Rust](https://www.rust-lang.org/tools/install), then run:
13+
The goal of this project is to provide comprehensive static analysis support for Ruby in CodeQL.
814

9-
```bash
10-
cargo build --release
11-
```
15+
For the queries and libraries that power CodeQL support for other languages, visit [the CodeQL
16+
repository](https://github.com/github/codeql).
1217

13-
## Generating the database schema and QL library
18+
## Installation
1419

15-
The generated `ql/lib/ruby.dbscheme` and `ql/lib/codeql/ruby/ast/internal/TreeSitter.qll` files are included in the repository, but they can be re-generated as follows:
20+
Simply clone this repository. There are no external dependencies.
1621

17-
```bash
18-
# Run the generator
19-
cargo run --release -p ruby-generator -- --dbscheme ql/lib/ruby.dbscheme --library ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
20-
# Then auto-format the QL library
21-
codeql query format -i ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
22-
```
22+
If you want to use the CodeQL extension for Visual Studio Code, import this repository into your VS
23+
Code workspace.
2324

24-
## Building a CodeQL database for a Ruby program
25+
## Usage
2526

26-
First, get an extractor pack. There are two options:
27+
To analyze a Ruby codebase, either use the [CodeQL command-line
28+
interface](https://codeql.github.com/docs/codeql-cli/) to create a database yourself, or
29+
download a pre-built database from [LGTM.com](https://lgtm.com/). You can then run any of the
30+
queries contained in this repository either on the command line or using the VS Code extension.
2731

28-
1. Either download the latest `codeql-ruby-pack` from Actions and unzip it twice, or
29-
2. Run `scripts/create-extractor-pack.sh` (Linux/Mac) or `scripts\create-extractor-pack.ps1` (Windows PowerShell) and the pack will be created in the `extractor-pack` directory.
32+
Note that the [lgtm.com](https://github.com/github/codeql-ruby/tree/lgtm.com) branch of this
33+
repository corresponds to the version of the queries that is currently deployed on LGTM.com.
34+
The [main](https://github.com/github/codeql-ruby/tree/main) branch may contain changes that
35+
have not been deployed yet, so you may need to upgrade databases downloaded from [LGTM.com](https://lgtm.com) before
36+
running queries on them.
3037

31-
Then run
38+
## Contributions
3239

33-
```bash
34-
codeql database create <database-path> -l ruby -s <project-source-path> --search-path <extractor-pack-path>
35-
```
40+
Contributions are welcome! Please see our [contribution guidelines](CONTRIBUTING.md) and our
41+
[code of conduct](CODE_OF_CONDUCT.md) for details on how to participate in our community.
3642

37-
## Running qltests
43+
## Licensing
3844

39-
Run
45+
The code in this repository is licensed under the [MIT license](LICENSE).
4046

41-
```bash
42-
codeql test run <test-path> --search-path <repository-root-path>
43-
```
47+
## Resources
4448

45-
## Writing database upgrade scripts
46-
47-
See [this guide](doc/prepare-db-upgrade.md).
49+
- [Writing CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/)
50+
- [CodeQL documentation](https://codeql.github.com/docs/)

doc/HOWTO.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Developer information
2+
3+
This document contains information about common development tasks.
4+
5+
## Building the tools from source
6+
7+
[Install Rust](https://www.rust-lang.org/tools/install), then run:
8+
9+
```bash
10+
cargo build --release
11+
```
12+
13+
## Generating the database schema and QL library
14+
15+
The generated `ql/lib/ruby.dbscheme` and `ql/lib/codeql/ruby/ast/internal/TreeSitter.qll` files are included in the repository, but they can be re-generated as follows:
16+
17+
```bash
18+
# Run the generator
19+
cargo run --release -p ruby-generator -- --dbscheme ql/lib/ruby.dbscheme --library ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
20+
# Then auto-format the QL library
21+
codeql query format -i ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
22+
```
23+
24+
## Building a CodeQL database for a Ruby program
25+
26+
First, get an extractor pack. There are two options:
27+
28+
1. Either download the latest `codeql-ruby-pack` from Actions and unzip it twice, or
29+
2. Run `scripts/create-extractor-pack.sh` (Linux/Mac) or `scripts\create-extractor-pack.ps1` (Windows PowerShell) and the pack will be created in the `extractor-pack` directory.
30+
31+
Then run
32+
33+
```bash
34+
codeql database create <database-path> -l ruby -s <project-source-path> --search-path <extractor-pack-path>
35+
```
36+
37+
## Running qltests
38+
39+
Run
40+
41+
```bash
42+
codeql test run <test-path> --search-path <repository-root-path>
43+
```
44+
45+
## Writing database upgrade scripts
46+
47+
See [this guide](prepare-db-upgrade.md).

0 commit comments

Comments
 (0)