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

[move] Small lint cleanups #18878

Merged
merged 5 commits into from
Aug 21, 2024
Merged

[move] Small lint cleanups #18878

merged 5 commits into from
Aug 21, 2024

Conversation

tnowacki
Copy link
Contributor

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:

@tnowacki tnowacki requested review from cgswords and a team July 31, 2024 23:11
Copy link

vercel bot commented Jul 31, 2024

@tnowacki is attempting to deploy a commit to the Mysten Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Jul 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2024 2:19am

}
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
Copy link
Contributor

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?

Copy link
Contributor Author

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 🤷

}

static REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r".*((Cap[A-Z0-9_]+)|Capability|(Cap$)).*").unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Comment on lines 105 to 110
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);
Copy link
Contributor

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., :

Suggested change
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);

Copy link
Contributor Author

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

Copy link
Contributor

@cgswords cgswords left a 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.

@tnowacki tnowacki enabled auto-merge (squash) August 2, 2024 02:17
@tnowacki tnowacki merged commit 9a24f66 into MystenLabs:main Aug 21, 2024
41 of 44 checks passed
@tnowacki tnowacki deleted the lint-cleanup branch August 21, 2024 22:20
tx-tomcat pushed a commit to tx-tomcat/sui-network that referenced this pull request Aug 27, 2024
## 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:
suiwombat pushed a commit that referenced this pull request Sep 16, 2024
## 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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants