2

add `--explain` subcommand by llogiq · Pull Request #8952 · rust-lang/rust-clipp...

 1 year ago
source link: https://github.com/rust-lang/rust-clippy/pull/8952
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

add --explain subcommand #8952

Merged

bors merged 1 commit into

master

from

explain

6 days ago

Merged

Conversation

Contributor

@llogiq llogiq commented on Jun 5

This closes #8291.


changelog: add cargo clippy -- --explain <lintname> subcommand

All reactions

Collaborator

rust-highfive commented on Jun 5

r? @dswij

(rust-highfive has picked a reviewer for you, use r? to override)

rust-highfive

added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label

on Jun 5

Contributor

Author

llogiq commented on Jun 5

edited

I started out trying to get a proc macro to work, but then I found Alexey Kladow's blog post about self-modifying code and I thought this might be just the right application for the technique.

Member

xFrednet commented on Jun 5

This one looks interesting, and my reviewing queue is currently relatively small. I would take over the review. (If you want to keep it @dswij, feel free to say so)

r? @xFrednet

@llogiq could you maybe link the blog post? Your comment reminded me of a post, I've read before. Also, as a side node, I sometimes find it confusing, when to use the double dashes after cargo clippy and when not. Therefore, I think it would be cool, if the --explain comment would also be accepted by cargo-clippy and then passed to clippy-driver. But that can also be done in a followup PR upside_down_face

dswij reacted with thumbs up emoji All reactions

Contributor

Author

llogiq commented on Jun 5

Updated my previus comment with the link.

xFrednet reacted with heart emoji All reactions

Member

dswij commented on Jun 5

Sure, go ahead!

Contributor

Author

llogiq commented on Jun 5

@xFrednet I'm fine with merging this & doing a follow-up for cargo-clippy later.

xFrednet reacted with thumbs up emoji All reactions

Contributor

Author

llogiq commented on Jun 5

I noted that -E is already used for "error".

Member

@xFrednet xFrednet left a comment

The implementation itself looks good to be. I haven't done a full test, but the initial tries seem good.

While I like the concept of using a test, it feels a bit off in Clippy's codebase since we already do this kind of generation in clippy_dev. This introduces another location with little benefit in comparison to adding it to clippy_dev. At least that's my impression. clippy_dev doesn't have the regex crate, but that should be simple to avoid/rewrite.

cc: @Serial-ATA This might be interesting, since you're working on the metadata collection/lint list. Feel free to ignore this as well upside_down_face

All reactions

src/main.rs

Outdated Show resolved

tests/check-docs.rs

Outdated Show resolved

tests/check-docs.rs

Outdated Show resolved

Contributor

Serial-ATA commented on Jun 7

Couldn't docs.rs be generated during the metadata collection lint alongside lints.json? Just so you don't have to reinvent the wheel to get the docs.

Member

flip1995 commented on Jun 10

Couldn't docs.rs be generated during the metadata collection lint alongside lints.json?

collect-metadata is only run during deployment and not even in bors CI. However, collect-metadata could use this file to generate the documentation instead of doing it itself.

This would be a really cool thing to have -- especially if we can somehow add this feature to rust-analyzer. Thank you for your work!

Contributor

Author

llogiq commented 18 days ago

edited

So, I see two ways to improve on this:

  • I'll move the docs creation to cargo-dev so it's included with update_lints and re-use our current infrastructure.
  • I'll change the generation to emit a file per lint and a single file to include_str! all of those doc files. This way we won't get too many merge conflicts from docs.

Contributor

Author

llogiq commented 18 days ago

This version should deal with the merge conflicts arising from doc changes.

I didn't get to changing the code to use cargo dev update_lints yet. Using the metadata collector would not be optimal, because we don't run it in CI. On the other hand, extending update_lints to also parse the doc comments would duplicate some machinery. Oh well.

Contributor

Author

llogiq commented 18 days ago

Hmmm...I should not name the files ".md" when they don't contain markdown...

Contributor

Author

llogiq commented 17 days ago

edited

With the following force-push, I removed the final newline from the md files as well as # -ignored code lines.

@dswij r?

Member

xFrednet commented 16 days ago

Sorry, for the late replay, I moved last week and life is currently still a bit chaotic. Reviewing this is on my todo list for this weekend. If @dswij want's to take over that would also be fine for me upside_down_face

llogiq reacted with thumbs up emoji All reactions

Contributor

Author

llogiq commented 11 days ago

xFrednet reacted with thumbs up emoji All reactions

Member

@xFrednet xFrednet left a comment

Overall, looks good to me. I also like the location in cargo-clippy. I've also played around with it and to works well :). My GitHub is actually struggling a bit with this many changes ^^.

Thank you for your patience, the last weeks have been very full for me sweat_smile

All reactions

src/docs.rs

Outdated Show resolved

src/main.rs

Outdated Show resolved

src/main.rs

Show resolved

Member

xFrednet commented 11 days ago

Hey @rust-lang/clippy, this PR adds the --explain comment to cargo-clippy. For this, it stores the lint description in a text file inside src/docs/<lint_name>.txt. The documentation files are automatically checked and updated by cargo dev update_lints. This seems to work quite well and looks good to me. Does anyone have any concerns regarding this? upside_down_face

dswij, Jarcho, and SirCharlieMars reacted with hooray emojiManishearth, dswij, and SirCharlieMars reacted with heart emoji All reactions

xFrednet

added the S-needs-discussion Status: Needs further discussion before merging or work can be started label

11 days ago

Contributor

Author

llogiq commented 10 days ago

I need to rebase to make the tests work.

Contributor

Author

llogiq commented 10 days ago

We discussed wanting this three meetings ago, and I agreed to implement it. I don't think there were any objections during that meeting.

Re the implementation: Splitting the files and using include_str! to pull them together was done to reduce merge conflicts. Merging this will fail unless it's rebased on a sufficiently late version (i.e. no docs changes in between), so please ping me before r+ing it.

Member

xFrednet commented 7 days ago

We discussed wanting this three meetings ago, and I agreed to implement it. I don't think there were any objections during that meeting.

I just wanted to make sure now that we had an actual implementation to play around with. It looks like everyone is cool with this :)


This looks good to me, you can r=me after a rebase and lint update upside_down_face Thank you for the implementation, happy to finally have this in Clippy partying_facetada

xFrednet

added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

and removed S-needs-discussion Status: Needs further discussion before merging or work can be started S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

labels

7 days ago

Contributor

Author

llogiq commented 6 days ago

@bors r=xFredNet

Contributor

bors commented 6 days ago

pushpin Commit ad72aee has been approved by xFredNet

It is now in the queue for this repository.

Contributor

bors commented 6 days ago

hourglass Testing commit ad72aee with merge 30e4532...

bors

merged commit 30e4532 into

master

6 days ago

6 checks passed

llogiq

deleted the explain branch

6 days ago

Contributor

Author

llogiq commented 6 days ago

Thank you for the review, @xFrednet.

xFrednet reacted with heart emoji All reactions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Assignees

xFrednet

Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

8 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK