@putout/plugin-putout 16.1.0 β†’ 16.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/README.md CHANGED
@@ -24,6 +24,7 @@ npm i @putout/plugin-putout -D
24
24
  "putout/apply-remove": "on",
25
25
  "putout/apply-insert-before": "on",
26
26
  "putout/apply-insert-after": "on",
27
+ "putout/apply-short-processors": "on",
27
28
  "putout/apply-namaspace-specifier": "on",
28
29
  "putout/add-args": "on",
29
30
  "putout/add-push": "on",
@@ -77,6 +78,36 @@ test('', async ({process}) => {
77
78
  });
78
79
  ```
79
80
 
81
+ ## apply-short-processors
82
+
83
+ Apply short names of processors, for example `__json` instead of `__putout_processor_json` . Checkout out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/908151edd3ee8d6a07d589df1e863883/1bd1eeadadea40915a2079f33a3845fa4fedda8e).
84
+
85
+ ### ❌ Example of incorrect code
86
+
87
+ ```js
88
+ export const match = () => ({
89
+ '__putout_processor_ignore(__a)': ({__a}) => {
90
+ const list = __a.elements.map(getValue);
91
+ },
92
+ '__putout_processor_filesystem(__a)': ({__a}) => {
93
+ const list = __a.elements.map(getValue);
94
+ },
95
+ });
96
+ ```
97
+
98
+ ### βœ… Example of correct code
99
+
100
+ ```js
101
+ export const match = () => ({
102
+ [__ignore]: ({__array}) => {
103
+ const list = __array.elements.map(getValue);
104
+ },
105
+ [__filesystem]: ({__object}) => {
106
+ const list = __object.elements.map(getValue);
107
+ },
108
+ });
109
+ ```
110
+
80
111
  ## apply-rename
81
112
 
82
113
  Better use [`rename(path, from, to)`](https://github.com/coderaiser/putout/tree/master/packages/operate#rename) method of `operator`.
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const {types, operator} = require('putout');
4
+
5
+ const {compute, rename} = operator;
6
+
7
+ const {Identifier} = types;
8
+ const chooseType = (a) => a === '__ignore' ? '__array' : '__object';
9
+
10
+ const getShortName = (a) => {
11
+ return a
12
+ .slice(0, a.indexOf('('))
13
+ .replace('putout_processor_', '');
14
+ };
15
+
16
+ module.exports.report = ({value}) => {
17
+ const name = getShortName(value);
18
+ return `Use '[${name}]' instead of '${value}'`;
19
+ };
20
+
21
+ module.exports.fix = ({path, value}) => {
22
+ const name = getShortName(value);
23
+
24
+ path.node.key = Identifier(name);
25
+ path.node.computed = true;
26
+ rename(path.get('value'), '__a', chooseType(name));
27
+ };
28
+
29
+ module.exports.traverse = ({push}) => ({
30
+ ObjectProperty(path) {
31
+ const [is, value] = compute(path.get('key'));
32
+
33
+ if (!is)
34
+ return;
35
+
36
+ if (!value.includes('__putout_processor'))
37
+ return;
38
+
39
+ push({
40
+ path,
41
+ value,
42
+ });
43
+ },
44
+ });
@@ -5,4 +5,6 @@ module.exports = {
5
5
  fromJS: 'const {fromJS} = operator',
6
6
  __filesystem: 'const {__filesystem} = operator',
7
7
  __json: 'const {__json} = operator',
8
+ __yaml: 'const {__yaml} = operator',
9
+ __ignore: 'const {__ignore} = operator',
8
10
  };
package/lib/index.js CHANGED
@@ -42,6 +42,7 @@ const applyNamaspaceSpecifier = require('./apply-namaspace-specifier');
42
42
  const convertGetRuleToRequire = require('./convert-get-rule-to-require');
43
43
  const addIndexToImport = require('./add-index-to-import');
44
44
  const applyRename = require('./apply-rename');
45
+ const applyShortProcessors = require('./apply-short-processors');
45
46
 
46
47
  module.exports.rules = {
47
48
  'apply-processors-destructuring': applyProcessorsDestructuring,
@@ -86,4 +87,5 @@ module.exports.rules = {
86
87
  'convert-get-rule-to-require': convertGetRuleToRequire,
87
88
  'add-index-to-import': addIndexToImport,
88
89
  'apply-rename': applyRename,
90
+ 'apply-short-processors': applyShortProcessors,
89
91
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "16.1.0",
3
+ "version": "16.3.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",