-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathno-amd-name.js
43 lines (37 loc) · 1.03 KB
/
no-amd-name.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 Enforce no naming of AMD modules
* @author Adam Davies
*/
'use strict';
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'suggestion',
messages: {
noModuleName: 'No AMD module name should be provided',
},
fixable: 'code',
},
create: function (context) {
return {
'CallExpression[callee.name=define]': function (node) {
if (node.arguments.length !== 3) {
return;
}
const arg1 = node.arguments[0];
const arg2 = node.arguments[1];
if (arg1 && arg1.type === 'Literal' && typeof arg1.value === 'string') {
context.report({
node: arg1,
messageId: 'noModuleName',
fix: function (fixer) {
return fixer.replaceTextRange([arg1.range[0], arg2.range[0]], '');
},
});
}
},
};
},
};