Skip to content

Commit

Permalink
Fixed clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ikrivosheev committed Nov 19, 2024
1 parent af0aa81 commit 58b585f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 42 deletions.
24 changes: 0 additions & 24 deletions .cargo/config

This file was deleted.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 4 additions & 3 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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())
});

Expand Down Expand Up @@ -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() {
Expand Down
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -207,7 +207,11 @@ fn _main() -> IoResult<()> {
let (is_posible_workspace, mut filtered_matches) =
matches.get_many::<String>("cwd").map_or((true, vec![dir.clone()]), |s| {
let args = s.filter(|it| *it != "sort").map(Into::into).collect::<Vec<_>>();
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 {
Expand Down Expand Up @@ -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> {
Expand Down
21 changes: 13 additions & 8 deletions src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn gather_headings(table: &Table, keys: &mut Vec<Heading>, 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() {
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 58b585f

Please sign in to comment.