liquidsoap-prettier 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +4 -0
  3. package/src/index.js +21 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liquidsoap-prettier",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Liquidsoap language prettier CLI and plugin",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/cli.js CHANGED
@@ -15,8 +15,10 @@ const run = async () => {
15
15
  w,
16
16
  check,
17
17
  c,
18
+ "print-width": printWidth = 80,
18
19
  } = parseArgs(process.argv.slice(2), {
19
20
  boolean: ["w", "write", "c", "check"],
21
+ number: ["print-width"],
20
22
  });
21
23
 
22
24
  if (!filename) {
@@ -53,12 +55,14 @@ const run = async () => {
53
55
  const isFormatted = await prettier.check(code, {
54
56
  parser: "liquidsoap",
55
57
  plugins: [prettierPluginLiquidsoap],
58
+ printWidth,
56
59
  });
57
60
  exitCode = isFormatted ? 0 : 2;
58
61
  } else {
59
62
  const formattedCode = await prettier.format(code, {
60
63
  parser: "liquidsoap",
61
64
  plugins: [prettierPluginLiquidsoap],
65
+ printWidth,
62
66
  });
63
67
 
64
68
  if (write || w) {
package/src/index.js CHANGED
@@ -44,9 +44,7 @@ const printString = (str) => {
44
44
  str
45
45
  .replace(/\\\n\s*/g, "")
46
46
  .split(/(\s)/)
47
- .map((s) =>
48
- s === " " ? ifBreak(group([" ", "\\", hardline, " "]), " ") : s,
49
- ),
47
+ .map((s) => (s === " " ? ifBreak([" ", "\\", hardline, " "], " ") : s)),
50
48
  );
51
49
  };
52
50
 
@@ -202,8 +200,7 @@ const print = (path, options, print) => {
202
200
  group([...printLabel(), ...(node.default ? ["=", print("default")] : [])]);
203
201
 
204
202
  const printAppArg = () => {
205
- if (node.label)
206
- return group([node.label, "=", indent([softline, print("value")])]);
203
+ if (node.label) return group([node.label, "=", print("value")]);
207
204
  return print("value");
208
205
  };
209
206
 
@@ -334,13 +331,9 @@ const print = (path, options, print) => {
334
331
  case "while":
335
332
  return group([
336
333
  "while",
337
- line,
338
- print("condition"),
339
- line,
334
+ group([indent([line, print("condition")]), line]),
340
335
  "do",
341
- line,
342
- print("loop"),
343
- line,
336
+ group([indent([line, print("loop")]), line]),
344
337
  "end",
345
338
  ]);
346
339
  case "for":
@@ -518,17 +511,23 @@ const print = (path, options, print) => {
518
511
  case "app_arg":
519
512
  return printAppArg();
520
513
  case "app":
521
- return group([
522
- print("op"),
523
- "(",
524
- ...(node.args.length === 0
525
- ? []
526
- : [
527
- indent([softline, group([joinWithComments([","], "args")])]),
528
- softline,
529
- ]),
530
- ")",
531
- ]);
514
+ if (node.args.length === 0) {
515
+ return group([print("op"), "(", ")"]);
516
+ }
517
+
518
+ // Print all arguments
519
+ const printedArgs = path.map(print, "args");
520
+
521
+ // Try to format on a single line first
522
+ const singleLine = join(", ", printedArgs);
523
+
524
+ // Format with line breaks
525
+ const multiLine = [
526
+ indent([line, join([",", line], printedArgs)]),
527
+ line,
528
+ ];
529
+
530
+ return group([print("op"), "(", ifBreak(multiLine, singleLine), ")"]);
532
531
  case "eof":
533
532
  return "";
534
533
  case "seq":