Skip to content

Update ruff check and ruff format to default to the current directory - #8791

Merged
zanieb merged 14 commits into
mainfrom
zanie/default
Nov 21, 2023
Merged

zanieb merged 14 commits into
mainfrom
zanie/default

Conversation

@zanieb

@zanieb zanieb commented Nov 20, 2023 •

Copy link
Copy Markdown
Member

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 of Ruff or ty label Nov 20, 2023
@zanieb

zanieb commented Nov 20, 2023

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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 thread docs/configuration.md
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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"]

@github-actions

github-actions Bot commented Nov 20, 2023 •

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@konstin konstin left a comment

Copy link
Copy Markdown
Member

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"] No newline at end of file

Copy link
Copy Markdown
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?

Comment thread 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("."))

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@zanieb zanieb Nov 21, 2023 •

Copy link
Copy Markdown
Member Author

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 thread docs/configuration.md
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
Copy Markdown
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?

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 of Ruff or ty

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: Invocation without arguments should check the current directory (🎁) Ability to specify default files in the config

3 participants