Skip to content

Commit d857439

Browse files
committed
feature: @putout/plugin-putout: add-traverse-args: convert-traverse-to-scan
1 parent 07a5e36 commit d857439

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const FS = '__putout_processor_filesystem(__object)';
2+
3+
export const report = () => `Remove vim swap file`;
4+
5+
export const fix = (filePath) => {
6+
removeFile(filePath);
7+
};
8+
9+
export const traverse = (path, {push}) => {
10+
findFile(path, '*.swp').map(push);
11+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const FS = '__putout_processor_filesystem(__object)';
2+
3+
export const report = () => `Remove vim swap file`;
4+
5+
export const fix = (filePath) => {
6+
removeFile(filePath);
7+
};
8+
9+
export const traverse = ({push}) => ({
10+
[FS](path) {
11+
findFile(path, '*.swp').map(push);
12+
}
13+
});

packages/plugin-putout/lib/add-traverse-args/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
objectPattern,
66
objectProperty,
77
identifier,
8+
isObjectPattern,
89
} = types;
910

1011
const {traverse, getBinding} = operator;
@@ -50,7 +51,12 @@ const isArgExists = (mainName, fn) => {
5051
if (!fn.params.length)
5152
return false;
5253

53-
for (const prop of fn.params[0].properties) {
54+
const [first] = fn.params;
55+
56+
if (!isObjectPattern(first))
57+
return false;
58+
59+
for (const prop of first.properties) {
5460
if (prop.key.name === mainName)
5561
return true;
5662
}

packages/plugin-putout/lib/add-traverse-args/index.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const {createTest} = require('@putout/test');
44
const addPush = require('.');
5+
const putout = require('..');
6+
const convertTraverseToScan = putout.rules['convert-traverse-to-scan'];
57

68
const test = createTest(__dirname, {
79
plugins: [
@@ -63,3 +65,10 @@ test('plugin-putout: add-traverse-args: no report: options-declared-upper', (t)
6365
t.noReport('options-declared-upper');
6466
t.end();
6567
});
68+
69+
test('plugin-putout: add-traverse-args: report: convert-traverse-to-scan', (t) => {
70+
t.transform('convert-traverse-to-scan', {
71+
'convert-traverse-to-scan': convertTraverseToScan,
72+
});
73+
t.end();
74+
});

0 commit comments

Comments
 (0)