Skip to content
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

chore: enforce unreachable_pub lint #3735

Merged
merged 20 commits into from
Apr 26, 2023
Merged

chore: enforce unreachable_pub lint #3735

merged 20 commits into from
Apr 26, 2023

Conversation

thomaseizinger
Copy link
Contributor

@thomaseizinger thomaseizinger commented Apr 4, 2023

Description

The unreachable_pub lint makes us aware of uses of pub that are not actually reachable from the crate root. This is considered good because it means reading a pub somewhere means it is actually public API. Some of our crates are quite large and keeping their entire API surface in your head is difficult.

We should strive for most items being pub(crate). This lint helps us enforce that.

Notes & open questions

Draft because not yet complete. There is a lot of code to go through so I think we want some kind of automation to do this for us.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@mxinden
Copy link
Member

mxinden commented Apr 5, 2023

I am in favor of this.

@thomaseizinger
Copy link
Contributor Author

Another data point for this: #3741

@thomaseizinger thomaseizinger marked this pull request as ready for review April 17, 2023 08:32
@thomaseizinger
Copy link
Contributor Author

@mxinden: Here is the initial version of enforcing this lint. I've applied most of the fixes with a script. Some of the pub(crate) could potentially also be just private. I didn't bother going through it all because I am not convinced that it matters other than for aesthetic reasons.

What is a bit surprising but also great is that fact that we seemed to correctly export all structs and not miss anything that is actually unreachable.

@thomaseizinger
Copy link
Contributor Author

I am also adding the script I used to fix the warnings. I imagine once we remove some deprecations and / or add new modules, it might come in handy again.

Please don't judge me for my poor Python skills 🙈

@thomaseizinger thomaseizinger requested review from mxinden and removed request for mxinden April 25, 2023 13:53
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mergify mergify bot merged commit 135942d into master Apr 26, 2023
@mergify mergify bot deleted the fix/unreachable-pub branch April 26, 2023 07:31
umgefahren pushed a commit to umgefahren/rust-libp2p that referenced this pull request Mar 8, 2024
The `unreachable_pub` lint makes us aware of uses of `pub` that are not actually reachable from the crate root. This is considered good because it means reading a `pub` somewhere means it is actually public API. Some of our crates are quite large and keeping their entire API surface in your head is difficult.

We should strive for most items being `pub(crate)`. This lint helps us enforce that.

Pull-Request: libp2p#3735.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants