@putout/printer 2.1.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,13 @@
1
+ 2023.06.12, v2.3.0
2
+
3
+ feature:
4
+ - 75353e2 @putout/printer: ArrayExpression: maxElementsInOneLine
5
+
6
+ 2023.06.12, v2.2.0
7
+
8
+ feature:
9
+ - 5be9df9 printer: comments
10
+
1
11
  2023.06.12, v2.1.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -104,7 +104,8 @@ write(ast, {
104
104
 
105
105
  ### `format`
106
106
 
107
- With help of `format` you can override next options:
107
+ Options related to visuals and not related to logic of output can be changed with help of `format`,
108
+ you can override next options:
108
109
 
109
110
  ```js
110
111
  const overrides = {
@@ -112,8 +113,9 @@ const overrides = {
112
113
  indent: ' ',
113
114
  newline: '\n',
114
115
  space: ' ',
115
- comments: true,
116
116
  splitter: '\n',
117
+ roundBraceOpen: '(',
118
+ roundBraceClose: ')',
117
119
  },
118
120
  };
119
121
  ```
@@ -121,8 +123,8 @@ const overrides = {
121
123
  - `indent` - use two spaces, tabs, or anything you want;
122
124
  - `newline` - symbol for used for line separation;
123
125
  - `space` - default symbol used for space character;
124
- - `comments` - produce comments in output or skip them;
125
126
  - `splitter` - mandatory symbol that used inside of statements like this:
127
+ - `roundBraceOpen` and `roundBraceClose` symbols to to output braces in a single argument arrow function expressions: `(a) => {}`.
126
128
 
127
129
  Default options produce:
128
130
 
@@ -148,12 +150,15 @@ const overrides = {
148
150
 
149
151
  And have minified code:
150
152
 
151
- ```js
152
- if (a > 3)
153
- console.log('ok');
154
- else
155
- console.log('not ok');
156
153
  ```
154
+ if(a>3)console.log('ok');else console.log('not ok');
155
+ ```
156
+
157
+ ### Semantics
158
+
159
+ Options used to configure logic of output, similar to ESLint rules:
160
+
161
+ - `maxElementsInOneLine` - count of `ArrayExpression` and `ArrayPattern` elements placed in one line.
157
162
 
158
163
  ### `write`
159
164
 
@@ -104,7 +104,7 @@ module.exports.parseComments = (path, {write}, semantics) => {
104
104
  };
105
105
 
106
106
  function isSameLine(path, loc) {
107
- return path.node.loc.start.line === loc.start.line;
107
+ return path.node.loc.start.line === loc.start.line || path.node.loc.end.line === loc.end.line;
108
108
  }
109
109
 
110
110
  function maybeInsideFn(insideFn, {print, indent}) {
@@ -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.1.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",