Skip to content

Commit

Permalink
Use Settings where AllSettings isn't required (#7518)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Sep 19, 2023
1 parent 511cc25 commit 297ec2c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 46 deletions.
10 changes: 5 additions & 5 deletions crates/ruff_cli/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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,
Expand Down
47 changes: 9 additions & 38 deletions crates/ruff_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand All @@ -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![]
};
Expand All @@ -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));
}
};

Expand All @@ -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() {
Expand Down Expand Up @@ -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)
};
Expand Down

0 comments on commit 297ec2c

Please sign in to comment.