-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
modify-ast-at-first.js
44 lines (40 loc) · 1.13 KB
/
modify-ast-at-first.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
/**
* @fileoverview Rule which modifies AST.
* @author Toru Nagashima
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "problem",
schema: []
},
create(context) {
return {
"Program": function(node) {
node.body.push({
"type": "Identifier",
"name": "modified",
"range": [0, 8],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
}
});
},
"Identifier": function(node) {
if (node.name === "bar") {
context.report({message: "error", node: node});
}
}
};
},
};