@putout/printer 18.38.1 → 18.39.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.
package/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ 2026.08.21, v18.39.0
2
+
3
+ feature:
4
+ - 6d273c4b @putout/printer: callMaxArgsInOneLine: add
5
+ - e01b3f21 @putout/printer: CallExpression: simplify
6
+ - 0b780176 @putout/printer: CallExpression: apply type checker
7
+
1
8
  2026.07.16, v18.38.1
2
9
 
3
10
  fix:
package/README.md CHANGED
@@ -98,6 +98,7 @@ print(ast, {
98
98
  comments: true,
99
99
  maxSpecifiersInOneLine: 2,
100
100
  maxElementsInOneLine: 3,
101
+ maxArgsInOneLine: 100,
101
102
  maxElementLengthInOneLine: 15,
102
103
  maxLogicalsInOneLine: 3,
103
104
  maxVariablesInOneLine: 4,
@@ -0,0 +1,18 @@
1
+ export const CallExpressionWithMaxArgs = (path, {write, indent, traverse}) => {
2
+ const {name} = path.node.callee;
3
+ const args = path.get('arguments');
4
+
5
+ write(name);
6
+ write('(');
7
+ indent.inc();
8
+
9
+ for (const arg of args) {
10
+ write.breakline();
11
+ traverse(arg);
12
+ write(',');
13
+ }
14
+
15
+ indent.dec();
16
+ write.breakline();
17
+ write(')');
18
+ };
@@ -1,5 +1,14 @@
1
+ import {types} from '@putout/babel';
1
2
  import {exists, isInsideCall} from '#is';
2
3
  import {maybeParens} from '#maybe-parens';
4
+ import {createTypeChecker} from '#type-checker';
5
+ import {CallExpressionWithMaxArgs} from './call-expression-with-max-args.js';
6
+
7
+ const {
8
+ isIdentifier,
9
+ isObjectExpression,
10
+ isArrayExpression,
11
+ } = types;
3
12
 
4
13
  const {isArray} = Array;
5
14
 
@@ -12,9 +21,35 @@ const parseArgs = (path) => {
12
21
  return argsPath;
13
22
  };
14
23
 
15
- export const CallExpression = maybeParens((path, {indent, print, maybe, traverse}) => {
24
+ function isMaxArgs(path, {maxArgsInOneLine}) {
25
+ const args = parseArgs(path);
26
+
27
+ const [first] = args;
28
+
29
+ if (isArrayExpression(first))
30
+ return false;
31
+
32
+ return args.length >= maxArgsInOneLine;
33
+ }
34
+
35
+ const isNeedsNewLine = createTypeChecker([
36
+ ['-: -> !', tooLong],
37
+ ['+', isInsideCall],
38
+ ]);
39
+
40
+ export const CallExpression = maybeParens((path, printer, semantics) => {
41
+ if (isMaxArgs(path, semantics))
42
+ return CallExpressionWithMaxArgs(path, printer);
43
+
44
+ const {
45
+ indent,
46
+ print,
47
+ maybe,
48
+ traverse,
49
+ } = printer;
50
+
16
51
  const args = parseArgs(path);
17
- const isParentCall = tooLong(args) && isInsideCall(path);
52
+ const needsNewline = isNeedsNewLine(path, semantics);
18
53
 
19
54
  const callee = path.get('callee');
20
55
  const typeParameters = path.get('typeArguments');
@@ -31,17 +66,17 @@ export const CallExpression = maybeParens((path, {indent, print, maybe, traverse
31
66
 
32
67
  const n = args.length - 1;
33
68
 
34
- maybe.indent.inc(isParentCall);
69
+ maybe.indent.inc(needsNewline);
35
70
 
36
71
  for (const [i, arg] of args.entries()) {
37
- const isObject = arg.isObjectExpression();
72
+ const isObject = isObjectExpression(arg);
38
73
 
39
- if (isParentCall && !isObject && n)
74
+ if (needsNewline && !isObject && n)
40
75
  print.breakline();
41
76
 
42
77
  print(arg);
43
78
 
44
- if (isParentCall && n) {
79
+ if (needsNewline && n) {
45
80
  print(',');
46
81
  continue;
47
82
  }
@@ -52,7 +87,7 @@ export const CallExpression = maybeParens((path, {indent, print, maybe, traverse
52
87
  }
53
88
  }
54
89
 
55
- if (isParentCall) {
90
+ if (needsNewline) {
56
91
  indent.dec();
57
92
  maybe.print.breakline(n);
58
93
  }
@@ -62,9 +97,11 @@ export const CallExpression = maybeParens((path, {indent, print, maybe, traverse
62
97
 
63
98
  export const OptionalCallExpression = CallExpression;
64
99
 
65
- function tooLong(args) {
100
+ function tooLong(path) {
101
+ const args = parseArgs(path);
102
+
66
103
  for (const arg of args) {
67
- if (arg.isIdentifier() && arg.node.name.length > 10)
104
+ if (isIdentifier(arg) && arg.node.name.length > 10)
68
105
  return true;
69
106
  }
70
107
 
@@ -37,6 +37,7 @@ const initSemantics = (format, semantics = {}) => ({
37
37
  maxLogicalsInOneLine: 3,
38
38
  maxVariablesInOneLine: 4,
39
39
  maxTypesInOneLine: 3,
40
+ maxArgsInOneLine: 100,
40
41
  trailingComma: true,
41
42
  ...parseQuotes(format),
42
43
  ...semantics,
@@ -11,7 +11,7 @@ const FAIL = 1;
11
11
 
12
12
  export const report = (coverage) => {
13
13
  const lines = [];
14
- const log = (a) => lines.push(a);
14
+ const log = lines.push.bind(lines);
15
15
  let exitCode = SUCCESS;
16
16
 
17
17
  for (const [name, {covered, typeNames}] of coverage) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.38.1",
3
+ "version": "18.39.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
@@ -86,7 +86,6 @@
86
86
  "@putout/plugin-react-hooks": "^9.0.0",
87
87
  "@supertape/operator-strip": "^1.0.0",
88
88
  "acorn": "^8.8.2",
89
- "chalk": "^5.6.2",
90
89
  "check-dts": "^1.0.0",
91
90
  "escover": "^6.0.0",
92
91
  "eslint": "^10.0.0",