Skip to content

Commit 03c944e

Browse files
committed
feature: @putout/plugin-putout: apply-transform-with-options: add
1 parent 586c8f3 commit 03c944e

File tree

9 files changed

+119
-0
lines changed

9 files changed

+119
-0
lines changed

packages/plugin-putout/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ npm i @putout/plugin-putout -D
4141
-[apply-rename](#apply-rename);
4242
-[apply-parens](#apply-parens);
4343
-[apply-short-processors](#apply-short-processors);
44+
-[apply-transform-with-options](#apply-transform-with-options);
4445
-[check-match](#check-match);
4546
-[check-declare](#check-declare);
4647
-[check-replace-code](#check-replace-code);
@@ -109,6 +110,7 @@ npm i @putout/plugin-putout -D
109110
"putout/apply-rename": "on",
110111
"putout/apply-parens": "on",
111112
"putout/apply-remove": "on",
113+
"putout/apply-transform-with-options": "on",
112114
"putout/apply-insert-before": "on",
113115
"putout/apply-insert-after": "on",
114116
"putout/apply-vars": "on",
@@ -210,6 +212,28 @@ t.report('a', 'Use b');
210212
t.noReport('a');
211213
```
212214

215+
## apply-transform-with-options
216+
217+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/92d40d40c75481816a5b5507e01d8315/bb54e932b4fff4bc0b453d723c72c7a9ed796b98).
218+
219+
### ❌ Example of incorrect code
220+
221+
```js
222+
t.transform('submenu', {
223+
submenuIndex: 1,
224+
insideSubmenu: true,
225+
});
226+
```
227+
228+
### ✅ Example of correct code
229+
230+
```js
231+
t.transformWithOptions('submenu', {
232+
submenuIndex: 1,
233+
insideSubmenu: true,
234+
});
235+
```
236+
213237
## apply-processors-destructuring
214238

215239
### ❌ Example of incorrect code
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
t.transformWithOptions('submenu', {
2+
submenuIndex: 1,
3+
insideSubmenu: true,
4+
});
5+
6+
t.transform('submenu', {
7+
submenuIndex,
8+
insideSubmenu,
9+
});
10+
11+
t.transform('submenu', {});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
t.transform('submenu', {
2+
submenuIndex: 1,
3+
insideSubmenu: true,
4+
});
5+
6+
t.transform('submenu', {
7+
submenuIndex,
8+
insideSubmenu,
9+
});
10+
11+
t.transform('submenu', {});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {types} from 'putout';
2+
3+
const {
4+
isLiteral,
5+
isObjectExpression,
6+
} = types;
7+
8+
export const report = () => `Use 'transformWithOptions()' instead of 'transform()'`;
9+
10+
export const match = () => ({
11+
't.transform(__a, __b)': ({__b}) => {
12+
if (!isObjectExpression(__b))
13+
return false;
14+
15+
if (!__b.properties.length)
16+
return false;
17+
18+
const [first] = __b.properties;
19+
20+
return isLiteral(first.value);
21+
},
22+
});
23+
24+
export const replace = () => ({
25+
't.transform(__a, __b)': 't.transformWithOptions(__a, __b)',
26+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
3+
4+
const test = createTest(import.meta.url, {
5+
plugins: [
6+
['apply-transform-with-options', plugin],
7+
],
8+
});
9+
10+
test('putout: apply-transform-with-options: report', (t) => {
11+
t.report('apply-transform-with-options', `Use 'transformWithOptions()' instead of 'transform()'`);
12+
t.end();
13+
});
14+
15+
test('putout: apply-transform-with-options: transform', (t) => {
16+
t.transform('apply-transform-with-options');
17+
t.end();
18+
});

packages/plugin-putout/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as applyTransformWithOptions from './apply-transform-with-options/index.js';
12
import * as convertPluginsElementToTuple from './convert-plugins-element-to-tuple/index.js';
23
import * as removeEmptyObjectFromTransform from './remove-empty-object-from-transform/index.js';
34
import * as applyExports from './apply-exports/index.js';
@@ -140,4 +141,5 @@ export const rules = {
140141
'apply-exports': ['off', applyExports],
141142
'remove-empty-object-from-transform': removeEmptyObjectFromTransform,
142143
'convert-plugins-element-to-tuple': convertPluginsElementToTuple,
144+
'apply-transform-with-options': applyTransformWithOptions,
143145
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
t.transformWithOptions('submenu', {
2+
submenuIndex: 1,
3+
insideSubmenu: true,
4+
});
5+
6+
t.transform('submenu', {
7+
submenuIndex,
8+
insideSubmenu,
9+
});
10+
11+
t.transform('submenu', {});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
t.transform('submenu', {
2+
submenuIndex: 1,
3+
insideSubmenu: true,
4+
});
5+
6+
t.transform('submenu', {
7+
submenuIndex,
8+
insideSubmenu,
9+
});
10+
11+
t.transform('submenu', {});

packages/plugin-putout/test/putout.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,8 @@ test('plugin-putout: transform: convert-plugins-element-to-tuple', (t) => {
344344
t.transform('convert-plugins-element-to-tuple');
345345
t.end();
346346
});
347+
348+
test('plugin-putout: transform: apply-transform-with-options', (t) => {
349+
t.transform('apply-transform-with-options');
350+
t.end();
351+
});

0 commit comments

Comments
 (0)