From 0d48b112fc6f0daf2e835e498899d91c3a975978 Mon Sep 17 00:00:00 2001 From: vohoanglong0107 Date: Tue, 30 Apr 2024 09:36:33 +0000 Subject: [PATCH] docs: update docs --- .../migrate/eslint_any_rule_to_biome.rs | 8 ++ .../biome_configuration/src/linter/rules.rs | 2 +- .../src/lint/nursery/use_jsx_sort_props.rs | 81 ++++++++++++++++--- .../@biomejs/backend-jsonrpc/src/workspace.ts | 2 +- .../@biomejs/biome/configuration_schema.json | 2 +- 5 files changed, 82 insertions(+), 13 deletions(-) diff --git a/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs b/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs index a8b970f2b07b..3438e30642df 100644 --- a/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs +++ b/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs @@ -1196,6 +1196,14 @@ pub(crate) fn migrate_eslint_any_rule( let rule = group.no_useless_fragments.get_or_insert(Default::default()); rule.set_level(rule_severity.into()); } + "react/jsx-sort-props" => { + if !options.include_nursery { + return false; + } + let group = rules.nursery.get_or_insert_with(Default::default); + let rule = group.use_jsx_sort_props.get_or_insert(Default::default()); + rule.set_level(rule_severity.into()); + } "react/no-array-index-key" => { let group = rules.suspicious.get_or_insert_with(Default::default); let rule = group.no_array_index_key.get_or_insert(Default::default()); diff --git a/crates/biome_configuration/src/linter/rules.rs b/crates/biome_configuration/src/linter/rules.rs index 403490af1fc6..bbec66b40a95 100644 --- a/crates/biome_configuration/src/linter/rules.rs +++ b/crates/biome_configuration/src/linter/rules.rs @@ -2724,7 +2724,7 @@ pub struct Nursery { #[doc = "Disallows package private imports."] #[serde(skip_serializing_if = "Option::is_none")] pub use_import_restrictions: Option>, - #[doc = "Succinct description of the rule."] + #[doc = "Enforce props sorting in JSX elements."] #[serde(skip_serializing_if = "Option::is_none")] pub use_jsx_sort_props: Option>, #[doc = "Enforce the sorting of CSS utility classes."] diff --git a/crates/biome_js_analyze/src/lint/nursery/use_jsx_sort_props.rs b/crates/biome_js_analyze/src/lint/nursery/use_jsx_sort_props.rs index a99abecf4ebd..fdf4337be24a 100644 --- a/crates/biome_js_analyze/src/lint/nursery/use_jsx_sort_props.rs +++ b/crates/biome_js_analyze/src/lint/nursery/use_jsx_sort_props.rs @@ -4,6 +4,7 @@ use std::cmp::Ordering; use biome_analyze::{ context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic, + RuleSource, RuleSourceKind, }; use biome_console::markup; use biome_deserialize_macros::Deserializable; @@ -15,33 +16,93 @@ use serde::{Deserialize, Serialize}; use crate::JsRuleAction; declare_rule! { - /// Succinct description of the rule. + /// Enforce props sorting in JSX elements. /// - /// Put context and details about the rule. - /// As a starting point, you can take the description of the corresponding _ESLint_ rule (if any). - /// - /// Try to stay consistent with the descriptions of implemented rules. - /// - /// Add a link to the corresponding ESLint rule (if any): + /// This rule checks if the JSX props are sorted in a consistent way. + /// A spread prop resets the sorting order. + /// The rule can be configured to sort props alphabetically, ignore case, and more. /// /// ## Examples /// /// ### Invalid /// /// ```js,expect_diagnostic - /// var a = 1; - /// a = 2; + /// ; /// ``` /// /// ### Valid /// /// ```js - /// // var a = 1; + /// ; + /// ; + /// ``` + /// + /// ## Options + /// + /// ### `callbacksLast` + /// + /// When `true`, callback props are sorted last. + /// + /// #### Example + /// + /// ```js + /// ; + /// ``` + /// + /// ### `shorthand` + /// + /// When `first`, shorthand props are sorted first. + /// When `last`, shorthand props are sorted last, unless `callbacksLast` is `true`, + /// in which case they are sorted before callbacks. + /// Default is `ignore`. + /// + /// #### Example + /// + /// ```js + /// // shorthand first + /// ; + /// // shorthand last + /// ; + /// ``` + /// + /// ### `multiline` + /// + /// When `first`, multiline props are sorted first, unless `shorthand` is `first`, + /// in which case they are sorted after shorthand props. + /// When `last`, multiline props are sorted last, unless `shorthand` is `last` or `callbacksLast` is `true`, + /// in which case they are sorted before shorthand props or callbacks. + /// Default is `ignore`. + /// + /// #### Example + /// + /// ```js + /// // multiline first + /// ; + /// // multiline last + /// ; /// ``` /// pub UseJsxSortProps { version: "next", name: "useJsxSortProps", + sources: &[RuleSource::EslintReact("jsx-sort-props")], + source_kind: RuleSourceKind::SameLogic, recommended: false, fix_kind: FixKind::Safe, } diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 370bb53249ac..1824e6ffc7d3 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -1013,7 +1013,7 @@ export interface Nursery { */ useImportRestrictions?: RuleConfiguration_for_Null; /** - * Succinct description of the rule. + * Enforce props sorting in JSX elements. */ useJsxSortProps?: RuleConfiguration_for_UseJsxSortPropsOptions; /** diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index 8a5fd9a396fc..0b7c006b206f 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -1617,7 +1617,7 @@ ] }, "useJsxSortProps": { - "description": "Succinct description of the rule.", + "description": "Enforce props sorting in JSX elements.", "anyOf": [ { "$ref": "#/definitions/UseJsxSortPropsConfiguration" }, { "type": "null" }