forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
104 lines (100 loc) · 3.08 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const _ = require('lodash');
const { flagErrors } = require('./validateImports.js');
const noGlobal = require('eslint/lib/rules/no-restricted-globals.js');
function getName(node) {
return node.type === 'Literal' ? node.value : node.name;
}
module.exports = {
rules: {
'validate-imports': {
meta: {
docs: {
description: 'validates module imports can be found without custom webpack resolvers, are in module whitelist, and not module entry points'
}
},
create: function(context) {
return {
"CallExpression[callee.name='require']"(node) {
let importPath = _.get(node, ['arguments', 0, 'value']);
if (importPath) {
flagErrors(context, node, importPath);
}
},
ImportDeclaration(node) {
let importPath = node.source.value.trim();
flagErrors(context, node, importPath);
},
'ExportNamedDeclaration[source]'(node) {
let importPath = node.source.value.trim();
flagErrors(context, node, importPath);
}
};
}
},
'no-member': {
meta: {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
target: { type: 'string' },
name: { type: 'string' },
message: { type: 'string' }
},
required: ['name', 'message'],
additionalProperties: false
},
uniqueItems: true,
minItems: 1
},
messages: {
noMember: "Unexpected use of '{{target}}.{{name}}'. {{message}}",
}
},
create(context) {
return {
MemberExpression(node) {
context.options.forEach(({name, target, message}) => {
if (target === node.object.name && getName(node.property) === name) {
context.report({
node,
messageId: 'noMember',
data: {
name,
target: target || '',
message
}
});
}
});
}
}
}
},
'no-global': Object.assign({}, noGlobal, {
// no-restricted-global that also looks for `window.GLOBAL`
create(context) {
const globals = Object.fromEntries(
context.options.map(option => typeof option === 'string' ? [option, null] : [option.name, option.message])
)
return Object.assign(noGlobal.create(context), {
MemberExpression(node) {
const name = getName(node.property);
if (node.object.name === 'window' && globals.hasOwnProperty(name)) {
const customMessage = globals[name];
context.report({
node,
messageId: customMessage == null ? 'defaultMessage' : 'customMessage',
data: {
name,
customMessage
}
})
}
}
})
}
}),
}
};