@putout/plugin-putout 26.3.1 → 26.4.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 +24 -0
- package/lib/convert-plugins-element-to-tuple/index.js +42 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ npm i @putout/plugin-putout -D
|
|
|
57
57
|
- ✅ [convert-process-to-find](#convert-process-to-find);
|
|
58
58
|
- ✅ [convert-progress-to-track-file](#convert-progress-to-track-file);
|
|
59
59
|
- ✅ [convert-putout-test-to-create-test](#convert-putout-test-to-create-test);
|
|
60
|
+
- ✅ [convert-plugins-element-to-tuple](#convert-plugins-element-to-tuple);
|
|
60
61
|
- ✅ [convert-replace-to-function](#convert-replace-to-function);
|
|
61
62
|
- ✅ [convert-replace-with](#convert-replace-with);
|
|
62
63
|
- ✅ [convert-replace-with-multiple](#convert-replace-with-multiple);
|
|
@@ -143,6 +144,7 @@ npm i @putout/plugin-putout -D
|
|
|
143
144
|
"putout/convert-report-to-function": "on",
|
|
144
145
|
"putout/convert-get-rule-to-require": "on",
|
|
145
146
|
"putout/convert-progress-to-track-file": "on",
|
|
147
|
+
"putout/convert-plugins-element-to-tuple": "on",
|
|
146
148
|
"putout/create-test": "on",
|
|
147
149
|
"putout/shorten-imports": "on",
|
|
148
150
|
"putout/declare": "on",
|
|
@@ -761,6 +763,28 @@ const test = createTest(__dirname, {
|
|
|
761
763
|
});
|
|
762
764
|
```
|
|
763
765
|
|
|
766
|
+
## convert-plugins-element-to-tuple
|
|
767
|
+
|
|
768
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/abcc9f79469db69849b6d6efd3e85a8a/0536c9f780a0c9db2feed3be92299a22f06b9720).
|
|
769
|
+
|
|
770
|
+
### ❌ Example of incorrect code
|
|
771
|
+
|
|
772
|
+
```js
|
|
773
|
+
t.transform('nested-not-block', [
|
|
774
|
+
['convert-if-to-jmp', convertIfToJmp],
|
|
775
|
+
convertDoWhileToJnz,
|
|
776
|
+
]);
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
### ✅ Example of correct code
|
|
780
|
+
|
|
781
|
+
```js
|
|
782
|
+
t.transform('nested-not-block', [
|
|
783
|
+
['convert-if-to-jmp', convertIfToJmp],
|
|
784
|
+
['convert-do-while-to-jnz', convertDoWhileToJnz],
|
|
785
|
+
]);
|
|
786
|
+
```
|
|
787
|
+
|
|
764
788
|
## convert-to-no-transform-code
|
|
765
789
|
|
|
766
790
|
### ❌ Example of incorrect code
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
import toKebabCase from 'just-kebab-case';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
isIdentifier,
|
|
6
|
+
isArrayExpression,
|
|
7
|
+
stringLiteral,
|
|
8
|
+
arrayExpression,
|
|
9
|
+
} = types;
|
|
10
|
+
|
|
11
|
+
const {replaceWith} = operator;
|
|
12
|
+
|
|
13
|
+
export const report = () => `Use 'tuple' instead of 'element'`;
|
|
14
|
+
|
|
15
|
+
export const fix = (path) => {
|
|
16
|
+
const {node} = path;
|
|
17
|
+
const name = toKebabCase(node.name);
|
|
18
|
+
|
|
19
|
+
replaceWith(path, arrayExpression([
|
|
20
|
+
stringLiteral(name),
|
|
21
|
+
node,
|
|
22
|
+
]));
|
|
23
|
+
};
|
|
24
|
+
export const traverse = ({push}) => ({
|
|
25
|
+
't.__a(__b, __array)': (path) => {
|
|
26
|
+
const array = path.get('arguments.1.elements');
|
|
27
|
+
const hasTuple = array.filter(isArrayExpression).length;
|
|
28
|
+
|
|
29
|
+
if (!hasTuple)
|
|
30
|
+
return;
|
|
31
|
+
|
|
32
|
+
for (const element of array) {
|
|
33
|
+
if (isArrayExpression(element))
|
|
34
|
+
continue;
|
|
35
|
+
|
|
36
|
+
if (!isIdentifier(element))
|
|
37
|
+
continue;
|
|
38
|
+
|
|
39
|
+
push(element);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as convertPluginsElementToTuple from './convert-plugins-element-to-tuple/index.js';
|
|
1
2
|
import * as removeEmptyObjectFromTransform from './remove-empty-object-from-transform/index.js';
|
|
2
3
|
import * as applyExports from './apply-exports/index.js';
|
|
3
4
|
import * as applyExportsToRenameFiles from './apply-exports-to-rename-files/index.js';
|
|
@@ -138,4 +139,5 @@ export const rules = {
|
|
|
138
139
|
'apply-exports-to-rename-files': applyExportsToRenameFiles,
|
|
139
140
|
'apply-exports': ['off', applyExports],
|
|
140
141
|
'remove-empty-object-from-transform': removeEmptyObjectFromTransform,
|
|
142
|
+
'convert-plugins-element-to-tuple': convertPluginsElementToTuple,
|
|
141
143
|
};
|
package/package.json
CHANGED