@putout/printer 15.3.2 → 15.5.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 +10 -0
- package/README.md +1 -0
- package/lib/tokenize/expressions/array-expression/array-expression.js +2 -0
- package/lib/tokenize/expressions/array-expression/newline.js +17 -1
- package/lib/tokenize/maybe/maybe-type-annotation.js +15 -1
- package/lib/tokenize/overrides/overrides.js +1 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2025.06.19, v15.5.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- c73f1da @putout/printer: ArrayExpression: maxElementLengthInOneLine: add
|
|
5
|
+
|
|
6
|
+
2025.06.18, v15.4.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 3317e10 @putout/printer: Identifier: typeAnnotation: do not print inside SequenceExpression, MemberExpression
|
|
10
|
+
|
|
1
11
|
2025.06.14, v15.3.2
|
|
2
12
|
|
|
3
13
|
fix:
|
package/README.md
CHANGED
|
@@ -102,6 +102,7 @@ module.exports.ArrayExpression = {
|
|
|
102
102
|
const {
|
|
103
103
|
maxElementsInOneLine,
|
|
104
104
|
trailingComma,
|
|
105
|
+
maxElementLengthInOneLine,
|
|
105
106
|
} = semantics;
|
|
106
107
|
|
|
107
108
|
const elements = path.get('elements');
|
|
@@ -116,6 +117,7 @@ module.exports.ArrayExpression = {
|
|
|
116
117
|
const isNewLine = isMultiLine(path, {
|
|
117
118
|
elements,
|
|
118
119
|
maxElementsInOneLine,
|
|
120
|
+
maxElementLengthInOneLine,
|
|
119
121
|
});
|
|
120
122
|
|
|
121
123
|
const n = elements.length - 1;
|
|
@@ -23,6 +23,7 @@ const {
|
|
|
23
23
|
isNullLiteral,
|
|
24
24
|
isStringLiteral,
|
|
25
25
|
isSpreadElement,
|
|
26
|
+
isIdentifier,
|
|
26
27
|
} = types;
|
|
27
28
|
|
|
28
29
|
const {round} = Math;
|
|
@@ -59,9 +60,24 @@ const isSiblingIsArray = (path) => {
|
|
|
59
60
|
.isArrayExpression();
|
|
60
61
|
};
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
function isMaxElementLengthInOneLine(elements, maxElementLengthInOneLine) {
|
|
64
|
+
if (elements.length > 1)
|
|
65
|
+
return false;
|
|
66
|
+
|
|
63
67
|
const [first] = elements;
|
|
64
68
|
|
|
69
|
+
if (!isIdentifier(first))
|
|
70
|
+
return false;
|
|
71
|
+
|
|
72
|
+
return first.node.name.length < maxElementLengthInOneLine;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports.isMultiLine = (path, {elements, maxElementsInOneLine, maxElementLengthInOneLine}) => {
|
|
76
|
+
const [first] = elements;
|
|
77
|
+
|
|
78
|
+
if (isMaxElementLengthInOneLine(elements, maxElementLengthInOneLine))
|
|
79
|
+
return ONE_LINE;
|
|
80
|
+
|
|
65
81
|
if (elements.length > maxElementsInOneLine && isStringLiteral(first))
|
|
66
82
|
return MULTI_LINE;
|
|
67
83
|
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
const {
|
|
5
|
+
isMemberExpression,
|
|
6
|
+
isSequenceExpression,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
3
9
|
module.exports.maybePrintTypeAnnotation = maybePrintTypeAnnotation;
|
|
4
10
|
|
|
5
11
|
module.exports.maybeTypeAnnotation = (visit) => (path, printer, semantics) => {
|
|
@@ -9,9 +15,17 @@ module.exports.maybeTypeAnnotation = (visit) => (path, printer, semantics) => {
|
|
|
9
15
|
};
|
|
10
16
|
|
|
11
17
|
function maybePrintTypeAnnotation(path, printer) {
|
|
12
|
-
const {
|
|
18
|
+
const {parentPath, node} = path;
|
|
19
|
+
|
|
20
|
+
const {typeAnnotation} = node;
|
|
13
21
|
const {write, traverse} = printer;
|
|
14
22
|
|
|
23
|
+
if (isSequenceExpression(parentPath))
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
if (isMemberExpression(parentPath))
|
|
27
|
+
return;
|
|
28
|
+
|
|
15
29
|
if (typeAnnotation) {
|
|
16
30
|
write(':');
|
|
17
31
|
write.space();
|
|
@@ -35,6 +35,7 @@ const initSemantics = (format, semantics = {}) => ({
|
|
|
35
35
|
maxPropertiesLengthInOneLine: 15,
|
|
36
36
|
maxSpecifiersInOneLine: 2,
|
|
37
37
|
maxElementsInOneLine: 5,
|
|
38
|
+
maxElementLengthInOneLine: 10,
|
|
38
39
|
maxLogicalsInOneLine: 3,
|
|
39
40
|
maxVariablesInOneLine: 4,
|
|
40
41
|
maxTypesInOneLine: 3,
|
package/package.json
CHANGED