mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 05:20:49 -05:00
Always check directly-passed-in files (#1564)
This commit is contained in:
@@ -46,9 +46,10 @@ pub fn run(
|
||||
|
||||
if paths.is_empty() {
|
||||
one_time_warning!(
|
||||
"{}: {}",
|
||||
"{}{} {}",
|
||||
"warning".yellow().bold(),
|
||||
"No Python files found under the given path(s)"
|
||||
":".bold(),
|
||||
"No Python files found under the given path(s)".bold()
|
||||
);
|
||||
return Ok(Diagnostics::default());
|
||||
}
|
||||
@@ -196,9 +197,10 @@ pub fn add_noqa(
|
||||
|
||||
if paths.is_empty() {
|
||||
one_time_warning!(
|
||||
"{}: {}",
|
||||
"{}{} {}",
|
||||
"warning".yellow().bold(),
|
||||
"No Python files found under the given path(s)"
|
||||
":".bold(),
|
||||
"No Python files found under the given path(s)".bold()
|
||||
);
|
||||
return Ok(0);
|
||||
}
|
||||
@@ -270,9 +272,10 @@ pub fn show_files(
|
||||
|
||||
if paths.is_empty() {
|
||||
one_time_warning!(
|
||||
"{}: {}",
|
||||
"{}{} {}",
|
||||
"warning".yellow().bold(),
|
||||
"No Python files found under the given path(s)"
|
||||
":".bold(),
|
||||
"No Python files found under the given path(s)".bold()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ use clap::{CommandFactory, Parser};
|
||||
use colored::Colorize;
|
||||
use notify::{recommended_watcher, RecursiveMode, Watcher};
|
||||
use path_absolutize::path_dedot;
|
||||
use ruff::one_time_warning;
|
||||
|
||||
/// Resolve the relevant settings strategy and defaults for the current
|
||||
/// invocation.
|
||||
@@ -177,24 +178,30 @@ pub(crate) fn inner_main() -> Result<ExitCode> {
|
||||
if cache {
|
||||
// `--no-cache` doesn't respect code changes, and so is often confusing during
|
||||
// development.
|
||||
eprintln!(
|
||||
"{}: debug build without --no-cache.",
|
||||
"warning".yellow().bold()
|
||||
one_time_warning!(
|
||||
"{}{} {}",
|
||||
"warning".yellow().bold(),
|
||||
":".bold(),
|
||||
"debug build without --no-cache.".bold()
|
||||
);
|
||||
}
|
||||
|
||||
let printer = Printer::new(&format, &log_level, &autofix, &violations);
|
||||
if cli.watch {
|
||||
if !matches!(autofix, fixer::Mode::None) {
|
||||
eprintln!(
|
||||
"{}: --fix is not enabled in watch mode.",
|
||||
"warning".yellow().bold()
|
||||
one_time_warning!(
|
||||
"{}{} {}",
|
||||
"warning".yellow().bold(),
|
||||
":".bold(),
|
||||
"--fix is not enabled in watch mode.".bold()
|
||||
);
|
||||
}
|
||||
if format != SerializationFormat::Text {
|
||||
eprintln!(
|
||||
"{}: --format 'text' is used in watch mode.",
|
||||
"warning".yellow().bold()
|
||||
one_time_warning!(
|
||||
"{}{} {}",
|
||||
"warning".yellow().bold(),
|
||||
":".bold(),
|
||||
"--format 'text' is used in watch mode.".bold()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -215,19 +215,7 @@ pub fn python_files_in_path(
|
||||
overrides: &Overrides,
|
||||
) -> Result<(Vec<Result<DirEntry, ignore::Error>>, Resolver)> {
|
||||
// Normalize every path (e.g., convert from relative to absolute).
|
||||
let mut paths = paths
|
||||
.iter()
|
||||
.map(|path| {
|
||||
if path.is_file() && !is_python_path(path) {
|
||||
Err(anyhow::anyhow!(
|
||||
"`{}` is not supported; Ruff only supports `.py` and `.pyi` files",
|
||||
path.to_str().unwrap()
|
||||
))
|
||||
} else {
|
||||
Ok(fs::normalize_path(path))
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<PathBuf>>>()?;
|
||||
let mut paths: Vec<PathBuf> = paths.iter().map(fs::normalize_path).collect();
|
||||
|
||||
// Search for `pyproject.toml` files in all parent directories.
|
||||
let mut resolver = Resolver::default();
|
||||
@@ -331,7 +319,12 @@ pub fn python_files_in_path(
|
||||
}
|
||||
}
|
||||
|
||||
if result.as_ref().map_or(true, is_python_entry) {
|
||||
if result.as_ref().map_or(true, |entry| {
|
||||
// Accept all files that are passed-in directly.
|
||||
(entry.depth() == 0 && entry.file_type().map_or(false, |ft| ft.is_file()))
|
||||
// Accept all Python files.
|
||||
|| is_python_entry(entry)
|
||||
}) {
|
||||
files.lock().unwrap().push(result);
|
||||
}
|
||||
|
||||
@@ -456,7 +449,7 @@ mod tests {
|
||||
assert!(match_exclusion(
|
||||
file_path,
|
||||
file_basename,
|
||||
&make_exclusion(exclude,)
|
||||
&make_exclusion(exclude),
|
||||
));
|
||||
|
||||
let path = Path::new("foo/bar").absolutize_from(project_root).unwrap();
|
||||
@@ -471,7 +464,7 @@ mod tests {
|
||||
assert!(match_exclusion(
|
||||
file_path,
|
||||
file_basename,
|
||||
&make_exclusion(exclude,)
|
||||
&make_exclusion(exclude),
|
||||
));
|
||||
|
||||
let path = Path::new("foo/bar/baz.py")
|
||||
@@ -488,7 +481,7 @@ mod tests {
|
||||
assert!(match_exclusion(
|
||||
file_path,
|
||||
file_basename,
|
||||
&make_exclusion(exclude,)
|
||||
&make_exclusion(exclude),
|
||||
));
|
||||
|
||||
let path = Path::new("foo/bar").absolutize_from(project_root).unwrap();
|
||||
@@ -503,7 +496,7 @@ mod tests {
|
||||
assert!(match_exclusion(
|
||||
file_path,
|
||||
file_basename,
|
||||
&make_exclusion(exclude,)
|
||||
&make_exclusion(exclude),
|
||||
));
|
||||
|
||||
let path = Path::new("foo/bar/baz.py")
|
||||
@@ -520,7 +513,7 @@ mod tests {
|
||||
assert!(match_exclusion(
|
||||
file_path,
|
||||
file_basename,
|
||||
&make_exclusion(exclude,)
|
||||
&make_exclusion(exclude),
|
||||
));
|
||||
|
||||
let path = Path::new("foo/bar/baz.py")
|
||||
@@ -537,7 +530,7 @@ mod tests {
|
||||
assert!(match_exclusion(
|
||||
file_path,
|
||||
file_basename,
|
||||
&make_exclusion(exclude,)
|
||||
&make_exclusion(exclude),
|
||||
));
|
||||
|
||||
let path = Path::new("foo/bar/baz.py")
|
||||
@@ -554,7 +547,7 @@ mod tests {
|
||||
assert!(!match_exclusion(
|
||||
file_path,
|
||||
file_basename,
|
||||
&make_exclusion(exclude,)
|
||||
&make_exclusion(exclude),
|
||||
));
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user