@putout/printer 2.2.0 → 2.3.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,8 @@
1
+ 2023.06.12, v2.3.0
2
+
3
+ feature:
4
+ - 75353e2 @putout/printer: ArrayExpression: maxElementsInOneLine
5
+
1
6
  2023.06.12, v2.2.0
2
7
 
3
8
  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
- ```js
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, MAX_ARRAY_ELEMENTS_WHEN_USED_AS_ARGUMENT))
290
+ if (isShortTwoSimplesInsideCall(path, maxElementsInOneLine))
291
291
  return false;
292
292
 
293
293
  if (isTwoStringsDifferentLength(elements))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",