-
Notifications
You must be signed in to change notification settings - Fork 352
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 by Bors] - Code validation and format checking #281
Conversation
I'm not seeing an existing issue for this, but the author has been very responsive in the past. Let me make one and see what we can do. |
if I remember correctly, Zola is order dependant for attributes and it should work with |
That did the trick. Thank you! This is important to know for everyone that creates and/or edits code examples. Do we have a place to note this down? |
IMO we should have a |
So, the question is: do we want to merge this as is, or block on a code formatting solution. IMO code formatting is the much-less important problem here; and I'd prefer to get this rolling faster to improve book quality and contributor experience. |
Would it work if you expand the macro then run the formatting? |
Agreed. I sadly couldn't find anything online about the
Do you mean expanding the macro so that you get |
@KDecay IMO we should split out the validation and formatting checks in order to unblock this. I really really want this in place before I (or others) attempt to write more content for the book. |
Definitely agreed. I'll update the CI workflow so it only validates the code. |
Updated the description accordingly. |
So, just to make sure I understand this correctly. Let's say I want to have a small code block that only shows a few lines that are added to a block that was defined earlier, I would now need to have the entire valid program in the code block and hide all the lines I don't want to show? |
@IceSentry Yup. This way we ensure that the code shown to the user is valid. You can also use the |
Right, makes sense, where can I get more information on how the hide-line parameter works? |
It looks like it's an extension of the rust-doc feature, but I can't immediately see where the hide-line parameter can be found. |
bors r+ |
# Objective Migrates #203 Closes #83 # Solution - [x] Add code validation - [x] ~~Add code format checking~~ Removed to unblock the code validation changes # Problems During the implementation of the code validation and the format checking I encountered some problems which I would appreciate guidance or help with. ## Need to be addressed 1. ~~Zola doesn't highlight the code blocks using the rust syntax if you add more than just the language to the code block attributes. Example `rust` highlights the code correctly, `rust,no_run` doesn't. So currently the code highlighting is broken.~~ Zola is order dependent for attributes (as noted by @mockersf). So changing the attribute order from `rust,no_run` to `no_run,rust` works just fine. 1. Running `cargo fmt` doesn't format the doc examples. Adding the `rustfmt.toml` option `format_code_in_doc_comments = true` enables this, but requires nightly. In my tests it also only works if you add the code examples directly without using `#[doc = include_str!("_index.md")]`. So currently the format checking is not working. ## Nice to have 1. The `lib.rs` file of the `code-validation` crate has to be manually updated each time a new `_index.md` file is added or removed. It might be a good idea to dive deeper and see if we can implement a solution where this work is done automatically. For now this should be more than fine though. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
Pull request successfully merged into new-book. Build succeeded: |
Objective
Migrates #203
Closes #83
Solution
Add code format checkingRemoved to unblock the code validation changesProblems
During the implementation of the code validation and the format checking I encountered some problems which I would appreciate guidance or help with.
Need to be addressed
Zola doesn't highlight the code blocks using the rust syntax if you add more than just the language to the code block attributes. ExampleZola is order dependent for attributes (as noted by @mockersf). So changing the attribute order fromrust
highlights the code correctly,rust,no_run
doesn't. So currently the code highlighting is broken.rust,no_run
tono_run,rust
works just fine.cargo fmt
doesn't format the doc examples. Adding therustfmt.toml
optionformat_code_in_doc_comments = true
enables this, but requires nightly. In my tests it also only works if you add the code examples directly without using#[doc = include_str!("_index.md")]
. So currently the format checking is not working.Nice to have
lib.rs
file of thecode-validation
crate has to be manually updated each time a new_index.md
file is added or removed. It might be a good idea to dive deeper and see if we can implement a solution where this work is done automatically. For now this should be more than fine though.