liquidsoap-prettier 1.6.0 → 1.7.1

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.
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "liquidsoap-prettier",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
4
4
  "description": "Liquidsoap language prettier CLI and plugin",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "bin": {
8
8
  "liquidsoap-prettier": "src/cli.js"
9
9
  },
10
+ "scripts": {
11
+ "build:web": "webpack --config webpack.web.cjs",
12
+ "release": "dune build && npm run build:web && npm publish",
13
+ "dev:prepare": "node ./scripts/download-parser.js",
14
+ "liquidsoap-prettier": "node ./src/cli.js"
15
+ },
10
16
  "prettier": {
11
17
  "plugins": [
12
18
  "./src/index.js"
@@ -28,11 +34,5 @@
28
34
  "tar-fs": "^3.0.6",
29
35
  "webpack": "^5.89.0",
30
36
  "webpack-cli": "^5.1.4"
31
- },
32
- "scripts": {
33
- "build:web": "webpack --config webpack.web.cjs",
34
- "release": "dune build && npm run build:web && npm publish",
35
- "dev:prepare": "node ./scripts/download-parser.js",
36
- "liquidsoap-prettier": "node ./src/cli.js"
37
37
  }
38
- }
38
+ }
File without changes
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
 
@@ -223,6 +220,8 @@ const print = (path, options, print) => {
223
220
  ];
224
221
  case "list":
225
222
  return group(["[", indent([softline, print("value")]), softline, "]"]);
223
+ case "ref":
224
+ return group(["ref", "(", print("value"), ")"]);
226
225
  case "json_object":
227
226
  return [
228
227
  "[",
@@ -334,13 +333,9 @@ const print = (path, options, print) => {
334
333
  case "while":
335
334
  return group([
336
335
  "while",
337
- line,
338
- print("condition"),
339
- line,
336
+ group([indent([line, print("condition")]), line]),
340
337
  "do",
341
- line,
342
- print("loop"),
343
- line,
338
+ group([indent([line, print("loop")]), line]),
344
339
  "end",
345
340
  ]);
346
341
  case "for":
@@ -518,17 +513,23 @@ const print = (path, options, print) => {
518
513
  case "app_arg":
519
514
  return printAppArg();
520
515
  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
- ]);
516
+ if (node.args.length === 0) {
517
+ return group([print("op"), "(", ")"]);
518
+ }
519
+
520
+ // Print all arguments
521
+ const printedArgs = path.map(print, "args");
522
+
523
+ // Try to format on a single line first
524
+ const singleLine = join(", ", printedArgs);
525
+
526
+ // Format with line breaks
527
+ const multiLine = [
528
+ indent([line, join([",", line], printedArgs)]),
529
+ line,
530
+ ];
531
+
532
+ return group([print("op"), "(", ifBreak(multiLine, singleLine), ")"]);
532
533
  case "eof":
533
534
  return "";
534
535
  case "seq":