/
no-amd.js
43 lines (33 loc) · 1.09 KB
/
no-amd.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
/**
* @fileoverview Rule to prefer imports to AMD
* @author Jamund Ferguson
*/
import docsUrl from '../docsUrl'
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: docsUrl('no-amd'),
},
schema: [],
},
create: function (context) {
return {
'CallExpression': function (node) {
if (context.getScope().type !== 'module') return
if (node.callee.type !== 'Identifier') return
if (node.callee.name !== 'require' &&
node.callee.name !== 'define') return
// todo: capture define((require, module, exports) => {}) form?
if (node.arguments.length !== 2) return
const modules = node.arguments[0]
if (modules.type !== 'ArrayExpression') return
// todo: check second arg type? (identifier or callback)
context.report(node, `Expected imports instead of AMD ${node.callee.name}().`)
},
}
},
}