mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Use Settings
where AllSettings
isn't required (#7518)
This commit is contained in:
parent
511cc25fc4
commit
297ec2c2d2
3 changed files with 17 additions and 46 deletions
|
@ -349,7 +349,7 @@ mod tests {
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use ruff::settings::{flags, AllSettings};
|
use ruff::settings::{flags, AllSettings, Settings};
|
||||||
use ruff_cache::CACHE_DIR_NAME;
|
use ruff_cache::CACHE_DIR_NAME;
|
||||||
|
|
||||||
use crate::cache::RelativePathBuf;
|
use crate::cache::RelativePathBuf;
|
||||||
|
@ -371,10 +371,10 @@ mod tests {
|
||||||
let _ = fs::remove_dir_all(&cache_dir);
|
let _ = fs::remove_dir_all(&cache_dir);
|
||||||
cache::init(&cache_dir).unwrap();
|
cache::init(&cache_dir).unwrap();
|
||||||
|
|
||||||
let settings = AllSettings::default();
|
let settings = Settings::default();
|
||||||
|
|
||||||
let package_root = fs::canonicalize(package_root).unwrap();
|
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);
|
assert_eq!(cache.new_files.lock().unwrap().len(), 0);
|
||||||
|
|
||||||
let mut paths = Vec::new();
|
let mut paths = Vec::new();
|
||||||
|
@ -426,7 +426,7 @@ mod tests {
|
||||||
|
|
||||||
cache.store().unwrap();
|
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);
|
assert_ne!(cache.package.files.len(), 0);
|
||||||
|
|
||||||
parse_errors.sort();
|
parse_errors.sort();
|
||||||
|
@ -710,7 +710,7 @@ mod tests {
|
||||||
lint_path(
|
lint_path(
|
||||||
&self.package_root.join(path),
|
&self.package_root.join(path),
|
||||||
Some(&self.package_root),
|
Some(&self.package_root),
|
||||||
&self.settings,
|
&self.settings.lib,
|
||||||
Some(cache),
|
Some(cache),
|
||||||
flags::Noqa::Enabled,
|
flags::Noqa::Enabled,
|
||||||
flags::FixMode::Generate,
|
flags::FixMode::Generate,
|
||||||
|
|
|
@ -15,7 +15,7 @@ use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use ruff::message::Message;
|
use ruff::message::Message;
|
||||||
use ruff::registry::Rule;
|
use ruff::registry::Rule;
|
||||||
use ruff::settings::{flags, AllSettings};
|
use ruff::settings::{flags, Settings};
|
||||||
use ruff::{fs, warn_user_once, IOError};
|
use ruff::{fs, warn_user_once, IOError};
|
||||||
use ruff_diagnostics::Diagnostic;
|
use ruff_diagnostics::Diagnostic;
|
||||||
use ruff_python_ast::imports::ImportMap;
|
use ruff_python_ast::imports::ImportMap;
|
||||||
|
@ -111,7 +111,7 @@ pub(crate) fn check(
|
||||||
.and_then(|parent| package_roots.get(parent))
|
.and_then(|parent| package_roots.get(parent))
|
||||||
.and_then(|package| *package);
|
.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_root = package.unwrap_or_else(|| path.parent().unwrap_or(path));
|
||||||
let cache = caches.as_ref().and_then(|caches| {
|
let cache = caches.as_ref().and_then(|caches| {
|
||||||
|
@ -199,7 +199,7 @@ pub(crate) fn check(
|
||||||
fn lint_path(
|
fn lint_path(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
package: Option<&Path>,
|
package: Option<&Path>,
|
||||||
settings: &AllSettings,
|
settings: &Settings,
|
||||||
cache: Option<&Cache>,
|
cache: Option<&Cache>,
|
||||||
noqa: flags::Noqa,
|
noqa: flags::Noqa,
|
||||||
autofix: flags::FixMode,
|
autofix: flags::FixMode,
|
||||||
|
|
|
@ -21,7 +21,7 @@ use ruff::logging::DisplayParseError;
|
||||||
use ruff::message::Message;
|
use ruff::message::Message;
|
||||||
use ruff::pyproject_toml::lint_pyproject_toml;
|
use ruff::pyproject_toml::lint_pyproject_toml;
|
||||||
use ruff::registry::AsRule;
|
use ruff::registry::AsRule;
|
||||||
use ruff::settings::{flags, AllSettings, Settings};
|
use ruff::settings::{flags, Settings};
|
||||||
use ruff::source_kind::SourceKind;
|
use ruff::source_kind::SourceKind;
|
||||||
use ruff::{fs, IOError, SyntaxError};
|
use ruff::{fs, IOError, SyntaxError};
|
||||||
use ruff_diagnostics::Diagnostic;
|
use ruff_diagnostics::Diagnostic;
|
||||||
|
@ -143,7 +143,7 @@ impl AddAssign for Diagnostics {
|
||||||
pub(crate) fn lint_path(
|
pub(crate) fn lint_path(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
package: Option<&Path>,
|
package: Option<&Path>,
|
||||||
settings: &AllSettings,
|
settings: &Settings,
|
||||||
cache: Option<&Cache>,
|
cache: Option<&Cache>,
|
||||||
noqa: flags::Noqa,
|
noqa: flags::Noqa,
|
||||||
autofix: flags::FixMode,
|
autofix: flags::FixMode,
|
||||||
|
@ -178,7 +178,6 @@ pub(crate) fn lint_path(
|
||||||
let source_type = match SourceType::from(path) {
|
let source_type = match SourceType::from(path) {
|
||||||
SourceType::Toml(TomlSourceType::Pyproject) => {
|
SourceType::Toml(TomlSourceType::Pyproject) => {
|
||||||
let messages = if settings
|
let messages = if settings
|
||||||
.lib
|
|
||||||
.rules
|
.rules
|
||||||
.iter_enabled()
|
.iter_enabled()
|
||||||
.any(|rule_code| rule_code.lint_source().is_pyproject_toml())
|
.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) {
|
match std::fs::read_to_string(path).map_err(SourceExtractionError::Io) {
|
||||||
Ok(contents) => contents,
|
Ok(contents) => contents,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Ok(Diagnostics::from_source_error(
|
return Ok(Diagnostics::from_source_error(&err, Some(path), settings));
|
||||||
&err,
|
|
||||||
Some(path),
|
|
||||||
&settings.lib,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let source_file = SourceFileBuilder::new(path.to_string_lossy(), contents).finish();
|
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 {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
|
@ -213,11 +208,7 @@ pub(crate) fn lint_path(
|
||||||
Ok(Some(sources)) => sources,
|
Ok(Some(sources)) => sources,
|
||||||
Ok(None) => return Ok(Diagnostics::default()),
|
Ok(None) => return Ok(Diagnostics::default()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Ok(Diagnostics::from_source_error(
|
return Ok(Diagnostics::from_source_error(&err, Some(path), settings));
|
||||||
&err,
|
|
||||||
Some(path),
|
|
||||||
&settings.lib,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -233,14 +224,8 @@ pub(crate) fn lint_path(
|
||||||
result,
|
result,
|
||||||
transformed,
|
transformed,
|
||||||
fixed,
|
fixed,
|
||||||
}) = lint_fix(
|
}) = lint_fix(path, package, noqa, settings, &source_kind, source_type)
|
||||||
path,
|
{
|
||||||
package,
|
|
||||||
noqa,
|
|
||||||
&settings.lib,
|
|
||||||
&source_kind,
|
|
||||||
source_type,
|
|
||||||
) {
|
|
||||||
if !fixed.is_empty() {
|
if !fixed.is_empty() {
|
||||||
match autofix {
|
match autofix {
|
||||||
flags::FixMode::Apply => match transformed.as_ref() {
|
flags::FixMode::Apply => match transformed.as_ref() {
|
||||||
|
@ -317,26 +302,12 @@ pub(crate) fn lint_path(
|
||||||
(result, fixed)
|
(result, fixed)
|
||||||
} else {
|
} else {
|
||||||
// If we fail to autofix, lint the original source code.
|
// If we fail to autofix, lint the original source code.
|
||||||
let result = lint_only(
|
let result = lint_only(path, package, settings, noqa, &source_kind, source_type);
|
||||||
path,
|
|
||||||
package,
|
|
||||||
&settings.lib,
|
|
||||||
noqa,
|
|
||||||
&source_kind,
|
|
||||||
source_type,
|
|
||||||
);
|
|
||||||
let fixed = FxHashMap::default();
|
let fixed = FxHashMap::default();
|
||||||
(result, fixed)
|
(result, fixed)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let result = lint_only(
|
let result = lint_only(path, package, settings, noqa, &source_kind, source_type);
|
||||||
path,
|
|
||||||
package,
|
|
||||||
&settings.lib,
|
|
||||||
noqa,
|
|
||||||
&source_kind,
|
|
||||||
source_type,
|
|
||||||
);
|
|
||||||
let fixed = FxHashMap::default();
|
let fixed = FxHashMap::default();
|
||||||
(result, fixed)
|
(result, fixed)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue