-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ruff check
and ruff format
to default to the current directory
#8791
Conversation
I'm looking into the behavior this exhibits with |
----- stderr ----- | ||
warning: Ignoring file . in favor of standard input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not enthused about this change. I'm unsure how best to fix it. I'm not sure I want to deal with changing the default for files
later so we can detect this case but it also feels kind of wrong to just avoid raising the warning if the file is .
.
Source:
ruff/crates/ruff_cli/src/lib.rs
Lines 87 to 95 in 7b4b004
if stdin_filename.is_some() { | |
if let Some(file) = files.iter().find(|file| file.as_path() != Path::new("-")) { | |
warn_user_once!( | |
"Ignoring file {} in favor of standard input.", | |
file.display() | |
); | |
} | |
return true; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:/ bde7712
!!! warning | ||
Paths provided to `include` _must_ match files. For example, `include = ["src"]` will fail since it | ||
matches a directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really feels like it should not be the case. We should join our default inclusions to directories. I'd prefer to tackle that separately though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be examples of use-cases in which one would want to include an entire directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in #3970 e.g. ruff check
with include = ["src", "tests"]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
db2e157
to
fab5932
Compare
@@ -0,0 +1,2 @@ | |||
[tool.ruff] | |||
include = ["a.py", "subdirectory/c.py"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: do you mind adding a newline here, so it isn't automatically added next time someone edits the file?
crates/ruff_cli/src/lib.rs
Outdated
if let Some(file) = files | ||
.iter() | ||
// We allow `.` in addition to `-` since it is the default file selector | ||
.find(|file| file.as_path() != Path::new("-") && file.as_path() != Path::new(".")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we now allow cat foo.py | ruff check --stdin-filename="foo.py" .
, without warning? That feels like a bug. I'm wondering if we should instead represent this default as the empty slice? I.e., at the relevant sites, if files
is empty, use the current working directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... I brought this up at #8791 (comment)
I don't like either solution honestly. .
as the Clap default is nice for the CLI help menu and such and it seems like a hassle to make sure the behavior is correct in the call sites. It does feel bad to omit the warning though so I guess I'll do the extra work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh sorry, I missed your comment! I defer to you as the author, I see there are tradeoffs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay kind of awkward but still fine e92000d
!!! warning | ||
Paths provided to `include` _must_ match files. For example, `include = ["src"]` will fail since it | ||
matches a directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be examples of use-cases in which one would want to include an entire directory?
e92000d
to
df58ad6
Compare
Closes #7347
Closes #3970 via use of
include
We could update examples in our documentation, but I worry since we do not have versioned documentation users on older versions would be confused. Instead, I'll open an issue to track updating use of
ruff check .
in the documentation sometime in the future.