@putout/plugin-putout 26.3.1 → 26.5.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
@@ -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
@@ -12,6 +12,7 @@ const FIXTURE = [
12
12
 
13
13
  const NAMES = [
14
14
  ...FIXTURE,
15
+ 'transform with options',
15
16
  'no report',
16
17
  'no transform',
17
18
  'no report after transform',
@@ -26,6 +27,7 @@ export const match = () => ({
26
27
  't.report(__a, __b)': check,
27
28
  't.transform(__a)': check,
28
29
  't.transform(__a, __b)': check,
30
+ 't.transformWithOptions(__a, __b)': check,
29
31
  't.noTransform(__a)': check,
30
32
  't.noReportWithOptions(__a, __b)': check,
31
33
  });
@@ -35,6 +37,7 @@ export const replace = () => ({
35
37
  't.report(__a, __b)': transform,
36
38
  't.transform(__a)': transform,
37
39
  't.transform(__a, __b)': transform,
40
+ 't.transformWithOptions(__a, __b)': transform,
38
41
  't.noTransform(__a)': transform,
39
42
  't.noReportAfterTransform(__a)': transform,
40
43
  't.noReportWithOptions(__a, __b)': transform,
@@ -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
  };
@@ -14,6 +14,7 @@ export const fix = ({path, incorrect, correct}) => {
14
14
 
15
15
  const INCORRECT = {
16
16
  TRANSFORM: /: (no report after transform|no transform|report|no report)/,
17
+ TRANSFORM_WITH_OPTIONS: /: (no report after transform|transform|no transform|report|no report)/,
17
18
  NO_TRANSFORM: /: (no report after transform|transform|report|no report)/,
18
19
  REPORT: /: (no report after transform|no report|transform|no transform)/,
19
20
  NO_REPORT: /: (no report after transform|report|transform|no transform)/,
@@ -32,6 +33,11 @@ export const traverse = ({push}) => ({
32
33
  incorrect: INCORRECT.TRANSFORM,
33
34
  correct: ': transform',
34
35
  }),
36
+ 't.transformWithOptions(__a, __b)': convert({
37
+ push,
38
+ incorrect: INCORRECT.TRANSFORM_WITH_OPTIONS,
39
+ correct: ': transform with options',
40
+ }),
35
41
  't.noTransform(__a)': convert({
36
42
  push,
37
43
  incorrect: INCORRECT.NO_TRANSFORM,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "26.3.1",
3
+ "version": "26.5.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",