mirror of https://github.com/astral-sh/ruff
refactor: Encapsulate PerFileIgnore impl details
This commit is contained in:
parent
028436af81
commit
4cc492a17a
|
|
@ -1,8 +1,7 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{command, Parser};
|
||||
use regex::Regex;
|
||||
use ruff::fs;
|
||||
use ruff::logging::LogLevel;
|
||||
use ruff::registry::{Rule, RuleSelector};
|
||||
use ruff::resolver::ConfigProcessor;
|
||||
|
|
@ -444,9 +443,6 @@ pub fn collect_per_file_ignores(pairs: Vec<PatternPrefixPair>) -> Vec<PerFileIgn
|
|||
}
|
||||
per_file_ignores
|
||||
.into_iter()
|
||||
.map(|(pattern, prefixes)| {
|
||||
let absolute = fs::normalize_path(Path::new(&pattern));
|
||||
PerFileIgnore::new(pattern, absolute, &prefixes)
|
||||
})
|
||||
.map(|(pattern, prefixes)| PerFileIgnore::new(pattern, &prefixes, None))
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,8 +149,7 @@ impl Configuration {
|
|||
per_file_ignores
|
||||
.into_iter()
|
||||
.map(|(pattern, prefixes)| {
|
||||
let absolute = fs::normalize_path_to(Path::new(&pattern), project_root);
|
||||
PerFileIgnore::new(pattern, absolute, &prefixes)
|
||||
PerFileIgnore::new(pattern, &prefixes, Some(project_root))
|
||||
})
|
||||
.collect()
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -87,16 +87,22 @@ impl FromStr for FilePattern {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PerFileIgnore {
|
||||
pub basename: String,
|
||||
pub absolute: PathBuf,
|
||||
pub codes: HashableHashSet<Rule>,
|
||||
pub(crate) basename: String,
|
||||
pub(crate) absolute: PathBuf,
|
||||
pub(crate) codes: HashableHashSet<Rule>,
|
||||
}
|
||||
|
||||
impl PerFileIgnore {
|
||||
pub fn new(basename: String, absolute: PathBuf, prefixes: &[RuleSelector]) -> Self {
|
||||
pub fn new(pattern: String, prefixes: &[RuleSelector], project_root: Option<&Path>) -> Self {
|
||||
let codes: FxHashSet<_> = prefixes.iter().flat_map(RuleSelector::codes).collect();
|
||||
let path = Path::new(&pattern);
|
||||
let absolute = match project_root {
|
||||
Some(project_root) => fs::normalize_path_to(path, project_root),
|
||||
None => fs::normalize_path(path),
|
||||
};
|
||||
|
||||
Self {
|
||||
basename,
|
||||
basename: pattern,
|
||||
absolute,
|
||||
codes: codes.into(),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue