Skip to content

Commit 0dc30a8

Browse files
committed
feature: @putout/plugin-putout: convert-push-object-to-push-path: multiple fix
1 parent 0eed296 commit 0dc30a8

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports.fix = ({path, from, to, toRename}) => {
2+
if (isImportSpecifier(path)) {
3+
path.node.imported = path.node.local;
4+
return;
5+
}
6+
7+
if (toRename)
8+
rename(path, from, to);
9+
10+
path.node.shorthand = true;
11+
};
12+
13+
module.exports.traverse = ({push, options}) => ({
14+
ImportSpecifier(path) {
15+
if (path.node.imported.value === path.node.local.name)
16+
push({
17+
path,
18+
});
19+
},
20+
});

packages/plugin-putout/lib/convert-push-object-to-push-path/fixture/multiple.js renamed to packages/plugin-putout/lib/convert-push-object-to-push-path/fixture/multiple-push.js

File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const fix = ({path}) => {
2+
removeClassName(path, 'menu-item-selected');
3+
};
4+
5+
export const traverse = ({push}) => ({
6+
JSXElement(path) {
7+
push(path);
8+
},
9+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const fix = ({path}) => {
2+
removeClassName(path, 'menu-item-selected');
3+
};
4+
5+
export const traverse = ({push}) => ({
6+
JSXElement(path) {
7+
push({
8+
path,
9+
});
10+
},
11+
});
12+

packages/plugin-putout/lib/convert-push-object-to-push-path/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ const {traverse} = operator;
55
export const report = () => `Use 'push(__a)' instead of 'push({path: __a})'`;
66

77
export const match = () => ({
8+
'push({path})': (vars, path) => {
9+
let is = false;
10+
const programPath = path.scope.getProgramParent().path;
11+
12+
traverse(programPath, {
13+
'export const fix = ({path}) => __body': () => {
14+
is = true;
15+
},
16+
});
17+
18+
return is;
19+
},
820
'export const fix = ({path}) => __a': (vars, {parentPath}) => {
921
let is = false;
1022

@@ -20,5 +32,6 @@ export const match = () => ({
2032

2133
export const replace = () => ({
2234
'push({path: __a})': 'push(__a)',
35+
'push({path})': 'push(path)',
2336
'export const fix = ({path}) => __a': 'export const fix = (path) => __a',
2437
});

packages/plugin-putout/lib/convert-push-object-to-push-path/index.spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ test('putout: convert-push-object-to-push-path: transform', (t) => {
1717
t.end();
1818
});
1919

20-
test('putout: convert-push-object-to-push-path: no report: multiple', (t) => {
21-
t.noReport('multiple');
20+
test('putout: convert-push-object-to-push-path: no report: multiple-push', (t) => {
21+
t.noReport('multiple-push');
22+
t.end();
23+
});
24+
25+
test('putout: convert-push-object-to-push-path: no report: multiple-fix', (t) => {
26+
t.noReport('multiple-fix');
27+
t.end();
28+
});
29+
30+
test('putout: convert-push-object-to-push-path: transform: no-rename', (t) => {
31+
t.transform('no-rename');
2232
t.end();
2333
});

0 commit comments

Comments
 (0)