mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Always check directly-passed-in files (#1564)
This commit is contained in:
parent
c4014ef2d3
commit
21986e89fd
4 changed files with 43 additions and 38 deletions
|
@ -64,11 +64,11 @@ Found 9 error(s).
|
||||||
9 potentially fixable with the --fix option.
|
9 potentially fixable with the --fix option.
|
||||||
```
|
```
|
||||||
|
|
||||||
Running from a parent directory should this "ignore" the `exclude` (hence, `concepts/file.py` gets
|
Running from a parent directory should "ignore" the `exclude` (hence, `concepts/file.py` gets
|
||||||
included in the output):
|
included in the output):
|
||||||
|
|
||||||
```
|
```
|
||||||
∴ (cd resources/test/project/examples && cargo run -- --config=docs/pyproject.toml .)
|
∴ (cd resources/test/project/examples && cargo run -- --config=docs/ruff.toml .)
|
||||||
docs/docs/concepts/file.py:5:5: F841 Local variable `x` is assigned to but never used
|
docs/docs/concepts/file.py:5:5: F841 Local variable `x` is assigned to but never used
|
||||||
docs/docs/file.py:1:1: I001 Import block is un-sorted or un-formatted
|
docs/docs/file.py:1:1: I001 Import block is un-sorted or un-formatted
|
||||||
docs/docs/file.py:8:5: F841 Local variable `x` is assigned to but never used
|
docs/docs/file.py:8:5: F841 Local variable `x` is assigned to but never used
|
||||||
|
@ -90,5 +90,7 @@ Unless we `--force-exclude`:
|
||||||
|
|
||||||
```
|
```
|
||||||
∴ cargo run resources/test/project/examples/excluded/ --force-exclude
|
∴ cargo run resources/test/project/examples/excluded/ --force-exclude
|
||||||
|
warning: No Python files found under the given path(s)
|
||||||
∴ cargo run resources/test/project/examples/excluded/script.py --force-exclude
|
∴ cargo run resources/test/project/examples/excluded/script.py --force-exclude
|
||||||
|
warning: No Python files found under the given path(s)
|
||||||
```
|
```
|
||||||
|
|
|
@ -46,9 +46,10 @@ pub fn run(
|
||||||
|
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
one_time_warning!(
|
one_time_warning!(
|
||||||
"{}: {}",
|
"{}{} {}",
|
||||||
"warning".yellow().bold(),
|
"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());
|
return Ok(Diagnostics::default());
|
||||||
}
|
}
|
||||||
|
@ -196,9 +197,10 @@ pub fn add_noqa(
|
||||||
|
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
one_time_warning!(
|
one_time_warning!(
|
||||||
"{}: {}",
|
"{}{} {}",
|
||||||
"warning".yellow().bold(),
|
"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);
|
return Ok(0);
|
||||||
}
|
}
|
||||||
|
@ -270,9 +272,10 @@ pub fn show_files(
|
||||||
|
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
one_time_warning!(
|
one_time_warning!(
|
||||||
"{}: {}",
|
"{}{} {}",
|
||||||
"warning".yellow().bold(),
|
"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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ use clap::{CommandFactory, Parser};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use notify::{recommended_watcher, RecursiveMode, Watcher};
|
use notify::{recommended_watcher, RecursiveMode, Watcher};
|
||||||
use path_absolutize::path_dedot;
|
use path_absolutize::path_dedot;
|
||||||
|
use ruff::one_time_warning;
|
||||||
|
|
||||||
/// Resolve the relevant settings strategy and defaults for the current
|
/// Resolve the relevant settings strategy and defaults for the current
|
||||||
/// invocation.
|
/// invocation.
|
||||||
|
@ -177,24 +178,30 @@ pub(crate) fn inner_main() -> Result<ExitCode> {
|
||||||
if cache {
|
if cache {
|
||||||
// `--no-cache` doesn't respect code changes, and so is often confusing during
|
// `--no-cache` doesn't respect code changes, and so is often confusing during
|
||||||
// development.
|
// development.
|
||||||
eprintln!(
|
one_time_warning!(
|
||||||
"{}: debug build without --no-cache.",
|
"{}{} {}",
|
||||||
"warning".yellow().bold()
|
"warning".yellow().bold(),
|
||||||
|
":".bold(),
|
||||||
|
"debug build without --no-cache.".bold()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let printer = Printer::new(&format, &log_level, &autofix, &violations);
|
let printer = Printer::new(&format, &log_level, &autofix, &violations);
|
||||||
if cli.watch {
|
if cli.watch {
|
||||||
if !matches!(autofix, fixer::Mode::None) {
|
if !matches!(autofix, fixer::Mode::None) {
|
||||||
eprintln!(
|
one_time_warning!(
|
||||||
"{}: --fix is not enabled in watch mode.",
|
"{}{} {}",
|
||||||
"warning".yellow().bold()
|
"warning".yellow().bold(),
|
||||||
|
":".bold(),
|
||||||
|
"--fix is not enabled in watch mode.".bold()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if format != SerializationFormat::Text {
|
if format != SerializationFormat::Text {
|
||||||
eprintln!(
|
one_time_warning!(
|
||||||
"{}: --format 'text' is used in watch mode.",
|
"{}{} {}",
|
||||||
"warning".yellow().bold()
|
"warning".yellow().bold(),
|
||||||
|
":".bold(),
|
||||||
|
"--format 'text' is used in watch mode.".bold()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,19 +215,7 @@ pub fn python_files_in_path(
|
||||||
overrides: &Overrides,
|
overrides: &Overrides,
|
||||||
) -> Result<(Vec<Result<DirEntry, ignore::Error>>, Resolver)> {
|
) -> Result<(Vec<Result<DirEntry, ignore::Error>>, Resolver)> {
|
||||||
// Normalize every path (e.g., convert from relative to absolute).
|
// Normalize every path (e.g., convert from relative to absolute).
|
||||||
let mut paths = paths
|
let mut paths: Vec<PathBuf> = paths.iter().map(fs::normalize_path).collect();
|
||||||
.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>>>()?;
|
|
||||||
|
|
||||||
// Search for `pyproject.toml` files in all parent directories.
|
// Search for `pyproject.toml` files in all parent directories.
|
||||||
let mut resolver = Resolver::default();
|
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);
|
files.lock().unwrap().push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +449,7 @@ mod tests {
|
||||||
assert!(match_exclusion(
|
assert!(match_exclusion(
|
||||||
file_path,
|
file_path,
|
||||||
file_basename,
|
file_basename,
|
||||||
&make_exclusion(exclude,)
|
&make_exclusion(exclude),
|
||||||
));
|
));
|
||||||
|
|
||||||
let path = Path::new("foo/bar").absolutize_from(project_root).unwrap();
|
let path = Path::new("foo/bar").absolutize_from(project_root).unwrap();
|
||||||
|
@ -471,7 +464,7 @@ mod tests {
|
||||||
assert!(match_exclusion(
|
assert!(match_exclusion(
|
||||||
file_path,
|
file_path,
|
||||||
file_basename,
|
file_basename,
|
||||||
&make_exclusion(exclude,)
|
&make_exclusion(exclude),
|
||||||
));
|
));
|
||||||
|
|
||||||
let path = Path::new("foo/bar/baz.py")
|
let path = Path::new("foo/bar/baz.py")
|
||||||
|
@ -488,7 +481,7 @@ mod tests {
|
||||||
assert!(match_exclusion(
|
assert!(match_exclusion(
|
||||||
file_path,
|
file_path,
|
||||||
file_basename,
|
file_basename,
|
||||||
&make_exclusion(exclude,)
|
&make_exclusion(exclude),
|
||||||
));
|
));
|
||||||
|
|
||||||
let path = Path::new("foo/bar").absolutize_from(project_root).unwrap();
|
let path = Path::new("foo/bar").absolutize_from(project_root).unwrap();
|
||||||
|
@ -503,7 +496,7 @@ mod tests {
|
||||||
assert!(match_exclusion(
|
assert!(match_exclusion(
|
||||||
file_path,
|
file_path,
|
||||||
file_basename,
|
file_basename,
|
||||||
&make_exclusion(exclude,)
|
&make_exclusion(exclude),
|
||||||
));
|
));
|
||||||
|
|
||||||
let path = Path::new("foo/bar/baz.py")
|
let path = Path::new("foo/bar/baz.py")
|
||||||
|
@ -520,7 +513,7 @@ mod tests {
|
||||||
assert!(match_exclusion(
|
assert!(match_exclusion(
|
||||||
file_path,
|
file_path,
|
||||||
file_basename,
|
file_basename,
|
||||||
&make_exclusion(exclude,)
|
&make_exclusion(exclude),
|
||||||
));
|
));
|
||||||
|
|
||||||
let path = Path::new("foo/bar/baz.py")
|
let path = Path::new("foo/bar/baz.py")
|
||||||
|
@ -537,7 +530,7 @@ mod tests {
|
||||||
assert!(match_exclusion(
|
assert!(match_exclusion(
|
||||||
file_path,
|
file_path,
|
||||||
file_basename,
|
file_basename,
|
||||||
&make_exclusion(exclude,)
|
&make_exclusion(exclude),
|
||||||
));
|
));
|
||||||
|
|
||||||
let path = Path::new("foo/bar/baz.py")
|
let path = Path::new("foo/bar/baz.py")
|
||||||
|
@ -554,7 +547,7 @@ mod tests {
|
||||||
assert!(!match_exclusion(
|
assert!(!match_exclusion(
|
||||||
file_path,
|
file_path,
|
||||||
file_basename,
|
file_basename,
|
||||||
&make_exclusion(exclude,)
|
&make_exclusion(exclude),
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue