Skip to content

Commit e7791cf

Browse files
committed
ci: satisfy rust formatting and clippy
1 parent c70252e commit e7791cf

8 files changed

Lines changed: 134 additions & 109 deletions

File tree

src/app.rs

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,9 @@ fn run_editor<W: io::Write>(
9595
let key = key_from_event(key);
9696
match app_state.handle_key(key, &mut keymap, &mut buffer, &mut view) {
9797
AppAction::Continue => {}
98-
AppAction::OpenFilePicker => open_file_from_picker(
99-
terminal,
100-
&mut buffer,
101-
&mut view,
102-
&mut app_state,
103-
)?,
98+
AppAction::OpenFilePicker => {
99+
open_file_from_picker(terminal, &mut buffer, &mut view, &mut app_state)?
100+
}
104101
AppAction::Quit => break,
105102
}
106103
render(
@@ -147,19 +144,11 @@ fn run_directory_picker<W: io::Write>(
147144
DirectoryPickerAction::Browse(path) => match DirectoryPicker::read(&path) {
148145
Ok(next_picker) => {
149146
picker = next_picker;
150-
render_directory_picker(
151-
&renderer,
152-
terminal.writer_mut(),
153-
&picker,
154-
)?;
147+
render_directory_picker(&renderer, terminal.writer_mut(), &picker)?;
155148
}
156149
Err(error) => {
157150
picker.set_status_message(format!("Open failed: {error}"));
158-
render_directory_picker(
159-
&renderer,
160-
terminal.writer_mut(),
161-
&picker,
162-
)?;
151+
render_directory_picker(&renderer, terminal.writer_mut(), &picker)?;
163152
}
164153
},
165154
DirectoryPickerAction::Open(path) => return Ok(Some(path)),
@@ -243,9 +232,7 @@ impl AppState {
243232

244233
match keymap.resolve(key) {
245234
KeymapResult::Command(commands::Command::SetMark) => self.set_mark(view),
246-
KeymapResult::Command(commands::Command::KillRegion) => {
247-
self.kill_region(buffer, view)
248-
}
235+
KeymapResult::Command(commands::Command::KillRegion) => self.kill_region(buffer, view),
249236
KeymapResult::Command(commands::Command::KillLine) => self.kill_line(buffer, view),
250237
KeymapResult::Command(commands::Command::Yank) => self.yank(buffer, view),
251238
KeymapResult::Command(commands::Command::RepeatSearch) => {
@@ -360,12 +347,7 @@ impl AppState {
360347
}
361348
}
362349

363-
fn run_command_line(
364-
&mut self,
365-
input: &str,
366-
buffer: &mut Buffer,
367-
view: &mut View,
368-
) -> AppAction {
350+
fn run_command_line(&mut self, input: &str, buffer: &mut Buffer, view: &mut View) -> AppAction {
369351
let trimmed = input.trim();
370352
let Some(command_text) = trimmed.strip_prefix('/') else {
371353
self.set_status("Commands must start with /", StatusKind::Error);
@@ -409,12 +391,7 @@ impl AppState {
409391
}
410392
}
411393

412-
fn run_search_command(
413-
&mut self,
414-
command: &str,
415-
buffer: &Buffer,
416-
view: &mut View,
417-
) -> AppAction {
394+
fn run_search_command(&mut self, command: &str, buffer: &Buffer, view: &mut View) -> AppAction {
418395
let query = command
419396
.strip_prefix("search")
420397
.map(str::trim)
@@ -1116,7 +1093,10 @@ mod tests {
11161093
assert_eq!(buffer.text(), "target");
11171094
assert_eq!(view.point(), 0);
11181095
let expected_status = format!("Opened {}", target_path.display());
1119-
assert_eq!(app.status_message.as_deref(), Some(expected_status.as_str()));
1096+
assert_eq!(
1097+
app.status_message.as_deref(),
1098+
Some(expected_status.as_str())
1099+
);
11201100
fs::remove_dir_all(dir).unwrap();
11211101
}
11221102

@@ -1200,7 +1180,13 @@ mod tests {
12001180
let mut buffer = buffer_with_text("notes.txt", "alpha beta alpha");
12011181
let mut view = View::new();
12021182

1203-
run_slash_command("/search alpha", &mut app, &mut keymap, &mut buffer, &mut view);
1183+
run_slash_command(
1184+
"/search alpha",
1185+
&mut app,
1186+
&mut keymap,
1187+
&mut buffer,
1188+
&mut view,
1189+
);
12041190
assert_eq!(view.point(), 11);
12051191

12061192
let action = app.handle_key(Key::Ctrl('s'), &mut keymap, &mut buffer, &mut view);
@@ -1221,7 +1207,13 @@ mod tests {
12211207
assert_eq!(app.status_message.as_deref(), Some("Usage: /search <text>"));
12221208
assert_eq!(app.status_kind, Some(StatusKind::Error));
12231209

1224-
run_slash_command("/search missing", &mut app, &mut keymap, &mut buffer, &mut view);
1210+
run_slash_command(
1211+
"/search missing",
1212+
&mut app,
1213+
&mut keymap,
1214+
&mut buffer,
1215+
&mut view,
1216+
);
12251217
assert_eq!(view.point(), 0);
12261218
assert_eq!(app.status_message.as_deref(), Some("Not found: missing"));
12271219
assert_eq!(app.status_kind, Some(StatusKind::Error));
@@ -1238,7 +1230,10 @@ mod tests {
12381230

12391231
assert_eq!(action, AppAction::Continue);
12401232
assert_eq!(buffer.text(), "old");
1241-
assert_eq!(app.status_message.as_deref(), Some("Unknown command: /bogus"));
1233+
assert_eq!(
1234+
app.status_message.as_deref(),
1235+
Some("Unknown command: /bogus")
1236+
);
12421237
}
12431238

12441239
fn start_dirty_quit_prompt(

src/buffer.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl Buffer {
224224
}
225225

226226
fn update_dirty(&mut self) {
227-
self.dirty = self.text.to_string() != self.clean_text;
227+
self.dirty = self.text != self.clean_text;
228228
}
229229
}
230230

@@ -251,7 +251,7 @@ fn clean_line_text(text: &str, line_idx: usize) -> String {
251251
};
252252

253253
if idx == line_idx {
254-
return line.trim_end_matches(&['\r', '\n']).to_string();
254+
return line.trim_end_matches(['\r', '\n']).to_string();
255255
}
256256
}
257257

@@ -326,8 +326,7 @@ fn ensure_parent_directory_exists(path: &Path) -> io::Result<()> {
326326
mod tests {
327327
use super::Buffer;
328328
use std::{
329-
fs,
330-
io,
329+
fs, io,
331330
path::PathBuf,
332331
time::{SystemTime, UNIX_EPOCH},
333332
};
@@ -551,7 +550,9 @@ mod tests {
551550
let error = buffer.save().unwrap_err();
552551

553552
assert_eq!(error.kind(), io::ErrorKind::NotFound);
554-
assert!(error.to_string().contains("parent directory does not exist"));
553+
assert!(error
554+
.to_string()
555+
.contains("parent directory does not exist"));
555556
assert!(buffer.is_dirty());
556557
assert!(!path.exists());
557558
remove_dir(dir);

src/commands.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ pub fn dispatch(command: Command, buffer: &mut Buffer, view: &mut View) -> Comma
6464
}
6565
CommandOutcome::default()
6666
}
67-
Command::KillLine
68-
| Command::KillRegion
69-
| Command::SetMark
70-
| Command::Yank => CommandOutcome::default(),
67+
Command::KillLine | Command::KillRegion | Command::SetMark | Command::Yank => {
68+
CommandOutcome::default()
69+
}
7170
Command::Undo => {
7271
if let Some(point) = buffer.undo() {
7372
view.set_point(point, buffer);
@@ -273,12 +272,10 @@ mod tests {
273272

274273
assert!(!outcome.quit);
275274
assert!(!outcome.save_failed);
276-
assert!(
277-
outcome
278-
.status_message
279-
.as_deref()
280-
.is_some_and(|message| message.contains("Wrote"))
281-
);
275+
assert!(outcome
276+
.status_message
277+
.as_deref()
278+
.is_some_and(|message| message.contains("Wrote")));
282279
assert!(!buffer.is_dirty());
283280
assert_eq!(fs::read_to_string(&path).unwrap(), "!old");
284281
fs::remove_dir_all(dir).unwrap();
@@ -293,12 +290,10 @@ mod tests {
293290

294291
assert!(outcome.save_failed);
295292
assert!(!outcome.quit);
296-
assert!(
297-
outcome
298-
.status_message
299-
.as_deref()
300-
.is_some_and(|message| message.contains("Save failed"))
301-
);
293+
assert!(outcome
294+
.status_message
295+
.as_deref()
296+
.is_some_and(|message| message.contains("Save failed")));
302297
assert!(buffer.is_dirty());
303298
fs::remove_dir_all(dir).unwrap();
304299
}

src/highlighter.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,11 @@ impl SyntaxHighlighter {
142142
let language = &languages[language_idx];
143143
let line_starts = line_start_offsets(lines);
144144
{
145-
let events = self.highlighter.highlight(
146-
&language.config,
147-
source.as_bytes(),
148-
None,
149-
|name| language_config_for_name(languages, name),
150-
);
145+
let events =
146+
self.highlighter
147+
.highlight(&language.config, source.as_bytes(), None, |name| {
148+
language_config_for_name(languages, name)
149+
});
151150
let Ok(events) = events else {
152151
return highlighted_lines;
153152
};
@@ -213,12 +212,11 @@ impl SyntaxHighlighter {
213212
continue;
214213
}
215214

216-
let events = self.highlighter.highlight(
217-
&language.config,
218-
line.as_bytes(),
219-
None,
220-
|name| language_config_for_name(languages, name),
221-
);
215+
let events =
216+
self.highlighter
217+
.highlight(&language.config, line.as_bytes(), None, |name| {
218+
language_config_for_name(languages, name)
219+
});
222220
let Ok(events) = events else {
223221
continue;
224222
};
@@ -514,7 +512,10 @@ mod tests {
514512
fn highlights_required_file_types() {
515513
let cases = [
516514
(Path::new("notes.md"), vec!["# Heading".to_string()]),
517-
(Path::new("data.json"), vec!["{\"enabled\": true}".to_string()]),
515+
(
516+
Path::new("data.json"),
517+
vec!["{\"enabled\": true}".to_string()],
518+
),
518519
(Path::new("config.toml"), vec!["enabled = true".to_string()]),
519520
];
520521

@@ -537,8 +538,14 @@ mod tests {
537538
language_label_for_path(Path::new("notes.markdown")),
538539
Some("MARKDOWN")
539540
);
540-
assert_eq!(language_label_for_path(Path::new("data.json")), Some("JSON"));
541-
assert_eq!(language_label_for_path(Path::new("config.toml")), Some("TOML"));
541+
assert_eq!(
542+
language_label_for_path(Path::new("data.json")),
543+
Some("JSON")
544+
);
545+
assert_eq!(
546+
language_label_for_path(Path::new("config.toml")),
547+
Some("TOML")
548+
);
542549
assert_eq!(language_label_for_path(Path::new("app.py")), Some("PYTHON"));
543550
assert_eq!(
544551
language_label_for_path(Path::new("index.jsx")),
@@ -548,7 +555,10 @@ mod tests {
548555
language_label_for_path(Path::new("app.tsx")),
549556
Some("TYPESCRIPT")
550557
);
551-
assert_eq!(language_label_for_path(Path::new("task.rake")), Some("RUBY"));
558+
assert_eq!(
559+
language_label_for_path(Path::new("task.rake")),
560+
Some("RUBY")
561+
);
552562
assert_eq!(language_label_for_path(Path::new("notes.txt")), None);
553563
}
554564

@@ -625,17 +635,25 @@ mod tests {
625635
let highlighted = highlighter.highlight_visible_lines(Path::new("notes.md"), &lines);
626636

627637
assert!(line_has_kind(&highlighted[0], HighlightKind::MarkupHeading));
628-
assert!(line_has_kind(&highlighted[0], HighlightKind::PunctuationSpecial));
629-
assert!(line_has_kind(&highlighted[1], HighlightKind::PunctuationSpecial));
630-
assert!(line_has_kind(&highlighted[2], HighlightKind::PunctuationSpecial));
638+
assert!(line_has_kind(
639+
&highlighted[0],
640+
HighlightKind::PunctuationSpecial
641+
));
642+
assert!(line_has_kind(
643+
&highlighted[1],
644+
HighlightKind::PunctuationSpecial
645+
));
646+
assert!(line_has_kind(
647+
&highlighted[2],
648+
HighlightKind::PunctuationSpecial
649+
));
631650
}
632651

633652
#[test]
634653
fn highlights_markdown_inline_markup() {
635654
let mut highlighter = SyntaxHighlighter::new();
636-
let lines = vec![
637-
"Use **bold**, *em*, `code`, and [link](https://example.com).".to_string(),
638-
];
655+
let lines =
656+
vec!["Use **bold**, *em*, `code`, and [link](https://example.com).".to_string()];
639657

640658
let highlighted = highlighter.highlight_visible_lines(Path::new("notes.md"), &lines);
641659

src/input.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ pub enum Key {
1717
}
1818

1919
pub fn key_from_event(event: KeyEvent) -> Key {
20-
if event.modifiers.contains(KeyModifiers::ALT)
21-
|| event.modifiers.contains(KeyModifiers::META)
22-
{
20+
if event.modifiers.contains(KeyModifiers::ALT) || event.modifiers.contains(KeyModifiers::META) {
2321
return Key::Unhandled;
2422
}
2523

0 commit comments

Comments
 (0)