-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
"Unify" fmt
and lint
rules for formatters
#14903
Conversation
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
Commits are useful in order |
if request.prior_formatter_result is None | ||
else request.prior_formatter_result |
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.
In a future change I think I'll refactor so this isn't needed. It's so confusing 😵
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.
Please!! I can't remember why this was necessary. But it's so copy pasta now.
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.
TL;DR Because these rules run for fmt
(in which case the formatter should run on the prior result) and lint
(in which case there is no "prior formatter result")
Also, it'd be a breaking user change so likely not worth it, but I wish the formatters were in a |
if isinstance(batch_results, FmtResult): | ||
return ( | ||
LintResult( | ||
1 if batch_results.did_change else 0, |
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.
It's a bummer we have to invent an error code here 😒
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
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.
Thanks a lot! This is a great cleanup.
As a follow-up we can issue a deprecation warning if our lint and fmt requests share a type (e.g. remove your lint code) |
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
Oh hey someone has already done that, indirectly 😂 |
How so? I don't think this is enough to block on, but is it solvable? |
Well this actually perpetuates that issue into It'll need to be addressed, but my approach would just be to give a fallback message about the formatter failing to format a file, which implies a file would fail lint anyways. E.g. |
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.
Amazing work. Not only really good code, but you did an excellent job with the proposal & google doc etc. So exciting 🎉
if request.prior_formatter_result is None | ||
else request.prior_formatter_result |
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.
Please!! I can't remember why this was necessary. But it's so copy pasta now.
Co-authored-by: Eric Arellano <[email protected]>
(proposal: https://docs.google.com/document/d/1KqrPP6VVi-Kq8EUqfo2IFffaHxdysCMPwrInoewM-LM/edit?usp=sharing)
This PR makes changes to
lint.py
to createFmtRequest
s for the purpose of linting, coercing theFmtResult
intoLintResult
.The core changes:
lint.py
now constructsFmtRequest
s in addition to the normal lint request types, and coerces theFmtResult
into aLintResult
FmtResult
'smessage
is now a simple tabbed list of files that changed. This will be used for bothfmt
andlint
.FmtResult
stdout
andstderr
are now debug logged. Unfortunately there's some out-of-order logging, but I think this is OK. Most users don't care.The formatter plugin changes:
check_only
which elides theSetupRequest
in each formatterargv
generationThis does not fix the issue pointed out in #14489 we can solve that later.
Beofre and after (using 4 cores)