Enhance learning material code examples validation and formatting#1578
Merged
alice-i-cecile merged 31 commits intobevyengine:mainfrom Jul 30, 2024
Merged
Conversation
Feels nicer to use compared to example.
alice-i-cecile
approved these changes
Jul 29, 2024
Member
alice-i-cecile
left a comment
There was a problem hiding this comment.
Delightful! Really pleased to see this working, and I think this is a reasonable approach.
BD103
approved these changes
Jul 30, 2024
| `./validate_examples.sh` | ||
|
|
||
| >[!TIP] | ||
| > The bash script can be called from any directory! |
Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
It does not make sense to version the project in this situation.
This is to prevent accidental calls of `cargo publish` having adverse effects.
Showcases how to write the learning-code-example's examples using the tools provided.
This way there is no ambiguities regarding the naming scheme for versioned, or staged progression, based example files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Part of #265
Fixes #279
As it stands code snippets used in the learning materials are not formatted and are currently only checked / validated by
code-validationwhich is a generally fragile, and at times frustrating, tool.Solution
This PR removes the
code-validationtool and supplants it withlearning-code-exampleswhich is a Cargo project without asrc/folder which stores the learning material code examples in theexamples/directory. From here we can runcargo check --examples,cargo clippy --examples, and most importantlycargo fmt --checkto validate and format the learning material code examples. Tho for ease of use it also supplies avalidate_examples.shscript which runs all three of those commands on the examples.The examples within have
// ANCHOR: name,// ANCHOR_END: nameand// HIDEto create the code snippets used in the pages.The
file_code_blockshortcode also got refactored to accommodate this and is now the primary way to use code block examples in the learning materials.The Quick Start Guide has been converted to use this tool as well.
Note
See the
learning-code-examples/README.mdfor full usage details.Note
This tool may also supplant
write-rust-doc-lines, but I am unsure ifwrite-rust-doc-linesimpacts only the learning material code blocks, or if we also use it in the migration guides and other places in the site's content.Testing
Run
zola serveto see the results of the snippets being pulled in.Run
./validate_examples.shto see the code examples be confirmed as running. (This actually helped spot that the plugin-development generic plugin example was non-functional; now it should work).