Enable excludes (#18)

This commit is contained in:
Charlie Marsh 2022-08-20 13:00:58 -04:00 committed by GitHub
parent 7359e862c1
commit b11a7eefa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 140 additions and 83 deletions

View file

@ -1,25 +1,34 @@
use std::path::Path;
use std::path::{Path, PathBuf};
use anyhow::Result;
use crate::pyproject::{load_config, Config};
use crate::pyproject::load_config;
pub struct Settings {
pub line_length: usize,
pub exclude: Vec<PathBuf>,
}
static DEFAULT_MAX_LINE_LENGTH: usize = 88;
impl From<Config> for Settings {
fn from(config: Config) -> Settings {
Settings {
line_length: config.line_length.unwrap_or(DEFAULT_MAX_LINE_LENGTH),
}
}
}
impl Settings {
pub fn from_paths<'a>(paths: impl IntoIterator<Item = &'a Path>) -> Result<Self> {
load_config(paths).map(|config| config.into())
let (project_root, config) = load_config(paths)?;
Ok(Settings {
line_length: config.line_length.unwrap_or(DEFAULT_MAX_LINE_LENGTH),
exclude: config
.exclude
.unwrap_or_default()
.into_iter()
.map(|path| {
if path.is_relative() {
project_root.join(path)
} else {
path
}
})
.collect(),
})
}
}