-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscript-type.js
53 lines (45 loc) · 1.4 KB
/
script-type.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
/**
* @fileoverview Enforce "@NScriptType" values
* @author Adam Davies
*/
'use strict';
//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
const metadataUtil = require('../util/metadata');
const scriptTypeMap = require('../util/scriptTypes');
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'problem',
messages: {
invalidValue: 'Invalid @NScriptType value: {{ value }}',
noValue: 'No @NScriptType value provided',
},
},
create: function (context) {
return {
Program: function () {
const scriptType = metadataUtil.getScriptType(context);
const scriptTypes = Object.keys(scriptTypeMap);
if (!scriptType) return;
if (!scriptType.value) {
context.report({
messageId: 'noValue',
loc: scriptType.locs.tag,
});
} else if (scriptType.locs.value && !scriptTypes.includes(scriptType.value)) {
context.report({
messageId: 'invalidValue',
data: {
value: scriptType.value,
},
loc: scriptType.locs.value,
});
}
},
};
},
};