Skip to content

Commit

Permalink
set cargo fmt width to 120
Browse files Browse the repository at this point in the history
100 is way too small!
  • Loading branch information
yshavit authored Jun 10, 2024
1 parent 5439834 commit 5ef82a4
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 148 deletions.
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 120
16 changes: 3 additions & 13 deletions src/fmt_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ where
N: Borrow<MdqNode>,
R: InlineResolver,
{
Value::Array(
nodes
.iter()
.map(|n| node_to_json::<R>(n.borrow()))
.collect(),
)
Value::Array(nodes.iter().map(|n| node_to_json::<R>(n.borrow())).collect())
}

pub fn node_to_json<R: InlineResolver>(node: &MdqNode) -> Value {
Expand All @@ -36,10 +31,7 @@ pub fn node_to_json<R: InlineResolver>(node: &MdqNode) -> Value {
}),
MdqNode::Paragraph { body } => json!({"paragraph": R::inlines_to_value(body)}),
MdqNode::BlockQuote { body } => json!({"block_quote": to_jsons::<R>(body)}),
MdqNode::List {
starting_index,
items,
} => {
MdqNode::List { starting_index, items } => {
let mut as_map = Map::new();
match starting_index {
Some(start_idx) => {
Expand Down Expand Up @@ -96,9 +88,7 @@ pub fn node_to_json<R: InlineResolver>(node: &MdqNode) -> Value {
CodeVariant::Code(opts) => {
let (lang, meta) = match opts {
None => (None, None),
Some(CodeOpts { language, metadata }) => {
(Some(language.to_string()), metadata.to_owned())
}
Some(CodeOpts { language, metadata }) => (Some(language.to_string()), metadata.to_owned()),
};
json!({
"code":json!({
Expand Down
23 changes: 5 additions & 18 deletions src/fmt_md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ where
write_md(out, body);
});
}
MdqNode::List {
starting_index,
items,
} => {
MdqNode::List { starting_index, items } => {
out.with_block(Block::Plain, |out| {
let mut index = starting_index.clone();
let mut prefix = String::with_capacity(8); // enough for "12. [ ] "
Expand All @@ -56,8 +53,7 @@ where
match &mut index {
None => prefix.push_str("- "),
Some(i) => {
std::fmt::Write::write_fmt(&mut prefix, format_args!("{}. ", &i))
.unwrap();
std::fmt::Write::write_fmt(&mut prefix, format_args!("{}. ", &i)).unwrap();
*i += 1;
}
};
Expand Down Expand Up @@ -112,12 +108,7 @@ where
out.write_char('|');
for (idx, col) in row.iter().enumerate() {
out.write_char(' ');
pad_to(
out,
&col,
*column_widths.get(idx).unwrap_or(&0),
alignments.get(idx),
);
pad_to(out, &col, *column_widths.get(idx).unwrap_or(&0), alignments.get(idx));
out.write_str(" |");
}
out.write_char('\n');
Expand Down Expand Up @@ -250,9 +241,7 @@ where
out.write_str(value);
out.write_str(surround);
}
Inline::Link {
url, text, title, ..
} => {
Inline::Link { url, text, title, .. } => {
out.write_char('[');
write_line(out, text);
out.write_str("](");
Expand All @@ -265,9 +254,7 @@ where
out.write_char(')');
// TODO reference-style (non-inline) images
}
Inline::Image {
url, alt, title, ..
} => {
Inline::Image { url, alt, title, .. } => {
out.write_str("![");
out.write_str(alt);
out.write_str("](");
Expand Down
30 changes: 6 additions & 24 deletions src/fmt_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,55 +81,37 @@ mod test {

#[test]
fn left_pad() {
assert_eq!(
"a ",
output_and_get(|out| pad_to(out, "a", 5, Alignment::Left))
);
assert_eq!("a ", output_and_get(|out| pad_to(out, "a", 5, Alignment::Left)));
}

#[test]
fn right_pad() {
assert_eq!(
" a",
output_and_get(|out| pad_to(out, "a", 5, Alignment::Right))
);
assert_eq!(" a", output_and_get(|out| pad_to(out, "a", 5, Alignment::Right)));
}

/// center pad, with the same amount of padding on each side
#[test]
fn center_pad_even() {
assert_eq!(
" a ",
output_and_get(|out| pad_to(out, "a", 5, Alignment::Center))
);
assert_eq!(" a ", output_and_get(|out| pad_to(out, "a", 5, Alignment::Center)));
}

/// center pad, with different amount of padding on each side
#[test]
fn center_pad_uneven() {
assert_eq!(
" ab ",
output_and_get(|out| pad_to(out, "ab", 5, Alignment::Center))
);
assert_eq!(" ab ", output_and_get(|out| pad_to(out, "ab", 5, Alignment::Center)));
}

#[test]
fn string_already_right_size() {
for align in [Alignment::Left, Alignment::Center, Alignment::Right] {
assert_eq!(
"abcde",
output_and_get(|out| pad_to(out, "abcde", 5, align))
);
assert_eq!("abcde", output_and_get(|out| pad_to(out, "abcde", 5, align)));
}
}

#[test]
fn string_already_too_big() {
for align in [Alignment::Left, Alignment::Center, Alignment::Right] {
assert_eq!(
"abcdef",
output_and_get(|out| pad_to(out, "abcdef", 3, align))
);
assert_eq!("abcdef", output_and_get(|out| pad_to(out, "abcdef", 3, align)));
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ mod tree;

fn main() {
let mut contents = String::new();
stdin()
.read_to_string(&mut contents)
.expect("invalid input (not utf8)");
stdin().read_to_string(&mut contents).expect("invalid input (not utf8)");
let ast = markdown::to_mdast(&mut contents, &markdown::ParseOptions::gfm()).unwrap();
let mdq: MdqNode = ast.try_into().unwrap();

Expand Down
4 changes: 1 addition & 3 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ impl<W: Write> Output<W> {
}
}
},
WritingState::HaveNotWrittenAnything
| WritingState::IgnoringNewlines
| WritingState::Error => {}
WritingState::HaveNotWrittenAnything | WritingState::IgnoringNewlines | WritingState::Error => {}
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ impl Selector {
SelectResult::None // see TODO on Selector
}
MdqNode::BlockQuote { body } => SelectResult::Recurse(body),
MdqNode::List {
starting_index,
items,
} => {
MdqNode::List { starting_index, items } => {
let _is_ordered = starting_index.is_some(); // TODO use in selected
SelectResult::RecurseOwned(
items
Expand Down Expand Up @@ -139,9 +136,7 @@ impl Selector {
match result {
SelectResult::Found(results) => results,
SelectResult::Recurse(children) => self.find_in_children(children),
SelectResult::RecurseOwned(children) => {
children.iter().flat_map(|elem| self.find(elem)).collect()
}
SelectResult::RecurseOwned(children) => children.iter().flat_map(|elem| self.find(elem)).collect(),
SelectResult::None => Vec::new(),
}
}
Expand Down
Loading

0 comments on commit 5ef82a4

Please sign in to comment.