Skip to content

Commit

Permalink
chore(rustfmt): Set up and run group_imports and imports_granularity
Browse files Browse the repository at this point in the history
A dream come true. The messiness was getting out
of hand
  • Loading branch information
alexpovel committed Aug 17, 2024
1 parent 7bddffb commit 15b6848
Show file tree
Hide file tree
Showing 40 changed files with 279 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
hooks:
- id: cargo-fmt
name: cargo fmt
entry: cargo fmt --
entry: cargo +nightly fmt -- --check
language: system
types:
- rust
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"[markdown]": {
// README.md has tests which are sensitive to all whitespace being present
"files.trimTrailingWhitespace": false,
}
},
"rust-analyzer.rustfmt.extraArgs": [
"+nightly", // Relying on some unstable features, see `rustfmt.toml`
],
}
13 changes: 6 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ mod hcl {
#[cfg(feature = "german")]
#[allow(unreachable_pub)] // Cannot get this to play nice with clippy
mod natural_languages {
use std::env;
use std::fs::{self, File};
use std::io::{BufReader, BufWriter};
use std::{
env,
fs::{self, File},
path::Path,
};
use std::path::Path;

pub fn generate_word_lists() {
let base_source_path = Path::new("data/word-lists");
Expand Down Expand Up @@ -80,13 +78,14 @@ mod natural_languages {

#[cfg(feature = "german")]
mod german {
use decompound::{decompound, DecompositionOptions};
use rayon::prelude::*;
use std::collections::HashSet;
use std::env;
use std::io::{BufReader, BufWriter, Read, Write};
use std::sync::Mutex;

use decompound::{decompound, DecompositionOptions};
use rayon::prelude::*;

macro_rules! time_it {
($name:expr, $e:expr) => {{
let now = std::time::Instant::now();
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group_imports = "StdExternalCrate" # Unstable
imports_granularity = "Module" # Unstable
3 changes: 2 additions & 1 deletion src/actions/deletion/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::Action;
use log::info;

use super::Action;

/// Deletes everything in the input.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Deletion {}
Expand Down
17 changes: 8 additions & 9 deletions src/actions/german/driver.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use crate::actions::{
german::{
machine::{StateMachine, Transition},
words::{Replace, Replacement, WordCasing},
},
Action,
};
use std::sync::LazyLock;

use cached::proc_macro::cached;
use cached::SizedCache;
use decompound::{decompound, DecompositionOptions};
use itertools::Itertools;
use itertools::MinMaxResult::{MinMax, NoElements, OneElement};
use log::{debug, trace};
use std::sync::LazyLock;
use unicode_titlecase::StrTitleCase;

use crate::actions::german::machine::{StateMachine, Transition};
use crate::actions::german::words::{Replace, Replacement, WordCasing};
use crate::actions::Action;

/// German language action, responsible for Umlauts and Eszett.
///
/// This action is responsible for applying the following rules, [**where
Expand Down Expand Up @@ -558,9 +556,10 @@ fn is_valid(word: &str, predicate: &impl Fn(&str) -> bool) -> bool {

#[cfg(test)]
mod tests {
use super::*;
use rstest::rstest;

use super::*;

#[test]
fn test_word_list_is_not_filtered() {
let mut stream = SET.stream();
Expand Down
10 changes: 5 additions & 5 deletions src/actions/german/machine.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{
LetterCasing::Lower, LetterCasing::Upper, SpecialCharacter, SpecialCharacter::Eszett,
SpecialCharacter::Umlaut, Umlaut::Ae, Umlaut::Oe, Umlaut::Ue, Word,
};

use log::trace;

use super::LetterCasing::{Lower, Upper};
use super::SpecialCharacter::{Eszett, Umlaut};
use super::Umlaut::{Ae, Oe, Ue};
use super::{SpecialCharacter, Word};

#[derive(Default, Debug)]
enum State {
#[default]
Expand Down
10 changes: 7 additions & 3 deletions src/actions/german/words.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fmt::Display;
use std::ops::Range;

use itertools::Itertools;
use std::{fmt::Display, ops::Range};

#[derive(Debug, PartialEq, Eq)]
pub(super) enum WordCasing {
Expand Down Expand Up @@ -216,10 +218,11 @@ impl Replace for String {

#[cfg(test)]
mod tests {
use rstest::rstest;

use super::WordCasing::*;
use super::WordCasingError::*;
use super::*;
use rstest::rstest;

#[rstest]
// Lowercase
Expand Down Expand Up @@ -253,9 +256,10 @@ mod tests {
#[cfg(test)]
#[allow(clippy::ignored_unit_patterns)] // in `proptest` macro, cannot be avoided
mod properties {
use super::*;
use proptest::prelude::*;

use super::*;

proptest! {
#![proptest_config(ProptestConfig::with_cases(10_000))]
#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/actions/lower/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::Action;
use log::info;

use super::Action;

/// Renders in lowercase.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Lower {}
Expand Down
7 changes: 5 additions & 2 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ mod symbols;
mod titlecase;
mod upper;

use crate::scoping::scope::ScopeContext;
use std::error::Error;
use std::fmt;

pub use deletion::Deletion;
#[cfg(feature = "german")]
pub use german::German;
pub use lower::Lower;
pub use normalization::Normalization;
pub use replace::{Replacement, ReplacementError};
use std::{error::Error, fmt};
pub use style::Style;
#[cfg(feature = "symbols")]
pub use symbols::{inversion::Symbols as SymbolsInversion, Symbols};
pub use titlecase::Titlecase;
pub use upper::Upper;

use crate::scoping::scope::ScopeContext;

/// An action in the processing pipeline.
///
/// Actions are the core of the text processing pipeline and can be applied in any
Expand Down
3 changes: 2 additions & 1 deletion src/actions/normalization/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::Action;
use unicode_categories::UnicodeCategories;
use unicode_normalization::UnicodeNormalization;

use super::Action;

/// Performs Unicode normalization.
///
/// Uses NFD (Normalization Form D), canonical decomposition.
Expand Down
9 changes: 6 additions & 3 deletions src/actions/replace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use super::{Action, ActionError};
use crate::scoping::scope::ScopeContext;
use std::error::Error;
use std::fmt;

use log::{debug, info};
use std::{error::Error, fmt};
use unescape::unescape;
use variables::{inject_variables, VariableExpressionError};

use super::{Action, ActionError};
use crate::scoping::scope::ScopeContext;

/// Items for dealing with variables in replacement values.
pub mod variables;

Expand Down
11 changes: 8 additions & 3 deletions src/actions/replace/variables.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::scoping::regex::CaptureGroup;
use std::collections::HashMap;
use std::error::Error;
use std::fmt;

use log::trace;
use std::{collections::HashMap, error::Error, fmt};

use crate::scoping::regex::CaptureGroup;

type Variables<'a> = HashMap<CaptureGroup, &'a str>;

Expand Down Expand Up @@ -282,9 +286,10 @@ impl Error for VariableExpressionError {}

#[cfg(test)]
mod test {
use super::*;
use rstest::*;

use super::*;

#[fixture]
fn variables() -> Variables<'static> {
Variables::from([
Expand Down
3 changes: 2 additions & 1 deletion src/actions/style/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::Action;
pub use colored::{Color, ColoredString, Colorize, Styles};

use super::Action;

/// Renders in the given style.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Style {
Expand Down
11 changes: 7 additions & 4 deletions src/actions/symbols/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::collections::VecDeque;

#[cfg(test)]
use enum_iterator::{all, Sequence};

#[cfg(all(doc, feature = "german"))]
use super::German;
use crate::actions::Action;
#[cfg(test)]
use enum_iterator::{all, Sequence};
use std::collections::VecDeque;

pub mod inversion;

Expand Down Expand Up @@ -223,9 +225,10 @@ fn replace(stack: &mut Vec<char>, symbol: Symbol) {

#[cfg(test)]
mod tests {
use super::*;
use rstest::rstest;

use super::*;

#[rstest]
#[case("", "")]
#[case(" ", " ")]
Expand Down
3 changes: 2 additions & 1 deletion src/actions/titlecase/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::Action;
use titlecase::titlecase;

use super::Action;

/// Renders in titlecase.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Titlecase {}
Expand Down
10 changes: 7 additions & 3 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{fs::File, io::Read, path::Path};
use std::fs::File;
use std::io::Read;
use std::path::Path;

/// A trait to facilitate finding corresponding, in one sense or another, files.
///
Expand Down Expand Up @@ -93,10 +95,12 @@ pub(crate) fn find_interpreter(source: &mut impl Read) -> Option<String> {

#[cfg(test)]
mod test {
use super::*;
use rstest::rstest;
use std::io::Cursor;

use rstest::rstest;

use super::*;

#[rstest]
#[case("", None)]
#[case(&" ".repeat(64), None)]
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@
//! # }
//! ```
#[cfg(doc)]
use std::ops::Range;

#[cfg(doc)]
use crate::{
actions::Action,
Expand All @@ -149,8 +152,6 @@ use crate::{
Scoper,
},
};
#[cfg(doc)]
use std::ops::Range;

/// Main components around [`Action`]s.
pub mod actions;
Expand Down
Loading

0 comments on commit 15b6848

Please sign in to comment.