Skip to content
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

Merged
merged 14 commits into from
Nov 21, 2023

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Nov 20, 2023

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.

@zanieb zanieb added the cli Related to the command-line interface label Nov 20, 2023
@zanieb
Copy link
Member Author

zanieb commented Nov 20, 2023

I'm looking into the behavior this exhibits with include per #3970 — it looks like more changes will be needed to properly support the desired behavior there.

Comment on lines 600 to 601
----- stderr -----
warning: Ignoring file . in favor of standard input.
Copy link
Member Author

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:

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;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:/ bde7712

@zanieb zanieb marked this pull request as ready for review November 20, 2023 17:22
Comment on lines +339 to +341
!!! warning
Paths provided to `include` _must_ match files. For example, `include = ["src"]` will fail since it
matches a directory.
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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"]

Copy link
Contributor

github-actions bot commented Nov 20, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@@ -0,0 +1,2 @@
[tool.ruff]
include = ["a.py", "subdirectory/c.py"]
Copy link
Member

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?

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("."))
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@zanieb zanieb Nov 21, 2023

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

Comment on lines +339 to +341
!!! warning
Paths provided to `include` _must_ match files. For example, `include = ["src"]` will fail since it
matches a directory.
Copy link
Member

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?

@zanieb zanieb merged commit d9151b1 into main Nov 21, 2023
17 checks passed
@zanieb zanieb deleted the zanie/default branch November 21, 2023 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command-line interface
Projects
None yet
3 participants