Use absolute paths for --stdin-filename matching (#1843)

Non-basename glob matches (e.g., for `--per-file-ignores`) assume that
the path has been converted to an absolute path. (We do this for
filenames as part of the directory traversal.) For filenames passed via
stdin, though, we're missing this conversion. So `--per-file-ignores`
that rely on the _basename_ worked as expected, but directory paths did
not.

Closes #1840.
This commit is contained in:
Charlie Marsh
2023-01-12 21:01:05 -05:00
committed by GitHub
parent b47e8e6770
commit 048e5774e8
2 changed files with 21 additions and 17 deletions

View File

@@ -14,7 +14,7 @@ use ::ruff::settings::types::SerializationFormat;
use ::ruff::settings::{pyproject, Settings};
#[cfg(feature = "update-informer")]
use ::ruff::updates;
use ::ruff::{commands, fix, warn_user_once};
use ::ruff::{commands, fix, fs, warn_user_once};
use anyhow::Result;
use clap::{CommandFactory, Parser};
use colored::Colorize;
@@ -244,7 +244,7 @@ pub(crate) fn inner_main() -> Result<ExitCode> {
// Generate lint violations.
let diagnostics = if is_stdin {
commands::run_stdin(
cli.stdin_filename.as_deref(),
cli.stdin_filename.map(fs::normalize_path).as_deref(),
&pyproject_strategy,
&file_strategy,
&overrides,