Use Settings where AllSettings isn't required (#7518)

This commit is contained in:
Micha Reiser 2023-09-19 23:16:20 +02:00 committed by GitHub
parent 511cc25fc4
commit 297ec2c2d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 46 deletions

View file

@ -349,7 +349,7 @@ mod tests {
use std::time::SystemTime;
use itertools::Itertools;
use ruff::settings::{flags, AllSettings};
use ruff::settings::{flags, AllSettings, Settings};
use ruff_cache::CACHE_DIR_NAME;
use crate::cache::RelativePathBuf;
@ -371,10 +371,10 @@ mod tests {
let _ = fs::remove_dir_all(&cache_dir);
cache::init(&cache_dir).unwrap();
let settings = AllSettings::default();
let settings = Settings::default();
let package_root = fs::canonicalize(package_root).unwrap();
let cache = Cache::open(&cache_dir, package_root.clone(), &settings.lib);
let cache = Cache::open(&cache_dir, package_root.clone(), &settings);
assert_eq!(cache.new_files.lock().unwrap().len(), 0);
let mut paths = Vec::new();
@ -426,7 +426,7 @@ mod tests {
cache.store().unwrap();
let cache = Cache::open(&cache_dir, package_root.clone(), &settings.lib);
let cache = Cache::open(&cache_dir, package_root.clone(), &settings);
assert_ne!(cache.package.files.len(), 0);
parse_errors.sort();
@ -710,7 +710,7 @@ mod tests {
lint_path(
&self.package_root.join(path),
Some(&self.package_root),
&self.settings,
&self.settings.lib,
Some(cache),
flags::Noqa::Enabled,
flags::FixMode::Generate,

View file

@ -15,7 +15,7 @@ use rustc_hash::FxHashMap;
use ruff::message::Message;
use ruff::registry::Rule;
use ruff::settings::{flags, AllSettings};
use ruff::settings::{flags, Settings};
use ruff::{fs, warn_user_once, IOError};
use ruff_diagnostics::Diagnostic;
use ruff_python_ast::imports::ImportMap;
@ -111,7 +111,7 @@ pub(crate) fn check(
.and_then(|parent| package_roots.get(parent))
.and_then(|package| *package);
let settings = resolver.resolve_all(path, pyproject_config);
let settings = resolver.resolve(path, pyproject_config);
let cache_root = package.unwrap_or_else(|| path.parent().unwrap_or(path));
let cache = caches.as_ref().and_then(|caches| {
@ -199,7 +199,7 @@ pub(crate) fn check(
fn lint_path(
path: &Path,
package: Option<&Path>,
settings: &AllSettings,
settings: &Settings,
cache: Option<&Cache>,
noqa: flags::Noqa,
autofix: flags::FixMode,

View file

@ -21,7 +21,7 @@ use ruff::logging::DisplayParseError;
use ruff::message::Message;
use ruff::pyproject_toml::lint_pyproject_toml;
use ruff::registry::AsRule;
use ruff::settings::{flags, AllSettings, Settings};
use ruff::settings::{flags, Settings};
use ruff::source_kind::SourceKind;
use ruff::{fs, IOError, SyntaxError};
use ruff_diagnostics::Diagnostic;
@ -143,7 +143,7 @@ impl AddAssign for Diagnostics {
pub(crate) fn lint_path(
path: &Path,
package: Option<&Path>,
settings: &AllSettings,
settings: &Settings,
cache: Option<&Cache>,
noqa: flags::Noqa,
autofix: flags::FixMode,
@ -178,7 +178,6 @@ pub(crate) fn lint_path(
let source_type = match SourceType::from(path) {
SourceType::Toml(TomlSourceType::Pyproject) => {
let messages = if settings
.lib
.rules
.iter_enabled()
.any(|rule_code| rule_code.lint_source().is_pyproject_toml())
@ -187,15 +186,11 @@ pub(crate) fn lint_path(
match std::fs::read_to_string(path).map_err(SourceExtractionError::Io) {
Ok(contents) => contents,
Err(err) => {
return Ok(Diagnostics::from_source_error(
&err,
Some(path),
&settings.lib,
));
return Ok(Diagnostics::from_source_error(&err, Some(path), settings));
}
};
let source_file = SourceFileBuilder::new(path.to_string_lossy(), contents).finish();
lint_pyproject_toml(source_file, &settings.lib)
lint_pyproject_toml(source_file, settings)
} else {
vec![]
};
@ -213,11 +208,7 @@ pub(crate) fn lint_path(
Ok(Some(sources)) => sources,
Ok(None) => return Ok(Diagnostics::default()),
Err(err) => {
return Ok(Diagnostics::from_source_error(
&err,
Some(path),
&settings.lib,
));
return Ok(Diagnostics::from_source_error(&err, Some(path), settings));
}
};
@ -233,14 +224,8 @@ pub(crate) fn lint_path(
result,
transformed,
fixed,
}) = lint_fix(
path,
package,
noqa,
&settings.lib,
&source_kind,
source_type,
) {
}) = lint_fix(path, package, noqa, settings, &source_kind, source_type)
{
if !fixed.is_empty() {
match autofix {
flags::FixMode::Apply => match transformed.as_ref() {
@ -317,26 +302,12 @@ pub(crate) fn lint_path(
(result, fixed)
} else {
// If we fail to autofix, lint the original source code.
let result = lint_only(
path,
package,
&settings.lib,
noqa,
&source_kind,
source_type,
);
let result = lint_only(path, package, settings, noqa, &source_kind, source_type);
let fixed = FxHashMap::default();
(result, fixed)
}
} else {
let result = lint_only(
path,
package,
&settings.lib,
noqa,
&source_kind,
source_type,
);
let result = lint_only(path, package, settings, noqa, &source_kind, source_type);
let fixed = FxHashMap::default();
(result, fixed)
};