mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Enable excludes (#18)
This commit is contained in:
parent
7359e862c1
commit
b11a7eefa3
10 changed files with 140 additions and 83 deletions
|
@ -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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue