Skip to content

Commit 9504491

Browse files
committed
docs: Add arrowParens and experimentalOperatorPosition options to plugin and website playground
1 parent 0a977f0 commit 9504491

File tree

5 files changed

+2144
-2791
lines changed

5 files changed

+2144
-2791
lines changed

packages/prettier-plugin-java/src/options.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ export default {
253253
description:
254254
"Prettify from the entrypoint, allowing to use prettier on snippet."
255255
},
256+
arrowParens: {
257+
type: "choice",
258+
category: "Java",
259+
default: "avoid",
260+
choices: [
261+
{ value: "always", description: "" },
262+
{ value: "avoid", description: "" }
263+
],
264+
description: "Include parentheses around a sole arrow function parameter."
265+
},
256266
trailingComma: {
257267
type: "choice",
258268
category: "Java",
@@ -263,5 +273,15 @@ export default {
263273
{ value: "none", description: "" }
264274
],
265275
description: "Print trailing commas wherever possible when multi-line."
276+
},
277+
experimentalOperatorPosition: {
278+
type: "choice",
279+
category: "Java",
280+
default: "end",
281+
choices: [
282+
{ value: "start", description: "" },
283+
{ value: "end", description: "" }
284+
],
285+
description: "Where to print operators when binary expressions wrap lines."
266286
}
267287
} satisfies SupportOptions;

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@monaco-editor/react": "^4",
2222
"lz-string": "^1",
2323
"prettier": "^3",
24-
"prettier-plugin-java": "file:./../packages/prettier-plugin-java/dist",
24+
"prettier-plugin-java": "file:../packages/prettier-plugin-java/dist",
2525
"prism-react-renderer": "^2",
2626
"react": "^19",
2727
"react-dom": "^19"

website/src/components/CodeEditor/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useColorMode } from "@docusaurus/theme-common";
2-
import Editor from "@monaco-editor/react";
2+
import { Editor, type OnChange } from "@monaco-editor/react";
33
import styles from "./index.module.css";
44

55
export default function CodeEditor(
66
props: Readonly<{
77
readOnly?: boolean;
88
rulers?: number[];
99
value?: string;
10-
onChange?: (value: string | undefined) => void;
10+
onChange?: OnChange;
1111
}>
1212
) {
1313
const { colorMode } = useColorMode();

website/src/pages/playground/index.tsx

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ interface State {
1111
printWidth?: number;
1212
tabWidth?: number;
1313
useTabs?: boolean;
14+
arrowParens?: ArrowParens;
1415
trailingComma?: TrailingComma;
16+
experimentalOperatorPosition?: ExperimentalOperatorPosition;
1517
requirePragma?: boolean;
1618
code?: string;
1719
}
1820

21+
enum ArrowParens {
22+
Always = "always",
23+
Avoid = "avoid"
24+
}
25+
1926
enum TrailingComma {
2027
All = "all",
2128
Es5 = "es5",
2229
None = "none"
2330
}
2431

32+
enum ExperimentalOperatorPosition {
33+
Start = "start",
34+
End = "end"
35+
}
36+
2537
const codeSample = `public interface MyInterface {
2638
String foo();
2739
int[] bar();
@@ -63,9 +75,17 @@ function Inner() {
6375
const [printWidth, setPrintWidth] = useState(initialState.printWidth ?? 80);
6476
const [tabWidth, setTabWidth] = useState(initialState.tabWidth ?? 2);
6577
const [useTabs, setUseTabs] = useState(initialState.useTabs ?? false);
66-
const [trailingComma, setTrailingComma] = useState<TrailingComma>(
78+
const [arrowParens, setArrowParens] = useState(
79+
initialState.arrowParens ?? ArrowParens.Avoid
80+
);
81+
const [trailingComma, setTrailingComma] = useState(
6782
initialState.trailingComma ?? TrailingComma.All
6883
);
84+
const [experimentalOperatorPosition, setExperimentalOperatorPosition] =
85+
useState(
86+
initialState.experimentalOperatorPosition ??
87+
ExperimentalOperatorPosition.End
88+
);
6989
const [requirePragma, setRequirePragma] = useState(
7090
initialState.requirePragma ?? false
7191
);
@@ -82,7 +102,9 @@ function Inner() {
82102
printWidth,
83103
tabWidth,
84104
useTabs,
105+
arrowParens,
85106
trailingComma,
107+
experimentalOperatorPosition,
86108
requirePragma,
87109
code
88110
});
@@ -96,12 +118,23 @@ function Inner() {
96118
printWidth,
97119
tabWidth,
98120
useTabs,
121+
arrowParens,
99122
trailingComma,
123+
experimentalOperatorPosition,
100124
requirePragma
101125
})
102126
.then(setFormattedCode)
103127
.catch(error => setFormattedCode(error.message));
104-
}, [printWidth, tabWidth, useTabs, trailingComma, requirePragma, code]);
128+
}, [
129+
printWidth,
130+
tabWidth,
131+
useTabs,
132+
arrowParens,
133+
trailingComma,
134+
experimentalOperatorPosition,
135+
requirePragma,
136+
code
137+
]);
105138

106139
return (
107140
<div className={styles.playground}>
@@ -137,6 +170,19 @@ function Inner() {
137170
</details>
138171
<details open>
139172
<summary>Java</summary>
173+
<label title="Include parentheses around a sole arrow function parameter.">
174+
--arrow-parens{" "}
175+
<select
176+
value={arrowParens}
177+
onChange={event =>
178+
setArrowParens(event.target.value as ArrowParens)
179+
}
180+
>
181+
{Object.values(ArrowParens).map(option => (
182+
<option key={option}>{option}</option>
183+
))}
184+
</select>
185+
</label>
140186
<label title="Print trailing commas wherever possible when multi-line.">
141187
--trailing-comma{" "}
142188
<select
@@ -150,6 +196,21 @@ function Inner() {
150196
))}
151197
</select>
152198
</label>
199+
<label title="Where to print operators when binary expressions wrap lines.">
200+
--experimental-operator-position{" "}
201+
<select
202+
value={experimentalOperatorPosition}
203+
onChange={event =>
204+
setExperimentalOperatorPosition(
205+
event.target.value as ExperimentalOperatorPosition
206+
)
207+
}
208+
>
209+
{Object.values(ExperimentalOperatorPosition).map(option => (
210+
<option key={option}>{option}</option>
211+
))}
212+
</select>
213+
</label>
153214
</details>
154215
<details open>
155216
<summary>Special</summary>

0 commit comments

Comments
 (0)