-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Move Pylint rendering to ruff_db
#19340
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
Conversation
|
Summary -- This is a very simple output format, the only decision is what to do if the file is missing from the diagnostic. For now, I opted to `unwrap_or_default` both the path and the `OneIndexed` row number, giving `:1: main diagnostic message` in the test without a file. Another quirk here is that the path is relativized. I just pasted in the `relativize_path` and `get_cwd` implementations from `ruff_linter::fs` for now, but maybe there's a better place for them. I didn't see any details about why this needs to be relativized in the original [issue](#1953), [PR](#1995), or in the pylint [docs](https://flake8.pycqa.org/en/latest/internal/formatters.html#pylint-formatter), but it did change the results of the CLI integration test when I tried deleting it. I haven't been able to reproduce that in the CLI, though, so it may only happen with `Command::current_dir`. Test Plan -- Tests ported from `ruff_linter` and a new test for the case with no file
|
crates/ruff_db/Cargo.toml
Outdated
| path-absolutize = { workspace = true, features = [ | ||
| "once_cell_cache", | ||
| "use_unix_paths_on_wasm", | ||
| ] } |
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.
The ruff_db crate shouldn't depend on any OS specific behavior except for code gated by the os feature. It otherwise makes compiling on other tagets (like you noticed with WASM) a fair bit more complicated.
For ty, making the path relative is implemented in FileResolver. Now, whether this is correct I'm not sure because it does mean that the paths are relative for all rendered output formats (including JSON where we might want to use absolute paths, although I'm not sure). But it is the right place to abstract away the integration logic between ty and Ruff.
ruff/crates/ruff_db/src/diagnostic/render.rs
Lines 714 to 716 in 988479d
| fn path(&self, file: File) -> &str { | |
| relativize_path(self.system().current_directory(), file.path(self).as_str()) | |
| } |
One solution is to change UnifiedFile::path to also return a relative path for Ruff files. A better solution is probably to add a current_directory method to FileResolver which returns system.current_directory for ty and whatever path-absolutize uses for ruff. You can then add a relative_path method to UnifiedFile which makes ::path relative to file_resolver.current_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.
I was playing with both the ty and ruff CLIs yesterday, and I think they have similar behavior here. As I mentioned in the description, the only place I saw a difference was in the integration tests where the [TMP]/ prefix appeared in the output even though it's supposed to be the current_dir. So I was thinking that this relativize call might be unnecessary in general.
But I'll add a method to the FileResolver just in case, that seems like a nice approach.
| let filename = filename.unwrap_or_default(); | ||
| let row = row.unwrap_or_default(); | ||
|
|
||
| writeln!(f, "{path}:{row}: {body}", path = relativize_path(filename))?; |
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.
Interesting, it seems that this matches pylint's VS code reporter and not the text reporter:
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 think it might be ParseableTextReporter actually: https://github.com/pylint-dev/pylint/blob/a14b2c4e68d3585c74fb7a3bbd5636e807a3ce77/pylint/reporters/text.py#L189
The VS Code one doesn't have a colon between path and row. This is the link in the renderer docstring that I copied over from ruff_linter: https://flake8.pycqa.org/en/latest/internal/formatters.html#pylint-formatter. I think it's supposed to be the Pylint output format from the flake8 tool.
Working on these definitely makes me curious if/how people are using the various output formats!
Co-authored-by: Micha Reiser <micha@reiser.io>
|
|
Oh yeah, I understand why we relativize the path in general, I just meant that I couldn't find any cases in the CLI where this relativize call made a difference. However, I found one immediately today, so I guess I wasn't testing the right thing yesterday. |
MichaReiser
left a comment
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.
Thank you
…finition * 'main' of https://github.com/astral-sh/ruff: (39 commits) [ty] Sync vendored typeshed stubs (astral-sh#19368) Fix typeshed-sync workflow (astral-sh#19367) Rework typeshed-sync workflow to also add docstrings for Windows- and MacOS-specific APIs (astral-sh#19360) [ty] Allow `-qq` for silent output mode (astral-sh#19366) [ty] Allow `-q` short alias for `--quiet` (astral-sh#19364) Add shellcheck to pre-commit (astral-sh#19361) distinguish references from definitions in `infer_nonlocal` [`pycodestyle`] Handle brace escapes for t-strings in logical lines (astral-sh#19358) [ty] Combine CallArguments and CallArgumentTypes (astral-sh#19337) Move Pylint rendering to `ruff_db` (astral-sh#19340) [`pylint`] Extend invalid string character rules to include t-strings (astral-sh#19355) Make TC010 docs example more realistic (astral-sh#19356) Move RDJSON rendering to `ruff_db` (astral-sh#19293) [`flake8-use-pathlib`] Skip single dots for `invalid-pathlib-with-suffix` (`PTH210`) on versions >= 3.14 (astral-sh#19331) [`ruff`] Allow `strict` kwarg when checking for `starmap-zip` (`RUF058`) in Python 3.14+ (astral-sh#19333) [ty] Reduce false positives for `TypedDict` types (astral-sh#19354) [ty] Remove `ConnectionInitializer` (astral-sh#19353) [ty] Use `Type::string_literal()` more (astral-sh#19352) [ty] Add ecosystem-report workflow (astral-sh#19349) [ty] Make use of salsa `Lookup` when interning values (astral-sh#19347) ... # Conflicts: # crates/ty_ide/src/goto.rs # crates/ty_server/src/server.rs
Summary
This is a very simple output format, the only decision is what to do if the file
is missing from the diagnostic. For now, I opted to
unwrap_or_defaultboth thepath and the
OneIndexedrow number, giving:1: main diagnostic messageinthe test without a file.
Another quirk here is that the path is relativized. I just pasted in the
relativize_pathandget_cwdimplementations fromruff_linter::fsfor now,but maybe there's a better place for them.
I didn't see any details about why this needs to be relativized in the original
issue,
PR, or in the pylint
docs,
but it did change the results of the CLI integration test when I tried deleting
it. I haven't been able to reproduce that in the CLI, though, so it may only
happen with
Command::current_dir.Test Plan
Tests ported from
ruff_linterand a new test for the case with no file