1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

refac: simplify config mechanism

This commit is contained in:
Kevin Amado 2024-11-23 20:20:51 -07:00
parent 6cf7503e4f
commit 04fe4d17dc
7 changed files with 11 additions and 37 deletions

2
Cargo.lock generated
View file

@ -10,6 +10,7 @@ dependencies = [
"pretty_assertions",
"rnix",
"rowan",
"serde",
]
[[package]]
@ -21,7 +22,6 @@ dependencies = [
"futures",
"num_cpus",
"rand",
"serde",
"serde_json",
"walkdir",
]

View file

@ -2,6 +2,7 @@
rnix = { version = "0.10.2", default-features = false, features = [] }
# rowan follows rnix
rowan = { version = "0.12.6", default-features = false, features = [] }
serde = { version = "*", default-features = false, features = ["derive"] }
[target.aarch64-unknown-linux-musl.dependencies.mimalloc]
default-features = false

View file

@ -1,11 +1,5 @@
use serde::Deserialize;
/// Configuration used by the formatter
#[derive(Clone)]
#[derive(Clone, Copy, Default, Deserialize)]
pub struct Config {}
use std::default::Default;
impl Default for Config {
fn default() -> Self {
Self {}
}
}

View file

@ -19,7 +19,6 @@ rand = { version = "*", default-features = false, features = [
"alloc",
"getrandom",
] }
serde = { version = "*", default-features = false, features = ["derive"] }
serde_json = { version = "*", default-features = false, features = ["std"] }
walkdir = { version = "*", default-features = false, features = [] }

View file

@ -10,7 +10,6 @@ use futures::stream::FuturesUnordered;
use futures::task::SpawnExt;
use crate::ads::random_ad;
use crate::config_options::ConfigOptions;
use crate::verbosity::Verbosity;
/// The Uncompromising Nix Code Formatter.
@ -110,8 +109,6 @@ fn format_paths(
let futures: FuturesUnordered<RemoteHandle<FormattedPath>> = paths
.into_iter()
.map(|path| {
let config = config.clone();
pool.spawn_with_handle(async move {
let status =
alejandra::format::in_fs(path.clone(), config, in_place);
@ -253,15 +250,12 @@ fn resolve_config(path: Option<&str>, verbosity: Verbosity) -> Config {
std::process::exit(1);
});
let config_file = serde_json::from_str::<ConfigOptions>(&contents)
.unwrap_or_else(|error| {
if verbosity.allows_errors() {
eprintln!("Errors found in config: {}", error);
}
std::process::exit(1);
});
config_file.into()
serde_json::from_str::<Config>(&contents).unwrap_or_else(|error| {
if verbosity.allows_errors() {
eprintln!("Errors found in config: {}", error);
}
std::process::exit(1);
})
} else {
Config::default()
}

View file

@ -1,13 +0,0 @@
use alejandra::config::Config;
use serde::Deserialize;
#[derive(Deserialize)]
pub(crate) struct ConfigOptions {}
impl From<ConfigOptions> for Config {
fn from(_config_options: ConfigOptions) -> Config {
let config = Config::default();
config
}
}

View file

@ -1,5 +1,4 @@
mod ads;
pub mod cli;
mod config_options;
mod find;
mod verbosity;