putout 32.6.0 → 32.8.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,19 @@
1
+ 2023.10.28, v32.8.0
2
+
3
+ feature:
4
+ - f23dbbe95 putout: printer: improve support of JSON
5
+ - 61e6bedef putout: printer: improve support of JSON and JSON in Markdown without ESLint
6
+
7
+ 2023.10.28, v32.7.0
8
+
9
+ feature:
10
+ - ca284d35c package: @putout/plugin-logical-expressions v5.0.0
11
+ - ad44b4283 @putout/plugin-logical-expressions: drop support of 🐊 < 32
12
+ - ecd39020e putout: printer: add ability to handle endOfFile in markdown listings without ESLint
13
+ - 7587c2c4c package: @putout/plugin-regexp v8.0.0
14
+ - a4110ac0c @putout/plugin-regexp: drop support of 🐊 < 32
15
+ - 798576371 package: @putout/printer v6.0.0
16
+
1
17
  2023.10.28, v32.6.0
2
18
 
3
19
  fix:
@@ -0,0 +1,50 @@
1
+ const {isArray} = Array;
2
+ const maybeArray = (a) => isArray(a) ? a : [a];
3
+
4
+ const DefaultMarkdown = {
5
+ format: {
6
+ endOfFile: '',
7
+ },
8
+ };
9
+
10
+ const JSON = {
11
+ format: {
12
+ quote: '"',
13
+ },
14
+ semantics: {
15
+ trailingComma: false,
16
+ },
17
+ };
18
+
19
+ export const configurePrinter = (name, printerOptions) => {
20
+ const [printer = 'putout', options = {}] = maybeArray(printerOptions);
21
+ const ext = name
22
+ .split('.')
23
+ .pop();
24
+
25
+ if (printer !== 'putout')
26
+ return printerOptions;
27
+
28
+ if (ext === 'json')
29
+ return [printer, JSON];
30
+
31
+ if (ext === 'md{json}')
32
+ return [printer, {
33
+ format: {
34
+ ...DefaultMarkdown.format,
35
+ ...JSON.format,
36
+ },
37
+ semantics: {
38
+ ...DefaultMarkdown.semantics,
39
+ ...JSON.semantics,
40
+ },
41
+ }];
42
+
43
+ if (ext === 'md{js}')
44
+ return [printer, DefaultMarkdown];
45
+
46
+ if (ext === 'md{ts}')
47
+ return [printer, DefaultMarkdown];
48
+
49
+ return [printer, options];
50
+ };
@@ -17,6 +17,7 @@ const getMatchedOptions = (name, options) => {
17
17
  };
18
18
 
19
19
  module.exports = ({fix, fixCount, isFlow, logError, raw, printer}) => async ({name, source, startLine, options}) => {
20
+ const {configurePrinter} = await import('./printer/printer.mjs');
20
21
  const isTS = /\.tsx?$/.test(name) || /{tsx?}$/.test(name);
21
22
  const matchedOptions = getMatchedOptions(name, options);
22
23
 
@@ -25,8 +26,8 @@ module.exports = ({fix, fixCount, isFlow, logError, raw, printer}) => async ({na
25
26
  fixCount,
26
27
  isTS,
27
28
  isFlow,
28
- printer,
29
29
  ...matchedOptions,
30
+ printer: configurePrinter(name, printer),
30
31
  });
31
32
 
32
33
  if (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "32.6.0",
3
+ "version": "32.8.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json",
@@ -105,7 +105,7 @@
105
105
  "@putout/plugin-for-of": "^3.0.0",
106
106
  "@putout/plugin-github": "^9.0.0",
107
107
  "@putout/plugin-gitignore": "^3.0.0",
108
- "@putout/plugin-logical-expressions": "^4.0.0",
108
+ "@putout/plugin-logical-expressions": "^5.0.0",
109
109
  "@putout/plugin-madrun": "^17.0.0",
110
110
  "@putout/plugin-math": "^2.0.0",
111
111
  "@putout/plugin-maybe": "^1.0.0",