Skip to content

Commit d4c6dfb

Browse files
polish
1 parent b52c9df commit d4c6dfb

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

tools/website-test/build.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,40 @@ fn should_combine_code_blocks(path: &Path) -> io::Result<bool> {
4343
Ok(buf.trim_ascii_end().ends_with(FLAG))
4444
}
4545

46-
fn apply_diff(src: &mut String, preamble: &str, added: &str, removed: &str)
47-
-> Result
48-
{
46+
fn apply_diff(src: &mut String, preamble: &str, added: &str, removed: &str) -> Result {
4947
assert!(
5048
!preamble.is_empty() || !removed.is_empty(),
51-
"Failure on applying a diff: \n\
52-
No preamble or text to remove provided, unable to find location to insert:\n{added}\n\
53-
In the following text:\n{src}",
49+
"Failure on applying a diff: \nNo preamble or text to remove provided, unable to find \
50+
location to insert:\n{added}\nIn the following text:\n{src}",
5451
);
5552

5653
let mut matches = src.match_indices(if preamble.is_empty() {
5754
removed
5855
} else {
59-
&preamble
56+
preamble
6057
});
6158
let Some((preamble_start, _)) = matches.next() else {
62-
e!("Failure on applying a diff: \n\
63-
couldn't find the following text:\n{preamble}\n\nIn the following text:\n{src}")
59+
e!(
60+
"Failure on applying a diff: \ncouldn't find the following text:\n{preamble}\n\nIn \
61+
the following text:\n{src}"
62+
)
6463
};
65-
64+
6665
assert!(
6766
matches.next().is_none(),
68-
"Failure on applying a diff: \n\
69-
Ambiguous preamble:\n{preamble}\n\
70-
In the following text:\n{src}\n\
71-
While trying to remove the following text:\n{removed}\n\
72-
And add the following:\n{added}\n"
67+
"Failure on applying a diff: \nAmbiguous preamble:\n{preamble}\nIn the following \
68+
text:\n{src}\nWhile trying to remove the following text:\n{removed}\nAnd add the \
69+
following:\n{added}\n"
7370
);
7471

7572
let preamble_end = preamble_start + preamble.len();
7673
assert!(
77-
src.get(preamble_end .. preamble_end + removed.len()) == Some(removed),
78-
"Failure on applying a diff: \n\
79-
Text to remove not found:\n{removed}\n\nIn the following text:\n{src}",
74+
src.get(preamble_end..preamble_end + removed.len()) == Some(removed),
75+
"Failure on applying a diff: \nText to remove not found:\n{removed}\n\nIn the following \
76+
text:\n{src}",
8077
);
8178

82-
src.replace_range(preamble_end .. preamble_end + removed.len(), added);
79+
src.replace_range(preamble_end..preamble_end + removed.len(), added);
8380
Ok(())
8481
}
8582

@@ -88,10 +85,10 @@ fn combined_code_blocks(path: &Path) -> Result<String> {
8885
let mut res = String::new();
8986

9087
let mut err = Ok(());
91-
let mut lines = file.lines().filter_map(|i| {
92-
i.map_err(|e| err = Err(e)).ok()
93-
}).enumerate();
94-
while let Some((i, line)) = lines.next() {
88+
let mut lines = file
89+
.lines()
90+
.filter_map(|i| i.map_err(|e| err = Err(e)).ok());
91+
while let Some(line) = lines.next() {
9592
if !line.starts_with("```rust") {
9693
continue;
9794
}
@@ -100,13 +97,12 @@ fn combined_code_blocks(path: &Path) -> Result<String> {
10097
let mut added = String::new();
10198
let mut removed = String::new();
10299
let mut diff_applied = false;
103-
for (i, line) in &mut lines {
100+
for line in &mut lines {
104101
if line.starts_with("```") {
105102
if !added.is_empty() || !removed.is_empty() {
106-
apply_diff(&mut res, &preamble, &added, &removed)
107-
.inspect_err(|_| eprintln!("Line {i}"))?;
108-
} else if !diff_applied { // if no diff markers were found, just add the contents
109-
eprintln!("Shrimply added {preamble:?}, line {i}");
103+
apply_diff(&mut res, &preamble, &added, &removed)?;
104+
} else if !diff_applied {
105+
// if no diff markers were found, just add the contents
110106
res += &preamble;
111107
}
112108
break;
@@ -122,13 +118,13 @@ fn combined_code_blocks(path: &Path) -> Result<String> {
122118
}
123119
removed += line;
124120
removed += "\n";
125-
} else if line.trim_ascii() == "// ..." { // disregard the preamble
121+
} else if line.trim_ascii() == "// ..." {
122+
// disregard the preamble
126123
preamble.clear();
127124
} else {
128125
if !added.is_empty() || !removed.is_empty() {
129126
diff_applied = true;
130-
apply_diff(&mut res, &preamble, &added, &removed)
131-
.inspect_err(|_| eprintln!("Line {i}"))?;
127+
apply_diff(&mut res, &preamble, &added, &removed)?;
132128
preamble += &added;
133129
added.clear();
134130
removed.clear();
@@ -233,7 +229,10 @@ fn inner_main() -> Result {
233229
let mut parts = vec![];
234230

235231
for part in rel {
236-
parts.push(part.to_str().ok_or_else(|| format!("Non-UTF8 path: {rel:?}"))?);
232+
parts.push(
233+
part.to_str()
234+
.ok_or_else(|| format!("Non-UTF8 path: {rel:?}"))?,
235+
);
237236
}
238237

239238
level.insert(path.clone(), &parts[..]);

website/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ walkthrough, it makes more sense to combine the changes described in the blocks
3636
For this end `website-test` scans all doc files for a special flag:
3737

3838
```html
39-
<!-- COMBINE CODE BLOCKS >
39+
<!-- COMBINE CODE BLOCKS -->
4040
```
4141
If a file ends with this specific comment (and an optional newline after it), all code blocks will be
4242
sown together, with respect to the diff markers in them. For example:
@@ -55,7 +55,7 @@ fn main() {
5555
}
5656
\`\`\`
5757

58-
<!-- COMBINE CODE BLOCKS>
58+
<!-- COMBINE CODE BLOCKS -->
5959
```
6060

6161
Will be tested as:

website/docs/concepts/function-components/properties.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,12 @@ Props are evaluated in the order they're specified, as shown by the following ex
318318
#[derive(yew::Properties, PartialEq)]
319319
struct Props { first: usize, second: usize, last: usize }
320320

321-
fn main() {
322-
let mut g = 1..=3;
323-
let props = yew::props!(Props { first: g.next().unwrap(), second: g.next().unwrap(), last: g.next().unwrap() });
321+
let mut g = 1..=3;
322+
let props = yew::props!(Props { first: g.next().unwrap(), second: g.next().unwrap(), last: g.next().unwrap() });
324323

325-
assert_eq!(props.first, 1);
326-
assert_eq!(props.second, 2);
327-
assert_eq!(props.last, 3);
328-
}
324+
assert_eq!(props.first, 1);
325+
assert_eq!(props.second, 2);
326+
assert_eq!(props.last, 3);
329327
```
330328

331329
## Anti Patterns

0 commit comments

Comments
 (0)