Skip to content

Commit

Permalink
infra: dprint, part 2
Browse files Browse the repository at this point in the history
- Reformat everything now that the bug in dprint for wrapping lines with
  inline code is fixed.
- Additionally, apply the formatting rules I *should have* applied the
  first time, so the repo has the same style it has historically used.
  • Loading branch information
chriskrycho committed Dec 5, 2024
1 parent 5bf8642 commit 38b2b85
Show file tree
Hide file tree
Showing 115 changed files with 5,223 additions and 5,168 deletions.
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/new_translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name: New translation
about: Let us know of a new language translation you're working on
---

Language your translation is for:
URL to the repo where you're working:
Language your translation is for: URL to the repo where you're working:
133 changes: 68 additions & 65 deletions ADMIN_TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ occasional maintenance tasks.

## Update the `rustc` version

- Delete your `target` directory, you're about to recompile everything anyway
- Change the version number in `.github/workflows/main.yml`
- Change the version number in `rust-toolchain`, which should change the
version you're using locally with `rustup`
- Change the version number in `src/title-page.md`
- Run `./tools/update-rustc.sh` (see its commented code for details on what it
* Delete your `target` directory, you're about to recompile everything anyway
* Change the version number in `.github/workflows/main.yml`
* Change the version number in `rust-toolchain`, which should change the version
you're using locally with `rustup`
* Change the version number in `src/title-page.md`
* Run `./tools/update-rustc.sh` (see its commented code for details on what it
does)
- Inspect the changes (by looking at the files changed according to git) and
* Inspect the changes (by looking at the files changed according to git) and
their effects (by looking at the files in `tmp/book-before` and
`tmp/book-after`) and commit them if they look good
- Grep for `manual-regeneration` and follow the instructions in those places to
* Grep for `manual-regeneration` and follow the instructions in those places to
update output that cannot be generated by a script

## Update the `edition` in all listings
Expand All @@ -30,18 +30,19 @@ Open `book.toml` and `nostarch/book.toml` and set the `edition` value in the

## Release a new version of the listings

We now make `.tar` files of complete projects containing every listing
available [as GitHub Releases](https://github.com/rust-lang/book/releases). To
create a new release artifact, for example if there have been code changes due
to edits or due to updating Rust and `rustfmt`, do the following:
We now make `.tar` files of complete projects containing every listing available
[as GitHub Releases](https://github.com/rust-lang/book/releases). To create a
new release artifact, for example if there have been code changes due to edits
or due to updating Rust and `rustfmt`, do the following:

- Create a git tag for the release and push it to GitHub, or create a new tag
by going to the GitHub UI, [drafting a new release](https://github.com/rust-lang/book/releases/new), and entering a new
tag instead of selecting an existing tag
- Run `cargo run --bin release_listings`, which will generate
* Create a git tag for the release and push it to GitHub, or create a new tag by
going to the GitHub UI,
[drafting a new release](https://github.com/rust-lang/book/releases/new), and
entering a new tag instead of selecting an existing tag
* Run `cargo run --bin release_listings`, which will generate
`tmp/listings.tar.gz`
- Upload `tmp/listings.tar.gz` in the GitHub UI for the draft release
- Publish the release
* Upload `tmp/listings.tar.gz` in the GitHub UI for the draft release
* Publish the release

## Add a new listing

Expand All @@ -50,78 +51,79 @@ output when the compiler is updated, and produce release artifacts containing
full projects for the listings, any listing beyond the most trivial should be
extracted into a file. To do that:

- Find where the new listing should go in the `listings` directory.
- There is one subdirectory for each chapter
- Numbered listings should use `listing-[chapter num]-[listing num]` for
their directory names.
- Listings without a number should start with `no-listing-` followed by a
* Find where the new listing should go in the `listings` directory.
* There is one subdirectory for each chapter
* Numbered listings should use `listing-[chapter num]-[listing num]` for their
directory names.
* Listings without a number should start with `no-listing-` followed by a
number that indicates its position in the chapter relative to the other
listings without numbers in the chapter, then a short description that
someone could read to find the code they're looking for.
- Listings used only for displaying the output of the code (for example, when
we say "if we had written x instead of y, we would get this compiler
error:" but we don't actually show code x) should be named with
`output-only-` followed by a number that indicates its position in the
chapter relative to the other listings used only for output, then a short
description that authors or contributors could read to find the code
they're looking for.
- **Remember to adjust surrounding listing numbers as appropriate!**
- Create a full Cargo project in that directory, either by using `cargo new` or
* Listings used only for displaying the output of the code (for example, when
we say "if we had written x instead of y, we would get this compiler error:"
but we don't actually show code x) should be named with `output-only-`
followed by a number that indicates its position in the chapter relative to
the other listings used only for output, then a short description that
authors or contributors could read to find the code they're looking for.
* **Remember to adjust surrounding listing numbers as appropriate!**
* Create a full Cargo project in that directory, either by using `cargo new` or
copying another listing as a starting point.
- Add the code and any surrounding code needed to create a full working example.
- If you only want to show part of the code in the file, use anchor comments
(`// ANCHOR: some_tag` and `// ANCHOR_END: some_tag`) to mark the parts of
the file you want to show.
- For Rust code, use the `{{#rustdoc_include [filename:some_tag]}}` directive
* Add the code and any surrounding code needed to create a full working example.
* If you only want to show part of the code in the file, use anchor comments
(`// ANCHOR: some_tag` and `// ANCHOR_END: some_tag`) to mark the parts of the
file you want to show.
* For Rust code, use the `{{#rustdoc_include [filename:some_tag]}}` directive
within the code blocks in the text. The `rustdoc_include` directive gives the
code that doesn't get displayed to `rustdoc` for `mdbook test` purposes.
- For anything else, use the `{{#include [filename:some_tag]}}` directive.
- If you want to display the output of a command in the text as well, create an
* For anything else, use the `{{#include [filename:some_tag]}}` directive.
* If you want to display the output of a command in the text as well, create an
`output.txt` file in the listing's directory as follows:
- Run the command, like `cargo run` or `cargo test`, and copy all of the
* Run the command, like `cargo run` or `cargo test`, and copy all of the
output.
- Create a new `output.txt` file with the first line `$ [the command you
* Create a new `output.txt` file with the first line
`$ [the command you
ran]`.
- Paste the output you just copied.
- Run `./tools/update-rustc.sh`, which should perform some normalization on
* Paste the output you just copied.
* Run `./tools/update-rustc.sh`, which should perform some normalization on
the compiler output.
- Include the output in the text with the `{{#include [filename]}}` directive.
- Add and commit output.txt.
- If you want to display output but for some reason it can't be generated by a
* Include the output in the text with the `{{#include [filename]}}` directive.
* Add and commit output.txt.
* If you want to display output but for some reason it can't be generated by a
script (say, because of user input or external events like making a web
request), keep the output inline but make a comment that contains
`manual-regeneration` and instructions for manually updating the inline
output.
- If you don't want this example to even be attempted to be formatted by
* If you don't want this example to even be attempted to be formatted by
`rustfmt` (for example because the example doesn't parse on purpose), add a
`rustfmt-ignore` file in the listing's directory and the reason it's not
being formatted as the contents of that file (in case it's a rustfmt bug that
might get fixed someday).
`rustfmt-ignore` file in the listing's directory and the reason it's not being
formatted as the contents of that file (in case it's a rustfmt bug that might
get fixed someday).

## See the effect of some change on the rendered book

To check, say, updating `mdbook` or changing the way files get included:

- Generate a built book before the change you want to test by running `mdbook
* Generate a built book before the change you want to test by running
`mdbook
build -d tmp/book-before`
- Apply the changes you want to test and run `mdbook build -d tmp/book-after`
- Run `./tools/megadiff.sh`
- Files remaining in `tmp/book-before` and `tmp/book-after` have differences
you can manually inspect with your favorite diff viewing mechanism
* Apply the changes you want to test and run `mdbook build -d tmp/book-after`
* Run `./tools/megadiff.sh`
* Files remaining in `tmp/book-before` and `tmp/book-after` have differences you
can manually inspect with your favorite diff viewing mechanism

## Produce new markdown files for No Starch

- Run `./tools/nostarch.sh`
- Spot check the files that script created in the `nostarch` directory
- Check them into git if you're starting a round of edits
* Run `./tools/nostarch.sh`
* Spot check the files that script created in the `nostarch` directory
* Check them into git if you're starting a round of edits

## Produce markdown from docx for diffing

- Save the docx file to `tmp/chapterXX.docx`.
- In Word, go to the review tab, choose "Accept all changes and stop tracking"
- Save the docx again and close Word
- Run `./tools/doc-to-md.sh`
- This should write `nostarch/chapterXX.md`. Adjust the XSL in
* Save the docx file to `tmp/chapterXX.docx`.
* In Word, go to the review tab, choose "Accept all changes and stop tracking"
* Save the docx again and close Word
* Run `./tools/doc-to-md.sh`
* This should write `nostarch/chapterXX.md`. Adjust the XSL in
`tools/doc-to-md.xsl` and run `./tools/doc-to-md.sh` again if needed.

## Generate Graphviz dot
Expand All @@ -143,7 +145,8 @@ values that don't cut off the image.
We sometimes publish to GitHub Pages for in-progress previews. The recommended
flow for publishing is:

- Install the `ghp-import` tool by running `pip install ghp-import` (or `pipx install ghp-import`, using [pipx][pipx]).
- In the root, run `tools/generate-preview.sh`
* Install the `ghp-import` tool by running `pip install ghp-import` (or
`pipx install ghp-import`, using [pipx][pipx]).
* In the root, run `tools/generate-preview.sh`

[pipx]: https://pipx.pypa.io/stable/#install-pipx
36 changes: 18 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,46 +56,46 @@ reporting a new issue or opening a new PR.

## Licensing

This repository is under the same license as Rust itself, MIT/Apache2. You
can find the full text of each license in the `LICENSE-*` files in this
repository.
This repository is under the same license as Rust itself, MIT/Apache2. You can
find the full text of each license in the `LICENSE-*` files in this repository.

## Code of Conduct

The Rust project has [a code of conduct](http://rust-lang.org/policies/code-of-conduct)
that governs all sub-projects, including this one. Please respect it!
The Rust project has
[a code of conduct](http://rust-lang.org/policies/code-of-conduct) that governs
all sub-projects, including this one. Please respect it!

## Expectations

Because the book is [printed][nostarch], and because we want
to keep the online version of the book close to the print version when
possible, it may take longer than you're used to for us to address your issue
or pull request.
Because the book is [printed][nostarch], and because we want to keep the online
version of the book close to the print version when possible, it may take longer
than you're used to for us to address your issue or pull request.

[nostarch]: https://nostarch.com/rust-programming-language-2nd-edition

So far, we've been doing a larger revision to coincide with [Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger
So far, we've been doing a larger revision to coincide with
[Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger
revisions, we will only be correcting errors. If your issue or pull request
isn't strictly fixing an error, it might sit until the next time that we're
working on a large revision: expect on the order of months or years. Thank you
for your patience!

## Help wanted

If you're looking for ways to help that don't involve large amounts of
reading or writing, check out the [open issues with the E-help-wanted
label][help-wanted]. These might be small fixes to the text, Rust code,
frontend code, or shell scripts that would help us be more efficient or
enhance the book in some way!
If you're looking for ways to help that don't involve large amounts of reading
or writing, check out the
[open issues with the E-help-wanted label][help-wanted]. These might be small
fixes to the text, Rust code, frontend code, or shell scripts that would help us
be more efficient or enhance the book in some way!

[help-wanted]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3AE-help-wanted

## Translations

We'd love help translating the book! See the [Translations] label to join in
efforts that are currently in progress. Open a new issue to start working on
a new language! We're waiting on [mdbook support] for multiple languages
before we merge any in, but feel free to start!
efforts that are currently in progress. Open a new issue to start working on a
new language! We're waiting on [mdbook support] for multiple languages before we
merge any in, but feel free to start!

[Translations]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations
[mdbook support]: https://github.com/rust-lang/mdBook/issues/5
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ This repository contains the source of "The Rust Programming Language" book.
[nostarch]: https://nostarch.com/rust-programming-language-2nd-edition

You can also read the book for free online. Please see the book as shipped with
the latest [stable], [beta], or [nightly] Rust releases. Be aware that issues
in those versions may have been fixed in this repository already, as those
releases are updated less frequently.
the latest [stable], [beta], or [nightly] Rust releases. Be aware that issues in
those versions may have been fixed in this repository already, as those releases
are updated less frequently.

[stable]: https://doc.rust-lang.org/stable/book/
[beta]: https://doc.rust-lang.org/beta/book/
[nightly]: https://doc.rust-lang.org/nightly/book/

See the [releases] to download just the code of all the code listings that appear in the book.
See the [releases] to download just the code of all the code listings that
appear in the book.

[releases]: https://github.com/rust-lang/book/releases

Expand Down Expand Up @@ -50,8 +51,8 @@ To build the book, type:
$ mdbook build
```

The output will be in the `book` subdirectory. To check it out, open it in
your web browser.
The output will be in the `book` subdirectory. To check it out, open it in your
web browser.

_Firefox:_

Expand Down Expand Up @@ -85,12 +86,12 @@ kinds of contributions we're looking for.

[contrib]: https://github.com/rust-lang/book/blob/main/CONTRIBUTING.md

Because the book is [printed][nostarch], and because we want
to keep the online version of the book close to the print version when
possible, it may take longer than you're used to for us to address your issue
or pull request.
Because the book is [printed][nostarch], and because we want to keep the online
version of the book close to the print version when possible, it may take longer
than you're used to for us to address your issue or pull request.

So far, we've been doing a larger revision to coincide with [Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger
So far, we've been doing a larger revision to coincide with
[Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger
revisions, we will only be correcting errors. If your issue or pull request
isn't strictly fixing an error, it might sit until the next time that we're
working on a large revision: expect on the order of months or years. Thank you
Expand All @@ -99,18 +100,17 @@ for your patience!
### Translations

We'd love help translating the book! See the [Translations] label to join in
efforts that are currently in progress. Open a new issue to start working on
a new language! We're waiting on [mdbook support] for multiple languages
before we merge any in, but feel free to start!
efforts that are currently in progress. Open a new issue to start working on a
new language! We're waiting on [mdbook support] for multiple languages before we
merge any in, but feel free to start!

[Translations]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations
[mdbook support]: https://github.com/rust-lang/mdBook/issues/5

## Spellchecking

To scan source files for spelling errors, you can use the `spellcheck.sh`
script available in the `ci` directory. It needs a dictionary of valid words,
which is provided in `ci/dictionary.txt`. If the script produces a false
positive (say, you used the word `BTreeMap` which the script considers invalid),
you need to add this word to `ci/dictionary.txt` (keep the sorted order for
consistency).
To scan source files for spelling errors, you can use the `spellcheck.sh` script
available in the `ci` directory. It needs a dictionary of valid words, which is
provided in `ci/dictionary.txt`. If the script produces a false positive (say,
you used the word `BTreeMap` which the script considers invalid), you need to
add this word to `ci/dictionary.txt` (keep the sorted order for consistency).
30 changes: 15 additions & 15 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# In each chapter

- [ ] Manual regeneration
- [ ] Check for upstream changes from last snapshot
- [ ] Propagate updated output to docx
- [ ] Extract docx and check diff
- [ ] Answer all comments
- [ ] Check cross references
- [ ] Check indentation of --snip--
- [ ] Numbered lines, Gray out unchanged lines
- [ ] Check line wrapping
- [ ] Check for unneeded command/compiling/running output
- [ ] Check println style and error messages
- [ ] Add alt text to images
- [ ] Index tags
- [ ] search for "convention" conventions:naming:of blah
- [ ] check for double spaces, spaces at the end of paragraphs
* [ ] Manual regeneration
* [ ] Check for upstream changes from last snapshot
* [ ] Propagate updated output to docx
* [ ] Extract docx and check diff
* [ ] Answer all comments
* [ ] Check cross references
* [ ] Check indentation of --snip--
* [ ] Numbered lines, Gray out unchanged lines
* [ ] Check line wrapping
* [ ] Check for unneeded command/compiling/running output
* [ ] Check println style and error messages
* [ ] Add alt text to images
* [ ] Index tags
* [ ] search for "convention" conventions:naming:of blah
* [ ] check for double spaces, spaces at the end of paragraphs
2 changes: 2 additions & 0 deletions dprint.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"json": {
},
"markdown": {
"textWrap": "always",
"unorderedListKind": "asterisks",
},
"malva": {
},
Expand Down
8 changes: 4 additions & 4 deletions packages/mdbook-trpl/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# mdbook_trpl

A shared package for [mdbook][mdbook] [preprocessors][pre] used in [_The Rust
Programming Language_][trpl].
A shared package for [mdbook][mdbook] [preprocessors][pre] used in
[_The Rust Programming Language_][trpl].

Supplies the following preprocessor binaries:

- [mdbook-trpl-note](./src/bin/note)
- [mdbook-trpl-listing](./src/bin/listing)
* [mdbook-trpl-note](./src/bin/note)
* [mdbook-trpl-listing](./src/bin/listing)

[mdbook]: https://crates.io/crates/mdbook
[pre]: https://rust-lang.github.io/mdBook/format/configuration/preprocessors.html
Expand Down
Loading

0 comments on commit 38b2b85

Please sign in to comment.