Skip to content

Enhance learning material code examples validation and formatting #1578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
64c8506
Create learning code examples directory
TrialDragon Jul 28, 2024
6e308ce
Add bevy dependency to learning-code-examples
TrialDragon Jul 28, 2024
3108251
Add quick start getting started examples
TrialDragon Jul 28, 2024
6111953
Refactor file code block short code macro
TrialDragon Jul 29, 2024
f5eece8
Change file_code_block shortcode back to anchor naming
TrialDragon Jul 29, 2024
994ba11
Clean up learning code examples
TrialDragon Jul 29, 2024
67d34a8
Use file_code_block shortcode in Quick Start book
TrialDragon Jul 29, 2024
14642b4
Make file_code_block ignore extra anchors between other anchors
TrialDragon Jul 29, 2024
251726c
Remove code-validation in favor of learning-code-examples
TrialDragon Jul 29, 2024
7c53c3e
Add validate examples script for ease of use
TrialDragon Jul 29, 2024
92bbc56
Add learning-code-examples README
TrialDragon Jul 29, 2024
52ac9de
Remove code-validation from workspace Cargo.toml
TrialDragon Jul 29, 2024
3a53cd9
Make step 2 of learning-code-examples README usage consistent
TrialDragon Jul 29, 2024
133ccf3
Make the placeholder for paths more obvious
TrialDragon Jul 29, 2024
9f15f91
Update CONTRIBUTING.md
TrialDragon Jul 29, 2024
6141de2
Format
TrialDragon Jul 29, 2024
34a8705
Fix learning-code-validation typo to learning-code-examples
TrialDragon Jul 29, 2024
7fdae39
Make validate_examples.sh executable
TrialDragon Jul 29, 2024
b77c81a
Run cargo fmt on learning-code-examples
TrialDragon Jul 29, 2024
7fd8986
Turn extra link in CONTRIBUTING.md into a note
TrialDragon Jul 29, 2024
8bb5873
Expand learning-code-examples README.md
TrialDragon Jul 29, 2024
6bf162e
Fix typo in workflows/ci.yml
TrialDragon Jul 29, 2024
5e5b800
Fix typo in quick start plugin development's generic plugin example
TrialDragon Jul 29, 2024
7a7ed9c
Change learning-code-examples workflow to use validate_examples script
TrialDragon Jul 30, 2024
504a4ca
Remove versioning from learning-code-examples
TrialDragon Jul 30, 2024
5f7f344
Disable publishing for learning-code-examples
TrialDragon Jul 30, 2024
8de37da
Disable learning-code-examples example autodiscovery
TrialDragon Jul 30, 2024
841ff9b
Clarify CONTRIBUTING.md wording on use of learning-code-examples
TrialDragon Jul 30, 2024
086835e
Expand learning-code-examples README.md with example
TrialDragon Jul 30, 2024
9ff1458
Codify learning-code-example example naming scheme in README.md
TrialDragon Jul 30, 2024
d6522dd
Normalize casing in the learning-code-examples README.md example
TrialDragon Jul 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev

- name: Build & run doc tests
run: cd code-validation && cargo test
run: cd learning-code-examples && ./validate_examples.sh

check-hide-lines:
runs-on: ubuntu-latest
Expand Down
18 changes: 11 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ To check out any local changes you've made:

A local server should start and you should be able to access a local version of the website from there.

## Testing changes to book code snippets
## Testing changes to learning material code examples

The code in the book is compiled and tested to make sure that the examples work for readers.
The code in the learning materials (e.g., Bevy Book, Quick Start Guide, Advanced Examples, etc.) is compiled, formatted, and tested to make sure that the examples work for readers.

To check your local changes, move into the `code-validation` folder of this project using `cd code-validation`, and then run `cargo test`. If you write a new section of the book, you have to add it in `code-validation/src/lib.rs` to enable code validation for it.
To validate your code snippets either run `validate_examples.sh` which resides in the `learning-code-examples` directory (and is the recommended way to use `learning-code-examples`), or from the root of the project run `cd learning-code-examples && cargo check --examples && cargo clippy --examples && cargo fmt --check`.

> [!NOTE]
> [See the `learning-code-examples` README.md for more info.](./learning-code-examples/README.md)

## Learning material structure

Expand Down Expand Up @@ -174,16 +177,17 @@ When writing and reviewing learning material for the Bevy Book and Quick Start G
These may be appropriate to link in "next steps" however at the end of the examples.
1. Third-party crates should be limited to the most essential, such as `rand`.
9. If additional code block attributes like `no_run` or `hide-lines=x-y` need to be specified, you should always order these so that the language is the last attribute. If we would specify `rust,no_run` the syntax highlighting wouldn't work, but changing it to `no_run,rust` makes it work.
10. To validate if local code changes are compiling you can `cd` into the `code-validation` folder and test your code using `cargo test`.
11. To make sure your web-based files (html, markdown) are formatted correctly run the commands:
10. To validate local code changes you can either `./learning-code-examples/validate_examples.sh` from anywhere, or from the project's root `cd learning-code-examples && cargo check --examples && cargo clippy --examples && cargo fmt --check`.
11. To make sure your web-based files (html, markdown) are formatted correctly run the commands:

```
markdownlint -f -c .github/linters/.markdown-lint.yml .
djlint
typos
```

in the root directory of your local Bevy website repository. This will format markdown files and tell you the issues in HTML files. In order to run the command you should install `markdownlint-cli`, `djlint`, and `typos-cli`. See: <https://github.com/igorshubovych/markdownlint-cli>, <https://www.djlint.com/docs/getting-started/>, and <https://github.com/crate-ci/typos?tab=readme-ov-file#install>. Note that the CI also includes `editorconfigchecker` but there isn't an easy way to run this manually, so you should instead rely on CI to validate files with this tool.
12. To hide lines of code in Zola Rust code blocks of the book you should: a. Mark each line you wish to hide with a `#` with an empty space afterwards like `# //...line_of_code_here...` although you were hiding lines in rustdoc. b. Run the [utility tool](write-rustdoc-hide-lines) in `<ROOT_OF_WEBSITE>/write_rustdoc-hide-lines/` named `write_rustdoc_hide_lines.sh`.
13. To reference Rust API docs you can use markdown's reference-style links like so:
12. To reference Rust API docs you can use markdown's reference-style links like so:
[`HashMap`]

```md
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[workspace]
resolver = "2"
members = [
"code-validation",
"generate-assets",
"generate-community",
"generate-errors",
"generate-release",
"learning-code-examples",
"write-rustdoc-hide-lines",
]

Expand Down
13 changes: 0 additions & 13 deletions code-validation/Cargo.toml

This file was deleted.

81 changes: 0 additions & 81 deletions code-validation/README.md

This file was deleted.

213 changes: 0 additions & 213 deletions code-validation/src/lib.rs

This file was deleted.

Loading