@putout/printer 6.11.1 → 6.11.2
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
|
@@ -5,7 +5,6 @@ const {
|
|
|
5
5
|
isStringAndIdentifier,
|
|
6
6
|
isIdentifierAndIdentifier,
|
|
7
7
|
isStringAndArray,
|
|
8
|
-
isIndented,
|
|
9
8
|
} = require('../../is');
|
|
10
9
|
|
|
11
10
|
const {
|
|
@@ -15,31 +14,18 @@ const {
|
|
|
15
14
|
} = require('./newline');
|
|
16
15
|
|
|
17
16
|
const {types} = require('@putout/babel');
|
|
17
|
+
|
|
18
18
|
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
isInsideArray,
|
|
20
|
+
isArrayInsideArray,
|
|
21
|
+
isArrayIndented,
|
|
22
|
+
} = require('./indent');
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
+
const {isObjectExpression} = types;
|
|
24
25
|
|
|
25
|
-
const
|
|
26
|
-
if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
|
|
27
|
-
return false;
|
|
28
|
-
|
|
29
|
-
return path.parentPath.node.elements.length <= 3;
|
|
30
|
-
};
|
|
26
|
+
const isNextObject = (a) => a.getNextSibling().isObjectExpression();
|
|
31
27
|
|
|
32
28
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
33
|
-
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
34
|
-
|
|
35
|
-
const isTwoLongStrings = ([a, b]) => {
|
|
36
|
-
const LONG_STRING = 20;
|
|
37
|
-
|
|
38
|
-
if (!isStringLiteral(a) || !isStringLiteral(b))
|
|
39
|
-
return false;
|
|
40
|
-
|
|
41
|
-
return a.node.value.length > LONG_STRING;
|
|
42
|
-
};
|
|
43
29
|
|
|
44
30
|
module.exports.ArrayExpression = {
|
|
45
31
|
beforeIf(path) {
|
|
@@ -71,7 +57,7 @@ module.exports.ArrayExpression = {
|
|
|
71
57
|
|
|
72
58
|
print('[');
|
|
73
59
|
|
|
74
|
-
const indented =
|
|
60
|
+
const indented = isArrayIndented(path);
|
|
75
61
|
|
|
76
62
|
if (indented)
|
|
77
63
|
maybe.indent.inc(shouldIncreaseIndent);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
const {isStringLiteral} = types;
|
|
5
|
+
|
|
6
|
+
const {isIndented} = require('../../is');
|
|
7
|
+
|
|
8
|
+
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
9
|
+
|
|
10
|
+
module.exports.isInsideArray = isInsideArray;
|
|
11
|
+
|
|
12
|
+
module.exports.isArrayIndented = (path) => {
|
|
13
|
+
const elements = path.get('elements');
|
|
14
|
+
|
|
15
|
+
if (isArrayInsideArray(path))
|
|
16
|
+
return false;
|
|
17
|
+
|
|
18
|
+
const [first] = elements;
|
|
19
|
+
|
|
20
|
+
return !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(first);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports.isArrayInsideArray = isArrayInsideArray;
|
|
24
|
+
|
|
25
|
+
function isArrayInsideArray(path) {
|
|
26
|
+
if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
|
|
27
|
+
return false;
|
|
28
|
+
|
|
29
|
+
return path.parentPath.node.elements.length <= 3;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const isTwoLongStrings = ([a, b]) => {
|
|
33
|
+
const LONG_STRING = 20;
|
|
34
|
+
|
|
35
|
+
if (!isStringLiteral(a) || !isStringLiteral(b))
|
|
36
|
+
return false;
|
|
37
|
+
|
|
38
|
+
return a.node.value.length > LONG_STRING;
|
|
39
|
+
};
|
package/package.json
CHANGED