Skip to content

Commit

Permalink
chore: Additional clippy lints and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
VorpalBlade committed Sep 6, 2024
1 parent fa76bf7 commit d93da4a
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 87 deletions.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,20 @@ tempfile = { version = "3.12.0", default-features = false }
[lints.rust]
rust-2018-idioms = "warn"
unreachable_pub = "warn"
unused_qualifications = "warn"

[lints.clippy]
assigning_clones = "warn"
doc_markdown = "warn"
format_push_string = "warn"
needless_pass_by_value = "warn"
ptr_as_ptr = "warn"
redundant_clone = "warn"
redundant_closure_for_method_calls = "warn"
semicolon_if_nothing_returned = "warn"
undocumented_unsafe_blocks = "warn"
uninlined_format_args = "warn"
unnecessary_box_returns = "warn"
unnecessary_safety_doc = "warn"
unwrap_used = "warn"
wildcard_imports = "warn"
17 changes: 7 additions & 10 deletions src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@
// Doc comments are used to generate --help, not to for rustdoc.
#![allow(clippy::doc_markdown)]

use std::fs::File;
use std::io::Write;

use crate::config;
use crate::utils::Chezmoi;
use crate::utils::ChezmoiVersion;
use crate::utils::CHEZMOI_AUTO_SOURCE_VERSION;
use anyhow::anyhow;
use anyhow::Context;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use indoc::formatdoc;
use ini_merge::filter::filter_ini;
use std::fs::File;
use std::io::Write;
use strum::Display;
use strum::EnumIter;
use strum::EnumMessage;
use strum::EnumString;
use strum::IntoStaticStr;

use ini_merge::filter::filter_ini;

use crate::config;
use crate::utils::Chezmoi;
use crate::utils::ChezmoiVersion;
use crate::utils::CHEZMOI_AUTO_SOURCE_VERSION;

#[cfg(test)]
mod tests;

Expand Down
31 changes: 13 additions & 18 deletions src/add/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
//! | Existing (modify_) | Normal | Update data file |
//! | Existing (modify_) | Smart | Update data file |
use super::internal_filter;
use crate::utils::Chezmoi;
use crate::utils::ChezmoiVersion;
use crate::utils::CHEZMOI_AUTO_SOURCE_VERSION;
use crate::Style;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use indoc::indoc;
Expand All @@ -24,13 +29,6 @@ use pretty_assertions::assert_eq;
use tempfile::tempdir;
use tempfile::TempDir;

use crate::utils::Chezmoi;
use crate::utils::ChezmoiVersion;
use crate::utils::CHEZMOI_AUTO_SOURCE_VERSION;
use crate::Style;

use super::internal_filter;

#[derive(Debug)]
struct FilterTest {
cfg: &'static str,
Expand Down Expand Up @@ -258,13 +256,12 @@ fn assert_nothing_added(chezmoi: &DummyChezmoi) {
}

mod versions {
use super::assert_nothing_added;
use super::DummyChezmoi;
use crate::add::add;
use crate::add::Mode;
use crate::Style;

use super::assert_nothing_added;
use super::DummyChezmoi;

#[test]
fn check_error_on_old_chezmoi() {
// Check that --style path errors on old chezmoi
Expand All @@ -288,14 +285,13 @@ mod versions {
}

mod path_tmpl {
use crate::add::add;
use crate::add::Mode;
use crate::Style;

use super::assert_default_basic;
use super::assert_default_script;
use super::assert_unchanged_script;
use super::DummyChezmoi;
use crate::add::add;
use crate::add::Mode;
use crate::Style;

#[test]
fn check_add_normal_missing() {
Expand Down Expand Up @@ -419,14 +415,13 @@ mod path_tmpl {
}

mod path {
use crate::add::add;
use crate::add::Mode;
use crate::Style;

use super::assert_default_basic;
use super::assert_default_script;
use super::assert_unchanged_script;
use super::DummyChezmoi;
use crate::add::add;
use crate::add::Mode;
use crate::Style;

#[test]
fn check_add_normal_missing() {
Expand Down
3 changes: 1 addition & 2 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Doc comments are used to generate --help, not to for rustdoc.
#![allow(clippy::doc_markdown)]

use crate::add::Style;
use bpaf::short;
use bpaf::Bpaf;
use bpaf::Parser;
Expand All @@ -12,8 +13,6 @@ use itertools::Itertools;
use strum::EnumMessage;
use strum::IntoEnumIterator;

use crate::add::Style;

/// Parser for `--style`
fn style() -> impl Parser<Style> {
const DEFAULT: Style = Style::Auto;
Expand Down
20 changes: 8 additions & 12 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
//! Describes configuration file format
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Debug;
use std::str::FromStr;

use self::parser::Directive;
use self::parser::Matcher;
use crate::transforms::Transform;
use anyhow::anyhow;
use anyhow::Context;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use winnow::Parser;

use ini_merge::filter::FilterAction;
use ini_merge::filter::FilterActions;
use ini_merge::filter::FilterActionsBuilder;
Expand All @@ -18,11 +14,11 @@ use ini_merge::mutations::Action;
use ini_merge::mutations::Mutations;
use ini_merge::mutations::MutationsBuilder;
use ini_merge::mutations::SectionAction;

use crate::transforms::Transform;

use self::parser::Directive;
use self::parser::Matcher;
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Debug;
use std::str::FromStr;
use winnow::Parser;

mod parser;

Expand Down
4 changes: 1 addition & 3 deletions src/config/parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Defines the winnow parser for the config file format.
use std::collections::HashMap;

use winnow::ascii::escaped_transform;
use winnow::ascii::space1;
use winnow::combinator::alt;
Expand Down Expand Up @@ -268,11 +267,10 @@ fn quoted_string_nl(i: &mut &str) -> PResult<String> {

#[cfg(test)]
mod tests {
use super::*;
use indoc::indoc;
use pretty_assertions::assert_eq;

use super::*;

#[test]
fn check_quoted_string() {
let (rem, out) = quoted_string.parse_peek("\"test \\\" \\\\input\"").unwrap();
Expand Down
23 changes: 10 additions & 13 deletions src/doctor.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
//! Sanity checking of environment
use std::env::VarError;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Write;
use std::process::Command;

use crate::utils::Chezmoi;
use crate::utils::ChezmoiVersion;
use crate::utils::RealChezmoi;
use crate::utils::CHEZMOI_AUTO_SOURCE_VERSION;
use anstream::println;
use anstream::stdout;
use anstyle::Effects;
use anstyle::Reset;
use anyhow::anyhow;
use anyhow::Context;
use itertools::Itertools;

use medic::Check;
use medic::CheckResult;

use crate::utils::Chezmoi;
use crate::utils::ChezmoiVersion;
use crate::utils::RealChezmoi;
use crate::utils::CHEZMOI_AUTO_SOURCE_VERSION;
use std::env::VarError;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Write;
use std::process::Command;

/// Perform environment sanity check
pub(crate) fn doctor() -> anyhow::Result<()> {
Expand Down
17 changes: 7 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
//! This is not a stable API, and is to be used internally by the binary and
//! the integration tests only.
use std::fs::File;
use std::io::Read;
use std::io::Write;

use anyhow::Context;
use indoc::printdoc;

use crate::utils::RealChezmoi;
use crate::utils::CHEZMOI_AUTO_SOURCE_VERSION;
pub use add::Style;
use anyhow::Context;
pub use arguments::parse_args;
pub use arguments::ChmmArgs;
use indoc::printdoc;
use ini_merge::merge::merge_ini;

use crate::utils::RealChezmoi;
use crate::utils::CHEZMOI_AUTO_SOURCE_VERSION;
use std::fs::File;
use std::io::Read;
use std::io::Write;

mod add;
mod arguments;
Expand Down
14 changes: 6 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
#![warn(clippy::semicolon_if_nothing_returned)]
#![warn(clippy::wildcard_imports)]

use std::io::stdin;
use std::io::stdout;
use std::io::BufWriter;
use std::io::Write;

use anstyle::AnsiColor;
use chezmoi_modify_manager::inner_main;
use chezmoi_modify_manager::parse_args;
use env_logger::Builder;
use env_logger::Env;
use log::Level;

use chezmoi_modify_manager::inner_main;
use chezmoi_modify_manager::parse_args;
use std::io::stdin;
use std::io::stdout;
use std::io::BufWriter;
use std::io::Write;

fn main() -> anyhow::Result<()> {
// Set up logging
Expand Down
4 changes: 1 addition & 3 deletions src/transforms.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! Defines supported transforms.
use ini_merge::mutations::transforms as ini_transforms;
use std::collections::HashMap;

use strum::EnumIter;
use strum::EnumMessage;
use strum::EnumString;
use strum::IntoStaticStr;

use ini_merge::mutations::transforms as ini_transforms;

#[allow(clippy::doc_markdown)]
/// Supported transforms
///
Expand Down
3 changes: 1 addition & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! Some shared utility functions
use std::env::VarError;

use anyhow::anyhow;
use anyhow::Context;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use duct::cmd;
use regex::Regex;
use std::env::VarError;

/// Represents the version number of chezmoi
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
10 changes: 4 additions & 6 deletions tests/integration/data_driven.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! Data & config driven tests.
use std::fs::File;
use std::io::BufReader;
use std::io::Read;

use camino::Utf8PathBuf;
use pretty_assertions::assert_eq;

use chezmoi_modify_manager::inner_main;
use chezmoi_modify_manager::ChmmArgs;
use pretty_assertions::assert_eq;
use std::fs::File;
use std::io::BufReader;
use std::io::Read;

/// Find all the test cases
fn find_test_cases() -> anyhow::Result<Vec<Utf8PathBuf>> {
Expand Down

0 comments on commit d93da4a

Please sign in to comment.