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:
parent
6cf7503e4f
commit
04fe4d17dc
7 changed files with 11 additions and 37 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -10,6 +10,7 @@ dependencies = [
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"rnix",
|
"rnix",
|
||||||
"rowan",
|
"rowan",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -21,7 +22,6 @@ dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
rnix = { version = "0.10.2", default-features = false, features = [] }
|
rnix = { version = "0.10.2", default-features = false, features = [] }
|
||||||
# rowan follows rnix
|
# rowan follows rnix
|
||||||
rowan = { version = "0.12.6", default-features = false, features = [] }
|
rowan = { version = "0.12.6", default-features = false, features = [] }
|
||||||
|
serde = { version = "*", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
[target.aarch64-unknown-linux-musl.dependencies.mimalloc]
|
[target.aarch64-unknown-linux-musl.dependencies.mimalloc]
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// Configuration used by the formatter
|
/// Configuration used by the formatter
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Copy, Default, Deserialize)]
|
||||||
pub struct Config {}
|
pub struct Config {}
|
||||||
|
|
||||||
use std::default::Default;
|
|
||||||
|
|
||||||
impl Default for Config {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ rand = { version = "*", default-features = false, features = [
|
||||||
"alloc",
|
"alloc",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
] }
|
] }
|
||||||
serde = { version = "*", default-features = false, features = ["derive"] }
|
|
||||||
serde_json = { version = "*", default-features = false, features = ["std"] }
|
serde_json = { version = "*", default-features = false, features = ["std"] }
|
||||||
walkdir = { version = "*", default-features = false, features = [] }
|
walkdir = { version = "*", default-features = false, features = [] }
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ use futures::stream::FuturesUnordered;
|
||||||
use futures::task::SpawnExt;
|
use futures::task::SpawnExt;
|
||||||
|
|
||||||
use crate::ads::random_ad;
|
use crate::ads::random_ad;
|
||||||
use crate::config_options::ConfigOptions;
|
|
||||||
use crate::verbosity::Verbosity;
|
use crate::verbosity::Verbosity;
|
||||||
|
|
||||||
/// The Uncompromising Nix Code Formatter.
|
/// The Uncompromising Nix Code Formatter.
|
||||||
|
@ -110,8 +109,6 @@ fn format_paths(
|
||||||
let futures: FuturesUnordered<RemoteHandle<FormattedPath>> = paths
|
let futures: FuturesUnordered<RemoteHandle<FormattedPath>> = paths
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|path| {
|
.map(|path| {
|
||||||
let config = config.clone();
|
|
||||||
|
|
||||||
pool.spawn_with_handle(async move {
|
pool.spawn_with_handle(async move {
|
||||||
let status =
|
let status =
|
||||||
alejandra::format::in_fs(path.clone(), config, in_place);
|
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);
|
std::process::exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
let config_file = serde_json::from_str::<ConfigOptions>(&contents)
|
serde_json::from_str::<Config>(&contents).unwrap_or_else(|error| {
|
||||||
.unwrap_or_else(|error| {
|
if verbosity.allows_errors() {
|
||||||
if verbosity.allows_errors() {
|
eprintln!("Errors found in config: {}", error);
|
||||||
eprintln!("Errors found in config: {}", error);
|
}
|
||||||
}
|
std::process::exit(1);
|
||||||
std::process::exit(1);
|
})
|
||||||
});
|
|
||||||
|
|
||||||
config_file.into()
|
|
||||||
} else {
|
} else {
|
||||||
Config::default()
|
Config::default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
mod ads;
|
mod ads;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
mod config_options;
|
|
||||||
mod find;
|
mod find;
|
||||||
mod verbosity;
|
mod verbosity;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue