diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index f474438..0000000 --- a/.cargo/config +++ /dev/null @@ -1,24 +0,0 @@ - -[alias] -mean-clippy = """\ - clippy --workspace --all-targets -- \ - -W rust_2018_idioms \ - -W semicolon_in_expressions_from_macros \ - -W unused_import_braces \ - -W unused_qualifications \ - -W clippy::branches_sharing_code \ - -W clippy::cloned_instead_of_copied \ - -W clippy::dbg_macro \ - -W clippy::empty_line_after_outer_attr \ - -W clippy::inefficient_to_string \ - -W clippy::macro_use_imports \ - -W clippy::map_flatten \ - -W clippy::mut_mut \ - -W clippy::needless_borrow \ - -A clippy::new_without_default \ - -W clippy::todo \ - -W clippy::unreadable_literal \ - -W clippy::unseparated_literal_suffix \ - -W clippy::useless_let_if_seq \ - -W clippy::wildcard_imports \ -""" diff --git a/Cargo.toml b/Cargo.toml index 8d85a29..63822ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,11 @@ description = "Check if tables and items in a .toml file are lexically sorted" repository = "https://github.com/DevinR528/cargo-sort" keywords = ["cargo", "subcommand", "dependencies", "sort", "check"] categories = ["development-tools::cargo-plugins", "development-tools"] -edition = "2018" +edition = "2021" readme = "README.md" exclude = ["examp", "fixtures"] default-run = "cargo-sort" +rust-version = "1.70" # [features] # fuzz = ["afl"] diff --git a/rustfmt.toml b/rustfmt.toml index 964b4c2..bdb55eb 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -3,7 +3,7 @@ wrap_comments = true imports_granularity = "Crate" newline_style = "Unix" use_small_heuristics = "Max" -version = "Two" +style_edition = "2021" fn_single_line = true max_width = 90 group_imports = "StdExternalCrate" diff --git a/src/fmt.rs b/src/fmt.rs index 51058e4..47bdc0a 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -18,6 +18,7 @@ const NEWLINE_PATTERN: &str = "\n"; /// assert!(config.trailing_comma); /// assert!(config.crlf); /// ``` +#[allow(dead_code)] pub struct Config { /// Use trailing comma where possible. /// @@ -174,7 +175,7 @@ fn fmt_value(value: &mut Value, config: &Config) { Value::Array(arr) => { if arr.to_string().len() > config.max_array_line_len { let arr_has_trailing_newline = - arr.trailing().as_str().map_or(false, |s| s.contains('\n')); + arr.trailing().as_str().is_some_and(|s| s.contains('\n')); let len = arr.len(); for (i, val) in arr.iter_mut().enumerate() { val.decor_mut().set_prefix(format!( @@ -238,7 +239,7 @@ fn fmt_table(table: &mut Table, config: &Config) { let keys: Vec<_> = table.iter().map(|(k, _)| k.to_owned()).collect(); for key in keys { - let is_value_for_space = table.get(&key).map_or(false, |item| { + let is_value_for_space = table.get(&key).is_some_and(|item| { item.is_value() && item.as_inline_table().map_or(true, |t| !t.is_dotted()) }); @@ -323,7 +324,7 @@ mod test { use similar_asserts::assert_eq; - use super::{Config, Document, fmt_toml}; + use super::{fmt_toml, Config, Document}; #[test] fn toml_fmt_check() { diff --git a/src/main.rs b/src/main.rs index f47aa22..e59a321 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,14 +2,14 @@ use std::{ borrow::Cow, env, fmt::Display, - fs::{OpenOptions, read_to_string}, + fs::{read_to_string, OpenOptions}, io::Write, path::{Path, PathBuf}, }; use clap::{ - Arg, ArgAction, ArgMatches, Command, crate_authors, crate_name, crate_version, - parser::ValueSource, + crate_authors, crate_name, crate_version, parser::ValueSource, Arg, ArgAction, + ArgMatches, Command, }; use fmt::Config; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; @@ -207,7 +207,11 @@ fn _main() -> IoResult<()> { let (is_posible_workspace, mut filtered_matches) = matches.get_many::("cwd").map_or((true, vec![dir.clone()]), |s| { let args = s.filter(|it| *it != "sort").map(Into::into).collect::>(); - if args.is_empty() { (true, vec![dir]) } else { (args.len() == 1, args) } + if args.is_empty() { + (true, vec![dir]) + } else { + (args.len() == 1, args) + } }); if flag_set("workspace", &matches) && is_posible_workspace { @@ -287,7 +291,11 @@ fn _main() -> IoResult<()> { } } - if flag { std::process::exit(0) } else { std::process::exit(1) } + if flag { + std::process::exit(0) + } else { + std::process::exit(1) + } } fn array_string_members(value: &toml_edit::Item) -> Vec<&str> { diff --git a/src/sort.rs b/src/sort.rs index 3eccc41..6c74b3f 100644 --- a/src/sort.rs +++ b/src/sort.rs @@ -123,7 +123,7 @@ fn gather_headings(table: &Table, keys: &mut Vec, depth: usize) { for (head, item) in table.iter() { match item { Item::Value(_) => { - if keys.last().map_or(false, |h| matches!(h, Heading::Complete(_))) { + if keys.last().is_some_and(|h| matches!(h, Heading::Complete(_))) { continue; } let next = match keys.pop().unwrap() { @@ -346,13 +346,18 @@ mod test { #[test] fn reorder() { let input = fs::read_to_string("examp/clippy.toml").unwrap(); - let sorted = super::sort_toml(&input, MATCHER, true, &[ - "package".to_owned(), - "features".to_owned(), - "dependencies".to_owned(), - "build-dependencies".to_owned(), - "dev-dependencies".to_owned(), - ]); + let sorted = super::sort_toml( + &input, + MATCHER, + true, + &[ + "package".to_owned(), + "features".to_owned(), + "dependencies".to_owned(), + "build-dependencies".to_owned(), + "dev-dependencies".to_owned(), + ], + ); assert_ne!(input, sorted.to_string()); } }