-
Notifications
You must be signed in to change notification settings - Fork 589
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
feat: check-in cargo dylint
with format_error
lint
#13750
Conversation
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
path = "ui/format_error.rs" | ||
|
||
[dependencies] | ||
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a585cda701581a16894858dc088eacd5a02fc78b" } # should match the toolchain version |
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.
Maybe we will need to add a script or checklist comments in rust-toolchain
for updating toolchain 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.
BTW, why does it need to match
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 internal API of rustc is not stable, which rust-clippy
depends on.
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.
Maybe we will need to add a script or checklist comments in
rust-toolchain
for updating toolchain now 🤣
It's okay. Mismatched version of clippy_utils
usually won't compile.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #13750 +/- ##
=======================================
Coverage 68.22% 68.22%
=======================================
Files 1523 1523
Lines 262075 262075
=======================================
Hits 178801 178801
Misses 83274 83274
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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 wanted to rubber stamp, but one thing makes me hesitant: clippy
is already very slow, and dylint
needs to rebuild the project once again. How to resolve this issue?
+1. Is it really worth it? |
Perhaps one lint is not worth it, but I can think of many rules, so I weakly support this. |
parallelize them? |
It's not a question of worth or not because I can't think of any other way to prevent the loss of error information. 😕 In theory, the slowness of If the running time is really a problem, I guess linting in main-cron or even manually is still good. |
Whether or not we should integrate |
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 concept looks really good to me. Previously we have some times when we wanted to add some custom lint rules but gave up. Such a dylint integration will make future custom linting easy. Thx!
|
||
impl EarlyLintPass for FormatArgsCollector { | ||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { | ||
if let ExprKind::FormatArgs(args) = &expr.kind { |
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.
Is format_args
a special macro which the compiler is aware of?
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 guess so, at the early pass.
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.
LGTM
@@ -0,0 +1,3 @@ | |||
[toolchain] | |||
channel = "nightly-2023-10-21" # should be identical to the root one |
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.
Is there anyway to sync this with root one automatically?
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 haven't found one. But as mentioned by @xxchan at #13750 (comment), there's more stuff to do when bumping the toolchain. Maybe we need a dedicated script or instruction for this.
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Whether or not we should integrate dylintto the development flow is a
topic in next PRs. In any case, checking in lints to our repository enable
collaboration on improving the quality of RisingWave's codebase
LGTM. Agree to check in and run daily and manually.
Btw, by slowness I did mean cargo check is slow, and dylint doesn’t share
build with clippy is worse.
…On Fri, 1 Dec 2023 at 16:46, Bugen Zhao ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In lints/src/utils/format_args_collector.rs
<#13750 (comment)>
:
> +use rustc_lint::{EarlyContext, EarlyLintPass};
+use rustc_session::impl_lint_pass;
+use rustc_span::{hygiene, Span};
+
+/// Collects [`rustc_ast::FormatArgs`] so that future late passes can call
+/// [`clippy_utils::macros::find_format_args`]
+#[derive(Default)]
+pub struct FormatArgsCollector {
+ format_args: FxHashMap<Span, Rc<FormatArgs>>,
+}
+
+impl_lint_pass!(FormatArgsCollector => []);
+
+impl EarlyLintPass for FormatArgsCollector {
+ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
+ if let ExprKind::FormatArgs(args) = &expr.kind {
I guess so, at the early pass.
—
Reply to this email directly, view it on GitHub
<#13750 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJBQZNIQDP5LT3VABJCEJXDYHGKPFAVCNFSM6AAAAABAA2IVDCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONJZGI4TENBYGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
If the running time is really a problem
I think it is, as I already run clippy locally very rarely now..
…On Fri, 1 Dec 2023 at 19:10, xxchan ***@***.***> wrote:
> Whether or not we should integrate dylintto the development flow is a
topic in next PRs. In any case, checking in lints to our repository
enable collaboration on improving the quality of RisingWave's codebase
LGTM. Agree to check in and run daily and manually.
Btw, by slowness I did mean cargo check is slow, and dylint doesn’t share
build with clippy is worse.
On Fri, 1 Dec 2023 at 16:46, Bugen Zhao ***@***.***> wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In lints/src/utils/format_args_collector.rs
> <#13750 (comment)>
> :
>
> > +use rustc_lint::{EarlyContext, EarlyLintPass};
> +use rustc_session::impl_lint_pass;
> +use rustc_span::{hygiene, Span};
> +
> +/// Collects [`rustc_ast::FormatArgs`] so that future late passes can call
> +/// [`clippy_utils::macros::find_format_args`]
> +#[derive(Default)]
> +pub struct FormatArgsCollector {
> + format_args: FxHashMap<Span, Rc<FormatArgs>>,
> +}
> +
> +impl_lint_pass!(FormatArgsCollector => []);
> +
> +impl EarlyLintPass for FormatArgsCollector {
> + fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
> + if let ExprKind::FormatArgs(args) = &expr.kind {
>
> I guess so, at the early pass.
>
> —
> Reply to this email directly, view it on GitHub
> <#13750 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AJBQZNIQDP5LT3VABJCEJXDYHGKPFAVCNFSM6AAAAABAA2IVDCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONJZGI4TENBYGA>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Check-in
cargo dylint
lints. Seelints/README.md
for more information.As described in #13725, it's not a good practice to directly format an error with
Display
orDebug
. However, it could be quite painful for developers to manually find and correct them.In this PR, we leverage
cargo dylint
to write a custom lint calledformat_error
and check the usages. The experience for both development and check is quite similar toclippy
, so it can be easily continuously integrated.To keep the PR clean, I haven't integrated it to CI or RiseDev now. Will do this in next PRs.
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.