Skip to content

Commit 92632bc

Browse files
committed
feature: anuma: convert to ast-grep format
1 parent 200cc5e commit 92632bc

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/split-plugins.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,25 @@ function parsePatterns(rule, plugin) {
4848
if (isFn(to))
4949
return [false];
5050

51-
result.patterns.push([from, to]);
51+
const newFrom = replaceTemplateValues(from);
52+
const newTo = replaceTemplateValues(to);
53+
54+
result.patterns.push([newFrom, newTo]);
5255
}
5356

5457
return [true, result];
5558
}
59+
60+
function replaceTemplateValues(template) {
61+
const match = template.match(/__[a-z]/g);
62+
63+
if (!match)
64+
return template;
65+
66+
for (const current of match) {
67+
const name = `$${current.at(-1).toUpperCase()}`;
68+
template = template.replaceAll(current, name);
69+
}
70+
71+
return template;
72+
}

lib/split-plugins.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ test('anuma: splitPlugins: report with args', (t) => {
5252
const expected = [{
5353
message: `Use 't.match()' instead of 't.ok()'`,
5454
patterns: [
55-
['t.ok(__a.includes(__b))', 't.match(__a, __b)'],
56-
['t.ok(__a.includes(__b), __c)', 't.match(__a, __b, __c)'],
57-
['t.ok(__a.test(__b))', 't.match(__b, __a)'],
58-
['t.ok(__a.test(__b), __c)', 't.match(__b, __a, __c)'],
55+
['t.ok($A.includes($B))', 't.match($A, $B)'],
56+
['t.ok($A.includes($B), $C)', 't.match($A, $B, $C)'],
57+
['t.ok($A.test($B))', 't.match($B, $A)'],
58+
['t.ok($A.test($B), $C)', 't.match($B, $A, $C)'],
5959
],
6060
rule: 'tape/convert-ok-to-match',
6161
}, {

0 commit comments

Comments
 (0)