Skip to content

Commit

Permalink
fix(project): fix JSON schema for stable hook options (#2401)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored Apr 10, 2024
1 parent 08ab901 commit b9f716d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Biome configuration files can correctly extends `.jsonc` configuration files now ([#2279](https://github.com/biomejs/biome/issues/2279)). Contributed by @Sec-ant

- Fixed the JSON schema for React hooks configuration ([#2396](https://github.com/biomejs/biome/issues/2396)). Contributed by @arendjr

#### Enhancements

- Biome now displays the location of a parsing error for its configuration file ([#1627](https://github.com/biomejs/biome/issues/1627)).
Expand Down
50 changes: 49 additions & 1 deletion crates/biome_js_analyze/src/react/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ impl StableReactHookConfiguration {
}

#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum StableHookResult {
/// Used to indicate the hook does not have a stable result.
#[default]
Expand All @@ -252,6 +251,55 @@ pub enum StableHookResult {
Indices(Vec<u8>),
}

#[cfg(feature = "schemars")]
impl JsonSchema for StableHookResult {
fn schema_name() -> String {
"StableHookResult".to_owned()
}

fn json_schema(_gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
use schemars::schema::*;
Schema::Object(SchemaObject {
subschemas: Some(Box::new(SubschemaValidation {
one_of: Some(vec![
Schema::Object(SchemaObject {
instance_type: Some(InstanceType::Boolean.into()),
metadata: Some(Box::new(Metadata {
description: Some("Whether the hook has a stable result.".to_owned()),
..Default::default()
})),
..Default::default()
}),
Schema::Object(SchemaObject {
instance_type: Some(InstanceType::Array.into()),
array: Some(Box::new(ArrayValidation {
items: Some(SingleOrVec::Single(Box::new(Schema::Object(SchemaObject {
instance_type: Some(InstanceType::Integer.into()),
format: Some("uint8".to_owned()),
number: Some(Box::new(NumberValidation {
minimum: Some(0.),
maximum: Some(255.),
..Default::default()
})),
..Default::default()
})))),
min_items: Some(1),
..Default::default()
})),
metadata: Some(Box::new(Metadata {
description: Some("Used to indicate the hook returns an array and some of its indices have stable identities.".to_owned()),
..Default::default()
})),
..Default::default()
})
]),
..Default::default()
})),
..Default::default()
})
}
}

impl biome_deserialize::Deserializable for StableHookResult {
fn deserialize(
value: &impl DeserializableValue,
Expand Down
2 changes: 1 addition & 1 deletion packages/@biomejs/backend-jsonrpc/src/workspace.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 10 additions & 17 deletions packages/@biomejs/biome/configuration_schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions website/src/content/docs/internals/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Biome configuration files can correctly extends `.jsonc` configuration files now ([#2279](https://github.com/biomejs/biome/issues/2279)). Contributed by @Sec-ant

- Fixed the JSON schema for React hooks configuration ([#2396](https://github.com/biomejs/biome/issues/2396)). Contributed by @arendjr

#### Enhancements

- Biome now displays the location of a parsing error for its configuration file ([#1627](https://github.com/biomejs/biome/issues/1627)).
Expand Down

0 comments on commit b9f716d

Please sign in to comment.