-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathno-log-module.js
60 lines (51 loc) · 1.56 KB
/
no-log-module.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @fileoverview Restrict loading of the N/log module to favor global Log
* @author Adam Davies
*/
'use strict';
//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
const moduleUtil = require('../util/modules');
const metadataUtil = require('../util/metadata');
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'suggestion',
messages: {
useGlobalLog: 'Use global log instead of the N/log module',
},
schema: [
{
type: 'object',
properties: {
allowInClientScripts: {
type: 'boolean',
},
},
additionalProperties: false,
},
],
},
create: function (context) {
return {
'CallExpression[callee.name=define]': function (node) {
const config = context.options[0] || { allowInClientScripts: true };
const logModule = moduleUtil.getModuleNodePair(node, 'N/log');
const scriptType = metadataUtil.getScriptType(context);
const isClientScript = scriptType && scriptType.value === 'ClientScript';
if (isClientScript && config.allowInClientScripts) {
return;
}
if (logModule) {
context.report({
node: logModule.name,
messageId: 'useGlobalLog',
});
}
},
};
},
};