diff --git a/crates/biome_js_analyze/src/lib.rs b/crates/biome_js_analyze/src/lib.rs index 5883fe6caa94..50b8e00f6176 100644 --- a/crates/biome_js_analyze/src/lib.rs +++ b/crates/biome_js_analyze/src/lib.rs @@ -177,7 +177,6 @@ mod tests { use std::slice; use crate::lint::correctness::use_exhaustive_dependencies::{Hook, HooksOptions}; - use crate::react::hooks::StableHookResult; use crate::{analyze, AnalysisFilter, ControlFlow}; #[ignore] @@ -202,7 +201,7 @@ mod tests { name: "myEffect".to_string(), closure_index: Some(0), dependencies_index: Some(1), - stable_result: StableHookResult::None, + stable_result: None, }; let rule_filter = RuleFilter::Rule("style", "useNodejsImportProtocol"); diff --git a/crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs b/crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs index 27439c8ebfaf..e6dfb3de72a9 100644 --- a/crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs +++ b/crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs @@ -323,7 +323,7 @@ pub struct Hook { /// /// For example, for React's `useRef()` hook the value would be `true`, /// while for `useState()` it would be `[1]`. - pub stable_result: StableHookResult, + pub stable_result: Option, } impl DeserializableValidator for Hook { @@ -358,12 +358,14 @@ impl ReactExtensiveDependenciesOptions { pub fn new(hooks: HooksOptions) -> Self { let mut result = ReactExtensiveDependenciesOptions::default(); for hook in hooks.hooks { - if hook.stable_result != StableHookResult::None { - result.stable_config.insert(StableReactHookConfiguration { - hook_name: hook.name.clone(), - result: hook.stable_result, - builtin: false, - }); + if let Some(stable_result) = hook.stable_result { + if stable_result != StableHookResult::None { + result.stable_config.insert(StableReactHookConfiguration { + hook_name: hook.name.clone(), + result: stable_result, + builtin: false, + }); + } } if let (Some(closure_index), Some(dependencies_index)) = (hook.closure_index, hook.dependencies_index) diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index a95553ddd13b..564220a419cd 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -2356,7 +2356,7 @@ Set to `true` to mark the identity of the hook's return value as stable, or use For example, for React's `useRef()` hook the value would be `true`, while for `useState()` it would be `[1]`. */ - stableResult: StableHookResult; + stableResult?: StableHookResult; } export type Accessibility = "noPublic" | "explicit" | "none"; export type ConsistentArrayType = "shorthand" | "generic"; diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index ad93f0dca247..1fda7fe4248b 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -1312,7 +1312,7 @@ }, "Hook": { "type": "object", - "required": ["name", "stableResult"], + "required": ["name"], "properties": { "closureIndex": { "description": "The \"position\" of the closure function, starting from zero.\n\nFor example, for React's `useEffect()` hook, the closure index is 0.", @@ -1329,7 +1329,10 @@ "name": { "description": "The name of the hook.", "type": "string" }, "stableResult": { "description": "Whether the result of the hook is stable.\n\nSet to `true` to mark the identity of the hook's return value as stable, or use a number/an array of numbers to mark the \"positions\" in the return array as stable.\n\nFor example, for React's `useRef()` hook the value would be `true`, while for `useState()` it would be `[1]`.", - "allOf": [{ "$ref": "#/definitions/StableHookResult" }] + "anyOf": [ + { "$ref": "#/definitions/StableHookResult" }, + { "type": "null" } + ] } }, "additionalProperties": false