Skip to content

Commit

Permalink
chore(turbo-tasks): Add a lint for Vc<T> in turbo-tasks types (#73298)
Browse files Browse the repository at this point in the history
### What?

Add a lint for `Vc<T>` in structs or enums with `#[turbo_tasks::value]`.

### Why?

We need to change them to `ResolvedVc<T>` so I'm adding a lint to check make it easier.

### How?

I asked a question of `ast-grep` discord. 

- https://discord.com/channels/1107749847722889217/1113524796316200980/1311549077275676753
  • Loading branch information
kdy1 authored Nov 28, 2024
1 parent 017da1b commit f121fbe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .config/ast-grep/rules/resolved-vc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json

id: no-vc-struct
message: Don't use a Vc directly in a struct
note: 'Prefer using ResolvedVc, or add a `// no-resolved-vc(<AUTHOR>): <REASON>` comment'
severity: warning
language: rust

rule:
pattern:
context: 'let x: Vc<$A> = 1;'
selector: generic_type
inside:
stopBy: end
not:
follows:
kind: line_comment
regex: \s*//\s*no-resolved-vc\((.+)\):.+
inside:
inside:
any:
- kind: struct_item
follows:
stopBy:
not:
kind: attribute_item
kind: attribute_item
has:
kind: attribute
regex: '^turbo_tasks::value(\(.*\))?$'
- inside:
kind: enum_variant_list
inside:
follows:
stopBy:
not:
kind: attribute_item
kind: attribute_item
has:
kind: attribute
regex: '^turbo_tasks::value(\(.*\))?$'
fix: ResolvedVc<$A>
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks/src/vc/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct ResolvedVc<T>
where
T: ?Sized,
{
// no-resolved-vc(kdy1): This is a resolved Vc, so we don't need to resolve it again
pub(crate) node: Vc<T>,
}

Expand Down

0 comments on commit f121fbe

Please sign in to comment.