Skip to content

Commit 2e1086c

Browse files
committed
refactor(formatter,oxfmt): Use Sort prefix for tailwind options
1 parent c2b788a commit 2e1086c

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

apps/oxfmt/src/core/oxfmtrc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use oxc_formatter::{
99
ArrowParentheses, AttributePosition, BracketSameLine, BracketSpacing, CustomGroupDefinition,
1010
EmbeddedLanguageFormatting, Expand, FormatOptions, GroupEntry, ImportModifier, ImportSelector,
1111
IndentStyle, IndentWidth, LineEnding, LineWidth, QuoteProperties, QuoteStyle, Semicolons,
12-
SortImportsOptions, SortOrder, TailwindcssOptions, TrailingCommas,
12+
SortImportsOptions, SortOrder, SortTailwindcssOptions, TrailingCommas,
1313
};
1414
use oxc_toml::Options as TomlFormatterOptions;
1515

@@ -231,7 +231,7 @@ pub struct FormatConfig {
231231
/// - Default: Disabled
232232
#[serde(skip_serializing_if = "Option::is_none")]
233233
#[serde(alias = "experimentalTailwindcss")]
234-
pub sort_tailwindcss: Option<TailwindcssConfig>,
234+
pub sort_tailwindcss: Option<SortTailwindcssConfig>,
235235
}
236236

237237
impl FormatConfig {
@@ -515,7 +515,7 @@ impl FormatConfig {
515515
}
516516

517517
if let Some(config) = self.sort_tailwindcss {
518-
format_options.sort_tailwindcss = Some(TailwindcssOptions {
518+
format_options.sort_tailwindcss = Some(SortTailwindcssOptions {
519519
config: config.config,
520520
stylesheet: config.stylesheet,
521521
functions: config.functions.unwrap_or_default(),
@@ -867,7 +867,7 @@ impl SortPackageJsonConfig {
867867

868868
#[derive(Debug, Clone, Default, Deserialize, Serialize, JsonSchema)]
869869
#[serde(rename_all = "camelCase", default)]
870-
pub struct TailwindcssConfig {
870+
pub struct SortTailwindcssConfig {
871871
/// Path to your Tailwind CSS configuration file (v3).
872872
///
873873
/// NOTE: Paths are resolved relative to the Oxfmt configuration file.

crates/oxc_formatter/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ pub struct FormatOptions {
7878
/// Enable Tailwind CSS class sorting in JSX class/className attributes.
7979
/// When enabled, class strings will be collected and passed to a callback for sorting.
8080
/// Defaults to None (disabled).
81-
pub sort_tailwindcss: Option<TailwindcssOptions>,
81+
pub sort_tailwindcss: Option<SortTailwindcssOptions>,
8282
}
8383

8484
/// Options for Tailwind CSS class sorting.
8585
/// Based on options from `prettier-plugin-tailwindcss`.
8686
///
8787
/// See <https://github.com/tailwindlabs/prettier-plugin-tailwindcss#options>
8888
#[derive(Debug, Default, Clone)]
89-
pub struct TailwindcssOptions {
89+
pub struct SortTailwindcssOptions {
9090
/// Path to your Tailwind CSS configuration file (v3).
9191
///
9292
/// Note: Paths are resolved relative to the Oxfmt configuration file.

crates/oxc_formatter/src/utils/tailwindcss.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use oxc_ast::ast::*;
1111
use oxc_span::GetSpan;
1212

1313
use crate::{
14-
Buffer, TailwindcssOptions,
14+
Buffer, SortTailwindcssOptions,
1515
ast_nodes::{AstNode, AstNodes},
1616
formatter::{FormatElement, Formatter, TailwindContextEntry, prelude::*},
1717
write,
@@ -51,7 +51,7 @@ pub fn tailwind_context_for_string_literal<'a>(
5151
/// - Custom attributes specified in `attributes` option
5252
pub fn is_tailwind_jsx_attribute(
5353
attr_name: &JSXAttributeName<'_>,
54-
options: &TailwindcssOptions,
54+
options: &SortTailwindcssOptions,
5555
) -> bool {
5656
let JSXAttributeName::Identifier(ident) = attr_name else {
5757
return false;
@@ -79,7 +79,10 @@ pub fn is_tailwind_jsx_attribute(
7979
/// - `foo().clsx(...)` - chained calls
8080
///
8181
/// Based on [prettier-plugin-tailwindcss's `isSortableExpression`](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/blob/28beb4e008b913414562addec4abb8ab261f3828/src/index.ts#L584-L605).
82-
pub fn is_tailwind_function_call(callee: &Expression<'_>, options: &TailwindcssOptions) -> bool {
82+
pub fn is_tailwind_function_call(
83+
callee: &Expression<'_>,
84+
options: &SortTailwindcssOptions,
85+
) -> bool {
8386
if options.functions.is_empty() {
8487
return false;
8588
}

npm/oxfmt/configuration_schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"description": "Sort Tailwind CSS classes.\n\nUsing the same algorithm as [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss).\nOption names omit the `tailwind` prefix used in the original plugin (e.g., `config` instead of `tailwindConfig`).\nFor details, see each field's documentation.\n\n- Default: Disabled",
205205
"anyOf": [
206206
{
207-
"$ref": "#/definitions/TailwindcssConfig"
207+
"$ref": "#/definitions/SortTailwindcssConfig"
208208
},
209209
{
210210
"type": "null"
@@ -496,7 +496,7 @@
496496
"description": "Sort Tailwind CSS classes.\n\nUsing the same algorithm as [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss).\nOption names omit the `tailwind` prefix used in the original plugin (e.g., `config` instead of `tailwindConfig`).\nFor details, see each field's documentation.\n\n- Default: Disabled",
497497
"anyOf": [
498498
{
499-
"$ref": "#/definitions/TailwindcssConfig"
499+
"$ref": "#/definitions/SortTailwindcssConfig"
500500
},
501501
{
502502
"type": "null"
@@ -771,7 +771,7 @@
771771
}
772772
]
773773
},
774-
"TailwindcssConfig": {
774+
"SortTailwindcssConfig": {
775775
"type": "object",
776776
"properties": {
777777
"attributes": {

tasks/website_formatter/src/snapshots/schema_json.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ expression: json
208208
"description": "Sort Tailwind CSS classes.\n\nUsing the same algorithm as [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss).\nOption names omit the `tailwind` prefix used in the original plugin (e.g., `config` instead of `tailwindConfig`).\nFor details, see each field's documentation.\n\n- Default: Disabled",
209209
"anyOf": [
210210
{
211-
"$ref": "#/definitions/TailwindcssConfig"
211+
"$ref": "#/definitions/SortTailwindcssConfig"
212212
},
213213
{
214214
"type": "null"
@@ -500,7 +500,7 @@ expression: json
500500
"description": "Sort Tailwind CSS classes.\n\nUsing the same algorithm as [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss).\nOption names omit the `tailwind` prefix used in the original plugin (e.g., `config` instead of `tailwindConfig`).\nFor details, see each field's documentation.\n\n- Default: Disabled",
501501
"anyOf": [
502502
{
503-
"$ref": "#/definitions/TailwindcssConfig"
503+
"$ref": "#/definitions/SortTailwindcssConfig"
504504
},
505505
{
506506
"type": "null"
@@ -775,7 +775,7 @@ expression: json
775775
}
776776
]
777777
},
778-
"TailwindcssConfig": {
778+
"SortTailwindcssConfig": {
779779
"type": "object",
780780
"properties": {
781781
"attributes": {

0 commit comments

Comments
 (0)