Unify Settings and AllSettings (#7532)

This commit is contained in:
Micha Reiser 2023-09-20 15:56:07 +02:00 committed by GitHub
parent ca3c15858d
commit b19eec9b2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 204 additions and 147 deletions

View file

@ -1,6 +1,7 @@
use once_cell::sync::Lazy;
use path_absolutize::path_dedot;
use regex::Regex;
use ruff_cache::cache_dir;
use rustc_hash::FxHashSet;
use std::collections::HashSet;
@ -17,7 +18,7 @@ use crate::rules::{
flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming,
pycodestyle, pydocstyle, pyflakes, pylint, pyupgrade,
};
use crate::settings::types::FilePatternSet;
use crate::settings::types::{FilePatternSet, SerializationFormat};
pub const PREFIXES: &[RuleSelector] = &[
RuleSelector::Prefix {
@ -72,7 +73,15 @@ pub static INCLUDE: Lazy<Vec<FilePattern>> = Lazy::new(|| {
impl Default for Settings {
fn default() -> Self {
let project_root = path_dedot::CWD.clone();
Self {
cache_dir: cache_dir(&project_root),
fix: false,
fix_only: false,
output_format: SerializationFormat::default(),
show_fixes: false,
show_source: false,
rules: PREFIXES
.iter()
.flat_map(|selector| selector.rules(PreviewMode::default()))
@ -92,7 +101,7 @@ impl Default for Settings {
namespace_packages: vec![],
preview: PreviewMode::default(),
per_file_ignores: vec![],
project_root: path_dedot::CWD.clone(),
project_root,
respect_gitignore: true,
src: vec![path_dedot::CWD.clone()],
tab_size: TabSize::default(),

View file

@ -31,27 +31,22 @@ pub mod flags;
pub mod rule_table;
pub mod types;
#[derive(Debug, Default)]
pub struct AllSettings {
pub cli: CliSettings,
pub lib: Settings,
}
#[derive(Debug, Default, Clone)]
#[allow(clippy::struct_excessive_bools)]
/// Settings that are not used by this library and only here so that `ruff_cli` can use them.
pub struct CliSettings {
pub cache_dir: PathBuf,
pub fix: bool,
pub fix_only: bool,
pub output_format: SerializationFormat,
pub show_fixes: bool,
pub show_source: bool,
}
#[derive(Debug, CacheKey)]
#[allow(clippy::struct_excessive_bools)]
pub struct Settings {
#[cache_key(ignore)]
pub cache_dir: PathBuf,
#[cache_key(ignore)]
pub fix: bool,
#[cache_key(ignore)]
pub fix_only: bool,
#[cache_key(ignore)]
pub output_format: SerializationFormat,
#[cache_key(ignore)]
pub show_fixes: bool,
#[cache_key(ignore)]
pub show_source: bool,
pub rules: RuleTable,
pub per_file_ignores: Vec<(GlobMatcher, GlobMatcher, RuleSet)>,