Skip to content

Commit 8db72b3

Browse files
committed
clippy
1 parent 82df356 commit 8db72b3

File tree

18 files changed

+99
-61
lines changed

18 files changed

+99
-61
lines changed

topiary-cli/src/cli.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ pub fn get_args() -> CLIResult<Cli> {
244244
// Make sure our FILE is not a directory
245245
if file.is_dir() {
246246
return Err(TopiaryError::Bin(
247-
format!("Cannot visualise directory \"{}\"; please provide a single file from disk or stdin.", file.to_string_lossy()),
247+
format!(
248+
"Cannot visualise directory \"{}\"; please provide a single file from disk or stdin.",
249+
file.to_string_lossy()
250+
),
248251
None,
249252
));
250253
}

topiary-cli/src/io.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
use nickel_lang_core::term::RichTerm;
1010
use tempfile::tempfile;
1111
use topiary_config::Configuration;
12-
use topiary_core::{formatter, Language, Operation, TopiaryQuery};
12+
use topiary_core::{Language, Operation, TopiaryQuery, formatter};
1313

1414
use crate::{
1515
cli::{AtLeastOneInput, ExactlyOneInput, FromStdin},
@@ -257,7 +257,9 @@ fn to_query_from_language(language: &topiary_config::language::Language) -> CLIR
257257
// builtin ones. Store the error, return that if we
258258
// fail to find anything, because the builtin error might be unexpected.
259259
Err(e) => {
260-
log::warn!("No query files found in any of the expected locations. Falling back to compile-time included files.");
260+
log::warn!(
261+
"No query files found in any of the expected locations. Falling back to compile-time included files."
262+
);
261263
to_query(&language.name).map_err(|_| e)?
262264
}
263265
};

topiary-cli/src/language.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{
22
collections::{
3-
hash_map::{DefaultHasher, Entry},
43
HashMap,
4+
hash_map::{DefaultHasher, Entry},
55
},
66
hash::{Hash, Hasher},
77
sync::Arc,

topiary-cli/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use std::{
1212
};
1313

1414
use error::Benign;
15-
use tabled::{settings::Style, Table};
15+
use tabled::{Table, settings::Style};
1616
use topiary_config::source::Source;
17-
use topiary_core::{check_query_coverage, formatter, Operation};
17+
use topiary_core::{Operation, check_query_coverage, formatter};
1818

1919
use crate::{
2020
cli::Commands,
2121
error::{CLIError, CLIResult, TopiaryError},
22-
io::{read_input, Inputs, OutputFile},
22+
io::{Inputs, OutputFile, read_input},
2323
language::LanguageDefinitionCache,
2424
};
2525

@@ -194,7 +194,7 @@ async fn run() -> CLIResult<()> {
194194
.await
195195
.inspect_err(|e| {
196196
// nickel may not be present in user config so log as info
197-
log::info!("Config formatting error: {}", e);
197+
log::info!("Config formatting error: {e}");
198198
})
199199
.is_ok()
200200
{

topiary-config/src/error.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,42 @@ pub enum TopiaryConfigFetchingError {
3636
impl fmt::Display for TopiaryConfigError {
3737
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3838
match self {
39-
TopiaryConfigError::FileNotFound(path) => write!(f, "We tried to find your configuration file at {}, but failed to do so. Make sure the file exists.", path.to_string_lossy()),
40-
TopiaryConfigError::UnknownLanguage(lang) => write!(f, "You were looking for language \"{lang}\", but we do not know that language."),
41-
TopiaryConfigError::UnknownExtension(ext) => write!(f, "You tried to format a file with extension: \"{ext}\", but we do not know that extension. Make sure the extension is in your configuration file!"),
42-
TopiaryConfigError::NoExtension(path) => write!(f, "You tried to format {} without specifying a language, but we cannot automatically detect the language because we can't find the filetype extension.", path.to_string_lossy()),
39+
TopiaryConfigError::FileNotFound(path) => write!(
40+
f,
41+
"We tried to find your configuration file at {}, but failed to do so. Make sure the file exists.",
42+
path.to_string_lossy()
43+
),
44+
TopiaryConfigError::UnknownLanguage(lang) => write!(
45+
f,
46+
"You were looking for language \"{lang}\", but we do not know that language."
47+
),
48+
TopiaryConfigError::UnknownExtension(ext) => write!(
49+
f,
50+
"You tried to format a file with extension: \"{ext}\", but we do not know that extension. Make sure the extension is in your configuration file!"
51+
),
52+
TopiaryConfigError::NoExtension(path) => write!(
53+
f,
54+
"You tried to format {} without specifying a language, but we cannot automatically detect the language because we can't find the filetype extension.",
55+
path.to_string_lossy()
56+
),
4357
#[cfg(not(target_arch = "wasm32"))]
44-
TopiaryConfigError::QueryFileNotFound(path) => write!(f, "We could not find the query file: \"{}\" anywhere. If you use the TOPIARY_LANGUAGE_DIR environment variable, make sure it set set correctly.", path.to_string_lossy()),
58+
TopiaryConfigError::QueryFileNotFound(path) => write!(
59+
f,
60+
"We could not find the query file: \"{}\" anywhere. If you use the TOPIARY_LANGUAGE_DIR environment variable, make sure it set set correctly.",
61+
path.to_string_lossy()
62+
),
4563
TopiaryConfigError::Io(error) => write!(f, "We encountered an io error: {error}"),
46-
TopiaryConfigError::Missing => write!(f, "A configuration file is missing. If you passed a configuration file, make sure it exists."),
47-
TopiaryConfigError::TreeSitterFacade(_) => write!(f, "We could not load the grammar for the given language"),
48-
TopiaryConfigError::Nickel(e) => write!(f, "Nickel error: {e:#?}\n\nDid you forget to add a \"priority\" annotation in your config file?"),
64+
TopiaryConfigError::Missing => write!(
65+
f,
66+
"A configuration file is missing. If you passed a configuration file, make sure it exists."
67+
),
68+
TopiaryConfigError::TreeSitterFacade(_) => {
69+
write!(f, "We could not load the grammar for the given language")
70+
}
71+
TopiaryConfigError::Nickel(e) => write!(
72+
f,
73+
"Nickel error: {e:#?}\n\nDid you forget to add a \"priority\" annotation in your config file?"
74+
),
4975
TopiaryConfigError::NickelDeserialization(e) => write!(f, "Nickel error: {e:#?}"),
5076
#[cfg(not(target_arch = "wasm32"))]
5177
TopiaryConfigError::Fetching(e) => write!(f, "Error Fetching Language: {e}"),

topiary-config/src/language.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use anyhow::anyhow;
66
#[cfg(not(target_arch = "wasm32"))]
77
use gix::{
8+
ObjectId,
89
interrupt::IS_INTERRUPTED,
910
progress::Discard,
10-
remote::{self, fetch, fetch::refmap, Direction},
11+
remote::{self, Direction, fetch, fetch::refmap},
1112
worktree::state::checkout,
12-
ObjectId,
1313
};
1414
use std::collections::HashSet;
1515
#[cfg(not(target_arch = "wasm32"))]
@@ -151,7 +151,7 @@ impl Language {
151151
GrammarSource::Path(_) => {
152152
return Err(TopiaryConfigFetchingError::GrammarFileNotFound(
153153
library_path,
154-
))
154+
));
155155
}
156156
}
157157
}

topiary-config/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ impl Configuration {
5555
#[allow(clippy::result_large_err)]
5656
pub fn fetch(merge: bool, file: &Option<PathBuf>) -> TopiaryConfigResult<(Self, RichTerm)> {
5757
// If we have an explicit file, fail if it doesn't exist
58-
if let Some(path) = file {
59-
if !path.exists() {
60-
return Err(TopiaryConfigError::FileNotFound(path.to_path_buf()));
61-
}
58+
if let Some(path) = file
59+
&& !path.exists()
60+
{
61+
return Err(TopiaryConfigError::FileNotFound(path.to_path_buf()));
6262
}
6363

6464
if merge {

topiary-core/benches/benchmark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use criterion::async_executor::FuturesExecutor;
2-
use criterion::{criterion_group, criterion_main, Criterion};
2+
use criterion::{Criterion, criterion_group, criterion_main};
33
use std::fs;
44
use std::io;
5-
use topiary_core::{formatter, Language, Operation, TopiaryQuery};
5+
use topiary_core::{Language, Operation, TopiaryQuery, formatter};
66

77
async fn format() {
88
let input = fs::read_to_string("../topiary-cli/tests/samples/input/nickel.ncl").unwrap();

topiary-core/src/atom_collection.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::{
88
use topiary_tree_sitter_facade::Node;
99

1010
use crate::{
11-
tree_sitter::NodeExt, Atom, Capitalisation, FormatterError, FormatterResult, ScopeCondition,
12-
ScopeInformation,
11+
Atom, Capitalisation, FormatterError, FormatterResult, ScopeCondition, ScopeInformation,
12+
tree_sitter::NodeExt,
1313
};
1414

1515
/// A struct that holds sets of node IDs that have line breaks before or after them.
@@ -206,14 +206,14 @@ impl AtomCollection {
206206
log::debug!("Skipping because context is single-line and #multi_line_only! is set");
207207
return Ok(());
208208
}
209-
if let Some(parent_id) = self.parent_leaf_nodes.get(&node.id()) {
210-
if *parent_id != node.id() {
211-
log::debug!(
212-
"Skipping because the match occurred below a leaf node: {}",
213-
node.display_one_based()
214-
);
215-
return Ok(());
216-
}
209+
if let Some(parent_id) = self.parent_leaf_nodes.get(&node.id())
210+
&& *parent_id != node.id()
211+
{
212+
log::debug!(
213+
"Skipping because the match occurred below a leaf node: {}",
214+
node.display_one_based()
215+
);
216+
return Ok(());
217217
}
218218

219219
match name {
@@ -404,10 +404,9 @@ impl AtomCollection {
404404
single_line_no_indent,
405405
..
406406
} = a
407+
&& *id == node.id()
407408
{
408-
if *id == node.id() {
409-
*single_line_no_indent = true;
410-
}
409+
*single_line_no_indent = true;
411410
}
412411
}
413412

@@ -421,10 +420,9 @@ impl AtomCollection {
421420
multi_line_indent_all,
422421
..
423422
} = a
423+
&& *id == node.id()
424424
{
425-
if *id == node.id() {
426-
*multi_line_indent_all = true;
427-
}
425+
*multi_line_indent_all = true;
428426
}
429427
}
430428
}
@@ -433,7 +431,7 @@ impl AtomCollection {
433431
return Err(FormatterError::Query(
434432
format!("@{unknown} is not a valid capture name"),
435433
None,
436-
))
434+
));
437435
}
438436
}
439437

@@ -778,7 +776,9 @@ impl AtomCollection {
778776
Some(multi_line),
779777
));
780778
} else {
781-
log::warn!("Found several measuring scopes in a single regular scope {scope_id:?}");
779+
log::warn!(
780+
"Found several measuring scopes in a single regular scope {scope_id:?}"
781+
);
782782
force_apply_modifications = true;
783783
}
784784
} else {
@@ -974,7 +974,10 @@ impl AtomCollection {
974974
// If two whitespace atoms follow each other, remove the non-dominant one.
975975
(
976976
moved_prev @ (Atom::Space | Atom::Hardline | Atom::Blankline),
977-
[head @ (Atom::Space | Atom::Hardline | Atom::Blankline), tail @ ..],
977+
[
978+
head @ (Atom::Space | Atom::Hardline | Atom::Blankline),
979+
tail @ ..,
980+
],
978981
) => {
979982
if head.dominates(moved_prev) {
980983
*moved_prev = Atom::Empty;
@@ -1248,7 +1251,7 @@ where
12481251

12491252
#[cfg(test)]
12501253
mod test {
1251-
use crate::{atom_collection::AtomCollection, Atom};
1254+
use crate::{Atom, atom_collection::AtomCollection};
12521255
use test_log::test;
12531256

12541257
#[test]

topiary-core/src/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! Named syntax nodes are elliptical; anonymous are rectangular.
33
use std::{borrow::Cow, fmt, io};
44

5-
use crate::{tree_sitter::SyntaxNode, FormatterResult};
5+
use crate::{FormatterResult, tree_sitter::SyntaxNode};
66

77
/// Doubly escapes whitespace (\n and \t) so it is
88
/// rendered as the escaped value in the GraphViz output

0 commit comments

Comments
 (0)