Skip to content

Commit 7f53274

Browse files
Sjlverdyc3
andauthored
docs: safety of useSortedKeys (#6112)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dyc3 <1808807+dyc3@users.noreply.github.com>
1 parent 286be7a commit 7f53274

File tree

8 files changed

+61
-45
lines changed

8 files changed

+61
-45
lines changed

crates/biome_configuration/src/analyzer/assist/actions.rs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_configuration/src/analyzer/linter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum RuleDomainValue {
4747
All,
4848
/// Disables all the rules that belong to this domain
4949
None,
50-
/// It enables only the recommended rules for this domain
50+
/// Enables only the recommended rules for this domain
5151
Recommended,
5252
}
5353

crates/biome_configuration/src/analyzer/linter/rules.rs

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_js_analyze/src/assist/source/use_sorted_keys.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,28 @@ use biome_string_case::comparable_token::ComparableToken;
1818
use crate::JsRuleAction;
1919

2020
declare_source_rule! {
21-
/// Enforce ordering of a JS object properties.
22-
///
23-
/// This rule checks if keys of the object are sorted in a consistent way.
24-
/// Keys are sorted in a [natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order).
25-
/// This rule will consider spread/calculated keys e.g [k]: 1 as non-sortable.
26-
/// Instead, whenever it encounters a non-sortable key, it will sort all the
27-
/// previous sortable keys up until the nearest non-sortable key, if one
28-
/// exist.
29-
/// This prevents breaking the override of certain keys using spread
30-
/// keys.
21+
/// Sort properties of a JS object in natural order.
22+
///
23+
/// [Natural order](https://en.wikipedia.org/wiki/Natural_sort_order) means
24+
/// that uppercase letters come before lowercase letters (e.g. `A` < `a` <
25+
/// `B` < `b`) and numbers are compared in a human way (e.g. `9` < `10`).
26+
///
27+
/// This rule will consider spread/calculated keys e.g [k]: 1 as
28+
/// non-sortable. Instead, whenever it encounters a non-sortable key, it
29+
/// will sort all the previous sortable keys up until the nearest
30+
/// non-sortable key, if one exist. This prevents breaking the override of
31+
/// certain keys using spread keys.
32+
///
33+
/// Sorting the keys of an object technically changes the semantics of the
34+
/// program. It affects the result of operations like
35+
/// `Object.getOwnPropertyNames`. Since ES2020, operations like `for-in`
36+
/// loops, `Object.keys`, and `JSON.stringify` are guaranteed to process
37+
/// string keys in insertion order.
38+
///
39+
/// In cases where the order of such operations is important, you can
40+
/// disable the assist action using a suppression comment:
41+
///
42+
/// `// biome-ignore assist/source/useSortedKeys`
3143
///
3244
/// ## Examples
3345
///

crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ use biome_string_case::comparable_token::ComparableToken;
1313
use std::ops::Not;
1414

1515
declare_source_rule! {
16-
/// Sorts the keys of a JSON object in natural order
16+
/// Sort the keys of a JSON object in natural order.
17+
///
18+
/// [Natural order](https://en.wikipedia.org/wiki/Natural_sort_order) means
19+
/// that uppercase letters come before lowercase letters (e.g. `A` < `a` <
20+
/// `B` < `b`) and numbers are compared in a human way (e.g. `9` < `10`).
1721
///
1822
/// ## Examples
1923
///

packages/@biomejs/backend-jsonrpc/src/workspace.ts

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@biomejs/biome/configuration_schema.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xtask/codegen/src/generate_configuration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ fn generate_group_struct(
937937
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
938938
/// A list of rules that belong to this group
939939
pub struct #group_pascal_ident {
940-
/// It enables the recommended rules for this group
940+
/// Enables the recommended rules for this group
941941
#[serde(skip_serializing_if = "Option::is_none")]
942942
pub recommended: Option<bool>,
943943

@@ -1010,7 +1010,7 @@ fn generate_group_struct(
10101010
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
10111011
/// A list of rules that belong to this group
10121012
pub struct #group_pascal_ident {
1013-
/// It enables the recommended rules for this group
1013+
/// Enables the recommended rules for this group
10141014
#[serde(skip_serializing_if = "Option::is_none")]
10151015
pub recommended: Option<bool>,
10161016

0 commit comments

Comments
 (0)