-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.js
45 lines (33 loc) 路 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
const {
isIdentifier,
Identifier,
} = require('putout').types;
module.exports.report = () => {
return `"noTransformCode" should be called instead of using same arguments twice in "transformCode"`;
};
module.exports.traverse = ({push}) => {
return {
CallExpression(path) {
const calleePath = path.get('callee');
if (!calleePath.isMemberExpression())
return;
const {object, property} = calleePath.node;
if (object.name !== 't' || property.name !== 'transformCode')
return;
const [a, b] = path.node.arguments;
if (!isIdentifier(a) || !isIdentifier(b))
return;
if (a.name !== b.name)
return;
push({
path,
calleePath,
});
},
};
};
module.exports.fix = ({path, calleePath}) => {
calleePath.node.property = Identifier('noTransformCode');
path.node.arguments.pop();
};