Skip to content

Commit 15a29f6

Browse files
committed
chore: cargo fmt
1 parent 8ba08bb commit 15a29f6

3 files changed

Lines changed: 24 additions & 26 deletions

File tree

‎src/formatter/mod.rs‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ use crate::{
88
util::overlaps,
99
};
1010
use itertools::Itertools;
11-
use std::cell::OnceCell;
1211
use rowan::{GreenNode, NodeOrToken, TextRange};
13-
use std::{
14-
cmp,
15-
collections::VecDeque,
16-
ops::Range,
17-
rc::Rc,
18-
};
12+
use std::cell::OnceCell;
13+
use std::{cmp, collections::VecDeque, ops::Range, rc::Rc};
1914

2015
#[macro_use]
2116
mod macros;
@@ -188,15 +183,14 @@ impl Default for Options {
188183

189184
impl Options {
190185
fn newline(&self) -> &'static str {
191-
if self.crlf {
192-
"\r\n"
193-
} else {
194-
"\n"
195-
}
186+
if self.crlf { "\r\n" } else { "\n" }
196187
}
197188

198189
fn newlines(&self, count: usize) -> impl Iterator<Item = &'static str> {
199-
std::iter::repeat_n(self.newline(), usize::min(count, self.allowed_blank_lines + 1))
190+
std::iter::repeat_n(
191+
self.newline(),
192+
usize::min(count, self.allowed_blank_lines + 1),
193+
)
200194
}
201195

202196
fn should_align_comments(&self, comment_count: usize) -> bool {
@@ -1249,9 +1243,11 @@ fn dangling_newlines(t: SyntaxToken) -> Option<usize> {
12491243

12501244
if let Some(nt) = t.next_sibling_or_token()
12511245
&& let Some(nnt) = nt.next_sibling_or_token()
1252-
&& nt.kind() == WHITESPACE && nnt.kind() == NEWLINE {
1253-
return Some(newline_count);
1254-
}
1246+
&& nt.kind() == WHITESPACE
1247+
&& nnt.kind() == NEWLINE
1248+
{
1249+
return Some(newline_count);
1250+
}
12551251

12561252
None
12571253
}

‎src/parser/mod.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ impl<'p> Parser<'p> {
146146
message: message.into(),
147147
});
148148
if let Some(t) = self.current_token
149-
&& !self.whitelisted(t) {
150-
self.token_as(ERROR).ok();
151-
}
149+
&& !self.whitelisted(t)
150+
{
151+
self.token_as(ERROR).ok();
152+
}
152153
} else {
153154
self.token_as(ERROR).ok();
154155
}
@@ -171,9 +172,10 @@ impl<'p> Parser<'p> {
171172

172173
fn add_error(&mut self, e: &Error) {
173174
if let Some(last_err) = self.errors.last_mut()
174-
&& last_err == e {
175-
return;
176-
}
175+
&& last_err == e
176+
{
177+
return;
178+
}
177179

178180
self.errors.push(e.clone());
179181
}

‎tests/formatter.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use oxc_toml::formatter::{format, Options};
1+
use oxc_toml::formatter::{Options, format};
22

33
#[test]
44
fn test_basic_formatting() {
55
const SOURCE: &str = "value=1\n[table]\nstring='some string'";
66
let formatted = format(SOURCE, Options::default());
7-
7+
88
// Should add spaces around =
99
assert!(formatted.contains("value = 1"));
1010
assert!(formatted.contains("string = 'some string'"));
@@ -22,7 +22,7 @@ foo="1.0"
2222
bar = "2.0"
2323
"#;
2424
let formatted = format(SOURCE, Options::default());
25-
25+
2626
// Should normalize spacing
2727
assert!(formatted.contains("name = \"test\""));
2828
assert!(formatted.contains("version = \"1.0.0\""));
@@ -34,7 +34,7 @@ bar = "2.0"
3434
fn test_formatter_preserves_comments() {
3535
const SOURCE: &str = "# Comment\nvalue=1";
3636
let formatted = format(SOURCE, Options::default());
37-
37+
3838
assert!(formatted.contains("# Comment"));
3939
assert!(formatted.contains("value = 1"));
4040
}

0 commit comments

Comments
 (0)