From 32ad3ebc2f8d78b9319824b5ac5128ddc492ecbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 28 Nov 2024 13:53:47 +0900 Subject: [PATCH 1/2] ResolvedVc lint --- .config/ast-grep/rules/resolved-vc.yml | 43 +++++++++++++++++++ .../crates/turbo-tasks/src/vc/resolved.rs | 1 + 2 files changed, 44 insertions(+) create mode 100644 .config/ast-grep/rules/resolved-vc.yml diff --git a/.config/ast-grep/rules/resolved-vc.yml b/.config/ast-grep/rules/resolved-vc.yml new file mode 100644 index 0000000000000..69569d0a9ede7 --- /dev/null +++ b/.config/ast-grep/rules/resolved-vc.yml @@ -0,0 +1,43 @@ +# 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(): ` comment' +severity: warning +language: rust + +rule: + pattern: + context: 'let x: Vc<$A> = 1;' + selector: generic_type + inside: + stopBy: end + kind: field_declaration + 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> diff --git a/turbopack/crates/turbo-tasks/src/vc/resolved.rs b/turbopack/crates/turbo-tasks/src/vc/resolved.rs index 77bca100563cf..3bfb2bd2e8e32 100644 --- a/turbopack/crates/turbo-tasks/src/vc/resolved.rs +++ b/turbopack/crates/turbo-tasks/src/vc/resolved.rs @@ -36,6 +36,7 @@ pub struct ResolvedVc 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, } From bb5c4358b3167551e32fdce2d013c33b3a7a603f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 28 Nov 2024 18:03:37 +0900 Subject: [PATCH 2/2] improve lint to support tuple structs --- .config/ast-grep/rules/resolved-vc.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.config/ast-grep/rules/resolved-vc.yml b/.config/ast-grep/rules/resolved-vc.yml index 69569d0a9ede7..5dacc94ad70bf 100644 --- a/.config/ast-grep/rules/resolved-vc.yml +++ b/.config/ast-grep/rules/resolved-vc.yml @@ -12,7 +12,6 @@ rule: selector: generic_type inside: stopBy: end - kind: field_declaration not: follows: kind: line_comment