@putout/printer 2.2.0 → 2.4.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,13 @@
|
|
|
1
|
+
2023.06.12, v2.4.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 1aa1e9e @putout/printer: ObjectExpression: improve support of using as not last argument of CallExpression
|
|
5
|
+
|
|
6
|
+
2023.06.12, v2.3.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 75353e2 @putout/printer: ArrayExpression: maxElementsInOneLine
|
|
10
|
+
|
|
1
11
|
2023.06.12, v2.2.0
|
|
2
12
|
|
|
3
13
|
feature:
|
package/README.md
CHANGED
|
@@ -158,8 +158,7 @@ if(a>3)console.log('ok');else console.log('not ok');
|
|
|
158
158
|
|
|
159
159
|
Options used to configure logic of output, similar to ESLint rules:
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
```
|
|
161
|
+
- `maxElementsInOneLine` - count of `ArrayExpression` and `ArrayPattern` elements placed in one line.
|
|
163
162
|
|
|
164
163
|
### `write`
|
|
165
164
|
|
|
@@ -23,8 +23,6 @@ const {
|
|
|
23
23
|
isStringAndMember,
|
|
24
24
|
} = require('../../is');
|
|
25
25
|
|
|
26
|
-
const MAX_ARRAY_ELEMENTS_WHEN_USED_AS_ARGUMENT = 4;
|
|
27
|
-
|
|
28
26
|
const isForOf = ({parentPath}) => parentPath.isForOfStatement();
|
|
29
27
|
|
|
30
28
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
@@ -112,7 +110,8 @@ module.exports.ArrayExpression = {
|
|
|
112
110
|
before(path, {print}) {
|
|
113
111
|
print.breakline();
|
|
114
112
|
},
|
|
115
|
-
print(path, {print, maybe, indent}) {
|
|
113
|
+
print(path, {print, maybe, indent}, semantics) {
|
|
114
|
+
const {maxElementsInOneLine} = semantics;
|
|
116
115
|
const elements = path.get('elements');
|
|
117
116
|
const shouldIncreaseIndent = !isIncreaseIndent(path);
|
|
118
117
|
|
|
@@ -123,6 +122,7 @@ module.exports.ArrayExpression = {
|
|
|
123
122
|
|
|
124
123
|
const isNewLine = isNewlineBetweenElements(path, {
|
|
125
124
|
elements,
|
|
125
|
+
maxElementsInOneLine,
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
const n = elements.length - 1;
|
|
@@ -256,7 +256,7 @@ function isOneSimple(path) {
|
|
|
256
256
|
return first.isMemberExpression();
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
function isNewlineBetweenElements(path, {elements}) {
|
|
259
|
+
function isNewlineBetweenElements(path, {elements, maxElementsInOneLine}) {
|
|
260
260
|
if (elements.length > 3 && !isObjectExpression(elements[0]))
|
|
261
261
|
return true;
|
|
262
262
|
|
|
@@ -287,7 +287,7 @@ function isNewlineBetweenElements(path, {elements}) {
|
|
|
287
287
|
if (isSimpleAndCall(elements))
|
|
288
288
|
return false;
|
|
289
289
|
|
|
290
|
-
if (isShortTwoSimplesInsideCall(path,
|
|
290
|
+
if (isShortTwoSimplesInsideCall(path, maxElementsInOneLine))
|
|
291
291
|
return false;
|
|
292
292
|
|
|
293
293
|
if (isTwoStringsDifferentLength(elements))
|
|
@@ -79,6 +79,17 @@ const hasNextLeadingComment = (path) => {
|
|
|
79
79
|
return hasLeadingComment(next);
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
const notLastArgInsideCall = (path) => {
|
|
83
|
+
const {parentPath} = path;
|
|
84
|
+
|
|
85
|
+
if (!parentPath.isCallExpression())
|
|
86
|
+
return false;
|
|
87
|
+
|
|
88
|
+
return path !== parentPath
|
|
89
|
+
.get('arguments')
|
|
90
|
+
.at(-1);
|
|
91
|
+
};
|
|
92
|
+
|
|
82
93
|
function shouldAddNewline(path) {
|
|
83
94
|
if (!path.parentPath.isLogicalExpression())
|
|
84
95
|
return false;
|
|
@@ -96,6 +107,9 @@ function isOneLine(path) {
|
|
|
96
107
|
if (!length)
|
|
97
108
|
return true;
|
|
98
109
|
|
|
110
|
+
if (notLastArgInsideCall(path))
|
|
111
|
+
return ONE_LINE;
|
|
112
|
+
|
|
99
113
|
if (isForOf(path))
|
|
100
114
|
return ONE_LINE;
|
|
101
115
|
|
package/package.json
CHANGED