-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
A-lintArea: New lintsArea: New lints
Description
What it does
This lint would warn users if any field in a struct is prefixed with an _ and marked pub, e.g.
struct DatabaseGuard {
pub _db_handle: Handle,
}
Prefixing a field name with an underscore is generally used to silence the unused field checker, so if you're suggesting the field shouldn't be used, then making it pub is most likely a mistake.
Note: this would be fairly similar to the used_underscore_binding lint
Lint Name
pub_underscore_field
Category
pedantic
Advantage
- Promotes better "visibility hygiene"
- Makes the concept of field access consistent across naming and visibility rules
Drawbacks
I don't think there are any. If someone has prefixed a field with an _ that shows intent to not use the field, and as such it doesn't/shouldn't need to be pub. I could be missing scenarios though :)
Example
struct DatabaseGuard {
pub _db_handle: Handle,
}Could be written as:
// if you do not intend to use the field `_db_handle`
struct DatabaseGuard {
_db_handle: Handle,
}
// ... or if you do intend to use the field
struct DatabaseGuard {
pub db_handle: Handle,
}Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints