-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[move] Small lint cleanups #18878
[move] Small lint cleanups #18878
Conversation
@tnowacki is attempting to deploy a commit to the Mysten Labs Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
} | ||
fn is_freeze_function(fun: &T::ModuleCall) -> bool { | ||
FREEZE_FUNCTIONS.iter().any(|(addr, module, fname)| { | ||
fun.module.value.is(*addr, *module) && &fun.name.value().as_str() == fname |
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.
Would it be cheaper to convert the names into symbols to avoid the as_str()
check?
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, but a lot of these aren't static symbols already, so not sure it would be worth it 🤷
external-crates/move/crates/move-compiler/src/sui_mode/linters/freezing_capability.rs
Outdated
Show resolved
Hide resolved
} | ||
|
||
static REGEX: Lazy<Regex> = | ||
Lazy::new(|| Regex::new(r".*((Cap[A-Z0-9_]+)|Capability|(Cap$)).*").unwrap()); |
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.
Lazy::new(|| Regex::new(r".*((Cap[A-Z0-9_]+)|Capability|(Cap$)).*").unwrap()); | |
Lazy::new(|| Regex::new(r".*Cap(?:[A-Z0-9_]+|ability|$).*").unwrap()); |
Shorter but less clear Regex.
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.
Would it make sense to revise the regex as:
.*Cap(?:(?:v)[A-Z0-9_]+|ability|$).*
This would catch Capv0
, etc, as well.
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 don't think I want to catch Capv0
, since someone should write it as CapV0
. In short, I'm trying to find word boundaries
let msg = format!( | ||
"The type {} is potentially a capability based on its name. Freezing a capability might lock out critical operations or otherwise open access to operations that otherwise should be restricted.", | ||
core::error_format_(type_arg, &core::Subst::empty()), | ||
); | ||
let diag = diag!(FREEZE_CAPABILITY_DIAG, (loc, msg)); | ||
context.env.add_diag(diag); |
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.
More recently I have been trying to follow Rust and split up longer message like this into a location message and a note, e.g., :
let msg = format!( | |
"The type {} is potentially a capability based on its name. Freezing a capability might lock out critical operations or otherwise open access to operations that otherwise should be restricted.", | |
core::error_format_(type_arg, &core::Subst::empty()), | |
); | |
let diag = diag!(FREEZE_CAPABILITY_DIAG, (loc, msg)); | |
context.env.add_diag(diag); | |
let msg = format!( | |
"The type {} is potentially a capability based on its name", | |
core::error_format_(type_arg, &core::Subst::empty()), | |
); | |
let mut diag = diag!(FREEZE_CAPABILITY_DIAG, (loc, msg)); | |
diag.add_note("Freezing a capability might lock out critical operations or otherwise open access to operations that otherwise should be restricted"); | |
context.env.add_diag(diag); |
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. Keep in mind though the note might not be rendered in the IDE easily
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, with a few small things to consider as notes.
## Description - Small changes/rewording to lints - Improved capability freezing lint - Fixed VISIT_TYPES ## Test plan - Updated tests --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API:
## Description - Small changes/rewording to lints - Improved capability freezing lint - Fixed VISIT_TYPES ## Test plan - Updated tests --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API:
Description
Test plan
Release notes
Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.
For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.