Skip to content

Commit d83137d

Browse files
authored
Merge pull request #4125 from rust-lang/dprint
infra: introduce dprint for easier formatting
2 parents 1366453 + 587b3e4 commit d83137d

File tree

119 files changed

+1509
-1494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1509
-1494
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ran dprint fmt on the repo
2+
3a30e4c1

ADMIN_TASKS.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ occasional maintenance tasks.
1414
does)
1515
- Inspect the changes (by looking at the files changed according to git) and
1616
their effects (by looking at the files in `tmp/book-before` and
17-
`tmp/book-after`) and commit them if they look good
17+
`tmp/book-after`) and commit them if they look good
1818
- Grep for `manual-regeneration` and follow the instructions in those places to
1919
update output that cannot be generated by a script
2020

@@ -36,9 +36,8 @@ create a new release artifact, for example if there have been code changes due
3636
to edits or due to updating Rust and `rustfmt`, do the following:
3737

3838
- Create a git tag for the release and push it to GitHub, or create a new tag
39-
by going to the GitHub UI, [drafting a new
40-
release](https://github.com/rust-lang/book/releases/new), and entering a new
41-
tag instead of selecting an existing tag
39+
by going to the GitHub UI, [drafting a new release](https://github.com/rust-lang/book/releases/new), and entering a new
40+
tag instead of selecting an existing tag
4241
- Run `cargo run --bin release_listings`, which will generate
4342
`tmp/listings.tar.gz`
4443
- Upload `tmp/listings.tar.gz` in the GitHub UI for the draft release
@@ -54,50 +53,50 @@ extracted into a file. To do that:
5453
- Find where the new listing should go in the `listings` directory.
5554
- There is one subdirectory for each chapter
5655
- Numbered listings should use `listing-[chapter num]-[listing num]` for
57-
their directory names.
56+
their directory names.
5857
- Listings without a number should start with `no-listing-` followed by a
59-
number that indicates its position in the chapter relative to the other
60-
listings without numbers in the chapter, then a short description that
61-
someone could read to find the code they're looking for.
58+
number that indicates its position in the chapter relative to the other
59+
listings without numbers in the chapter, then a short description that
60+
someone could read to find the code they're looking for.
6261
- Listings used only for displaying the output of the code (for example, when
63-
we say "if we had written x instead of y, we would get this compiler
64-
error:" but we don't actually show code x) should be named with
65-
`output-only-` followed by a number that indicates its position in the
66-
chapter relative to the other listings used only for output, then a short
67-
description that authors or contributors could read to find the code
68-
they're looking for.
62+
we say "if we had written x instead of y, we would get this compiler
63+
error:" but we don't actually show code x) should be named with
64+
`output-only-` followed by a number that indicates its position in the
65+
chapter relative to the other listings used only for output, then a short
66+
description that authors or contributors could read to find the code
67+
they're looking for.
6968
- **Remember to adjust surrounding listing numbers as appropriate!**
7069
- Create a full Cargo project in that directory, either by using `cargo new` or
7170
copying another listing as a starting point.
7271
- Add the code and any surrounding code needed to create a full working example.
7372
- If you only want to show part of the code in the file, use anchor comments
7473
(`// ANCHOR: some_tag` and `// ANCHOR_END: some_tag`) to mark the parts of
75-
the file you want to show.
74+
the file you want to show.
7675
- For Rust code, use the `{{#rustdoc_include [filename:some_tag]}}` directive
7776
within the code blocks in the text. The `rustdoc_include` directive gives the
78-
code that doesn't get displayed to `rustdoc` for `mdbook test` purposes.
77+
code that doesn't get displayed to `rustdoc` for `mdbook test` purposes.
7978
- For anything else, use the `{{#include [filename:some_tag]}}` directive.
8079
- If you want to display the output of a command in the text as well, create an
8180
`output.txt` file in the listing's directory as follows:
8281
- Run the command, like `cargo run` or `cargo test`, and copy all of the
83-
output.
82+
output.
8483
- Create a new `output.txt` file with the first line `$ [the command you
8584
ran]`.
8685
- Paste the output you just copied.
8786
- Run `./tools/update-rustc.sh`, which should perform some normalization on
88-
the compiler output.
87+
the compiler output.
8988
- Include the output in the text with the `{{#include [filename]}}` directive.
9089
- Add and commit output.txt.
9190
- If you want to display output but for some reason it can't be generated by a
9291
script (say, because of user input or external events like making a web
93-
request), keep the output inline but make a comment that contains
94-
`manual-regeneration` and instructions for manually updating the inline
95-
output.
92+
request), keep the output inline but make a comment that contains
93+
`manual-regeneration` and instructions for manually updating the inline
94+
output.
9695
- If you don't want this example to even be attempted to be formatted by
9796
`rustfmt` (for example because the example doesn't parse on purpose), add a
98-
`rustfmt-ignore` file in the listing's directory and the reason it's not
99-
being formatted as the contents of that file (in case it's a rustfmt bug that
100-
might get fixed someday).
97+
`rustfmt-ignore` file in the listing's directory and the reason it's not
98+
being formatted as the contents of that file (in case it's a rustfmt bug that
99+
might get fixed someday).
101100

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

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ or pull request.
4545

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

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

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $ cargo install mdbook --locked --version <version_num>
3535

3636
The book also uses two mdbook plugins which are part of this repository. If you
3737
do not install them, you will see warnings when building and the output will not
38-
look right, but you *will* still be able to build the book. To use the plugins,
38+
look right, but you _will_ still be able to build the book. To use the plugins,
3939
you should run:
4040

4141
```bash
@@ -55,6 +55,7 @@ The output will be in the `book` subdirectory. To check it out, open it in
5555
your web browser.
5656

5757
_Firefox:_
58+
5859
```bash
5960
$ firefox book/index.html # Linux
6061
$ open -a "Firefox" book/index.html # OS X
@@ -63,6 +64,7 @@ $ start firefox.exe .\book\index.html # Windows (Cmd)
6364
```
6465

6566
_Chrome:_
67+
6668
```bash
6769
$ google-chrome book/index.html # Linux
6870
$ open -a "Google Chrome" book/index.html # OS X
@@ -89,8 +91,7 @@ to keep the online version of the book close to the print version when
8991
possible, it may take longer than you're used to for us to address your issue
9092
or pull request.
9193

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

dprint.jsonc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"typescript": {
3+
},
4+
"json": {
5+
},
6+
"markdown": {
7+
},
8+
"malva": {
9+
},
10+
"excludes": [
11+
"**/node_modules",
12+
"**/*-lock.json",
13+
"**/target",
14+
// We don’t to apply auto-formatting to this *yet*, at a minimum. It may be
15+
// helpful as a way of replacing some of the manual formatting we do in both
16+
// the nostarch script and the script for pulling data back over from docx,
17+
// though, so we may *start* doing so in the future.
18+
"nostarch",
19+
// These should never change at this point
20+
"2018-edition",
21+
"first-edition",
22+
"second-edition",
23+
"redirects",
24+
// has empty list items which look like headings to a formatter
25+
".github/ISSUE_TEMPLATE/bug_report.md"
26+
],
27+
"plugins": [
28+
"https://plugins.dprint.dev/typescript-0.93.3.wasm",
29+
"https://plugins.dprint.dev/json-0.19.4.wasm",
30+
"https://plugins.dprint.dev/markdown-0.17.8.wasm",
31+
"https://plugins.dprint.dev/g-plane/malva-v0.11.0.wasm"
32+
]
33+
}

ferris.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,50 @@
77
/** @type {Array<FerrisType>} */
88
const FERRIS_TYPES = [
99
{
10-
attr: 'does_not_compile',
11-
title: 'This code does not compile!'
10+
attr: "does_not_compile",
11+
title: "This code does not compile!",
1212
},
1313
{
14-
attr: 'panics',
15-
title: 'This code panics!'
14+
attr: "panics",
15+
title: "This code panics!",
1616
},
1717
{
18-
attr: 'not_desired_behavior',
19-
title: 'This code does not produce the desired behavior.'
20-
}
21-
]
18+
attr: "not_desired_behavior",
19+
title: "This code does not produce the desired behavior.",
20+
},
21+
];
2222

23-
document.addEventListener('DOMContentLoaded', () => {
23+
document.addEventListener("DOMContentLoaded", () => {
2424
for (let ferrisType of FERRIS_TYPES) {
25-
attachFerrises(ferrisType)
25+
attachFerrises(ferrisType);
2626
}
27-
})
27+
});
2828

2929
/**
3030
* @param {FerrisType} type
3131
*/
3232
function attachFerrises(type) {
33-
let elements = document.getElementsByClassName(type.attr)
33+
let elements = document.getElementsByClassName(type.attr);
3434

3535
for (let codeBlock of elements) {
3636
// Skip SVG etc.: in principle, these should never be attached to those, but
3737
// this means if someone happens to have a browser extension which *is*
3838
// attaching them, it will not break the code.
3939
if (!(codeBlock instanceof HTMLElement)) {
40-
continue
40+
continue;
4141
}
4242

43-
let lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length
43+
let lines = codeBlock.innerText.replace(/\n$/, "").split(/\n/).length;
4444

4545
/** @type {'small' | 'large'} */
46-
let size = lines < 4 ? 'small' : 'large'
46+
let size = lines < 4 ? "small" : "large";
4747

48-
let container = prepareFerrisContainer(codeBlock, size == 'small')
48+
let container = prepareFerrisContainer(codeBlock, size == "small");
4949
if (!container) {
50-
continue
50+
continue;
5151
}
5252

53-
container.appendChild(createFerris(type, size))
53+
container.appendChild(createFerris(type, size));
5454
}
5555
}
5656

@@ -60,22 +60,22 @@ function attachFerrises(type) {
6060
* @returns {Element | null} - The container element to use.
6161
*/
6262
function prepareFerrisContainer(element, useButtons) {
63-
let foundButtons = element.parentElement?.querySelector('.buttons')
63+
let foundButtons = element.parentElement?.querySelector(".buttons");
6464
if (useButtons && foundButtons) {
65-
return foundButtons
65+
return foundButtons;
6666
}
6767

68-
let div = document.createElement('div')
69-
div.classList.add('ferris-container')
68+
let div = document.createElement("div");
69+
div.classList.add("ferris-container");
7070

7171
if (!element.parentElement) {
7272
console.error(`Could not install Ferris on ${element}, which is missing a parent`);
7373
return null;
7474
}
7575

76-
element.parentElement.insertBefore(div, element)
76+
element.parentElement.insertBefore(div, element);
7777

78-
return div
78+
return div;
7979
}
8080

8181
/**
@@ -84,17 +84,17 @@ function prepareFerrisContainer(element, useButtons) {
8484
* @returns {HTMLAnchorElement} - The generated anchor element.
8585
*/
8686
function createFerris(type, size) {
87-
let a = document.createElement('a')
88-
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
89-
a.setAttribute('target', '_blank')
87+
let a = document.createElement("a");
88+
a.setAttribute("href", "ch00-00-introduction.html#ferris");
89+
a.setAttribute("target", "_blank");
9090

91-
let img = document.createElement('img')
92-
img.setAttribute('src', 'img/ferris/' + type.attr + '.svg')
93-
img.setAttribute('title', type.title)
94-
img.classList.add('ferris')
95-
img.classList.add('ferris-' + size)
91+
let img = document.createElement("img");
92+
img.setAttribute("src", "img/ferris/" + type.attr + ".svg");
93+
img.setAttribute("title", type.title);
94+
img.classList.add("ferris");
95+
img.classList.add("ferris-" + size);
9696

97-
a.appendChild(img)
97+
a.appendChild(img);
9898

99-
return a
99+
return a;
100100
}

packages/mdbook-trpl-note/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mdbook-trpl-note
22

3-
This is a *very* simple [preprocessor][pre] for [mdBook][mdbook], focused specifically on the content of _The Rust Programming Language_ book. This preprocessor takes Markdown like this—
3+
This is a _very_ simple [preprocessor][pre] for [mdBook][mdbook], focused specifically on the content of _The Rust Programming Language_ book. This preprocessor takes Markdown like this—
44

55
```markdown
66
> Note: This is some material we want to provide more emphasis for, because it
@@ -37,7 +37,7 @@ Here is all the important things to know about that particular subject.
3737
This allows using the relatively standard Markdown convention of (incorrectly!) using blockquotes for “callouts” or “notes” like this, while still producing semantic HTML which conveys the actual intent.
3838

3939
> [!NOTE]
40-
> This is *not* a full “admonition” preprocessor, and it is not remotely compliant with [the GitHub “alert” syntax][alerts]. It exists almost entirely for the sake of providing better semantic HTML for _The Rust Programming Language_ book with a minimum of disruption to existing workflows!
40+
> This is _not_ a full “admonition” preprocessor, and it is not remotely compliant with [the GitHub “alert” syntax][alerts]. It exists almost entirely for the sake of providing better semantic HTML for _The Rust Programming Language_ book with a minimum of disruption to existing workflows!
4141
>
4242
> You are probably better off using one of the other existing alert/admonition preprocessors:
4343
>

packages/trpl/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
## 0.1.0
44

5-
Initial release! Adds support code for the first draft of the new async chapter of the book.
5+
Initial release! Adds support code for the first draft of the new async chapter of the book.

packages/trpl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This repository is the home of the `trpl` crate used in _The Rust Programming
66
Language_ book materials.
77

8-
This crate mostly just re-exports items from *other* crates. It exists for two
8+
This crate mostly just re-exports items from _other_ crates. It exists for two
99
main reasons:
1010

1111
1. So that as you read along in _The Rust Programming Language_, you can add

0 commit comments

Comments
 (0)