Skip to content

Commit 62863f4

Browse files
committed
Simplify script type lookup
1 parent 5c54d94 commit 62863f4

File tree

4 files changed

+47
-53
lines changed

4 files changed

+47
-53
lines changed

lib/rules/entry-points.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const { getScriptType } = require('../util/metadata');
4-
const { scriptTypeMap, scriptTypes } = require('../util/scriptTypes');
54

65
module.exports = {
76
meta: {
@@ -16,9 +15,7 @@ module.exports = {
1615
let hasValidEntryPoint = false;
1716
let scriptType = getScriptType(context);
1817

19-
scriptType = scriptType && scriptType.value;
20-
21-
if (!scriptType || !scriptTypes.includes(scriptType)) {
18+
if (!scriptType.value || !scriptType.def) {
2219
return;
2320
}
2421

@@ -37,7 +34,7 @@ module.exports = {
3734
if (returnArgument && returnArgument.type === 'ObjectExpression') {
3835
for (const property of returnArgument.properties) {
3936
if (
40-
scriptTypeMap[scriptType].entryPoints.includes(property.key.name) &&
37+
scriptType.def.entryPoints.includes(property.key.name) &&
4138
(property.value.type === 'Identifier' ||
4239
property.value.type === 'FunctionExpression')
4340
) {
@@ -53,17 +50,15 @@ module.exports = {
5350
n.type === 'ExpressionStatement' &&
5451
n.expression.left.type === 'MemberExpression' &&
5552
n.expression.left.object.name === returnArgument.name &&
56-
scriptTypeMap[scriptType].entryPoints.includes(
57-
n.expression.left.property.name
58-
)
53+
scriptType.def.entryPoints.includes(n.expression.left.property.name)
5954
);
6055

6156
if (returnAssignments.length > 0) {
6257
hasValidEntryPoint = true;
6358
}
6459
}
6560

66-
if (scriptTypeMap[scriptType].entryPoints.length === 0) {
61+
if (scriptType.def.entryPoints.length === 0) {
6762
hasValidEntryPoint = true;
6863
}
6964

@@ -72,7 +67,7 @@ module.exports = {
7267
node: returnStatement || callback,
7368
messageId: 'returnEntryPoint',
7469
data: {
75-
type: scriptType,
70+
type: scriptType.value,
7671
},
7772
});
7873
}

lib/rules/script-type.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const { getScriptType } = require('../util/metadata');
4-
const { scriptTypes } = require('../util/scriptTypes');
54

65
module.exports = {
76
meta: {
@@ -23,7 +22,7 @@ module.exports = {
2322
messageId: 'noValue',
2423
loc: scriptType.locs.tag,
2524
});
26-
} else if (scriptType.locs.value && !scriptTypes.includes(scriptType.value)) {
25+
} else if (scriptType.locs.value && !scriptType.def) {
2726
context.report({
2827
messageId: 'invalidValue',
2928
data: {

lib/util/metadata.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { getScriptTypeDef } = require('./scriptTypes');
4+
35
const SCRIPT_TAG = '@NScriptType';
46
const SCRIPT_TAG_REGEX = /@NScriptType(?: (\S+))?/;
57

@@ -25,7 +27,8 @@ function getScriptType(context) {
2527
const typeIndex = tagIndex + SCRIPT_TAG.length + 1;
2628

2729
return {
28-
value: scriptType.toLowerCase(),
30+
value: scriptType,
31+
def: getScriptTypeDef(scriptType),
2932
locs: {
3033
tag: {
3134
start: sourceCode.getLocFromIndex(tagIndex),

lib/util/scriptTypes.js

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'use strict';
22

3-
const scriptTypeMap = {
4-
BankConnectivityPlugin: {
3+
const scriptTypes = [
4+
{
5+
name: 'BankConnectivityPlugin',
56
entryPoints: [
67
'getRequiredConfigurationFields',
78
'downloadPreviousDayBankStatementFile',
89
],
910
},
10-
BundleInstallationScript: {
11+
{
12+
name: 'BundleInstallationScript',
1113
entryPoints: [
1214
'afterInstall',
1315
'afterUpdate',
@@ -16,7 +18,8 @@ const scriptTypeMap = {
1618
'beforeUpdate',
1719
],
1820
},
19-
ClientScript: {
21+
{
22+
name: 'ClientScript',
2023
entryPoints: [
2124
'fieldChanged',
2225
'lineInit',
@@ -32,63 +35,57 @@ const scriptTypeMap = {
3235
'localizationContextExit',
3336
],
3437
},
35-
CustomGLPlugin: {
36-
entryPoitns: ['customizeGlImpact'],
37-
},
38-
DatasetBuilderPlugin: {
39-
entryPoints: ['createDataset'],
40-
},
41-
FiConnectivityPlugin: {
38+
{ name: 'CustomGLPlugin', entryPoints: ['customizeGlImpact'] },
39+
{ name: 'DatasetBuilderPlugin', entryPoints: ['createDataset'] },
40+
{
41+
name: 'FiConnectivityPlugin',
4242
entryPoints: ['getConfigurationIFrameUrl', 'getAccounts', 'getTransactionData'],
4343
},
44-
FiParserPlugin: {
44+
{
45+
name: 'FiParserPlugin',
4546
entryPoints: [
4647
'parseData',
4748
'getStandardTransactionCodes',
4849
'getExpenseCodes',
4950
'getConfigurationPageUrl',
5051
],
5152
},
52-
MapReduceScript: {
53+
{
54+
name: 'MapReduceScript',
5355
entryPoints: ['getInputData', 'map', 'reduce', 'summarize'],
5456
},
55-
MassUpdateScript: {
56-
entryPoints: ['each'],
57-
},
58-
PluginTypeImpl: {
59-
entryPoints: [],
60-
},
61-
Portlet: {
62-
entryPoints: ['render'],
63-
},
64-
Restlet: {
65-
entryPoints: ['delete', 'get', 'post', 'put'],
66-
},
67-
ScheduledScript: {
68-
entryPoints: ['execute'],
69-
},
70-
SDFInstallationScript: {
71-
entryPoints: ['run'],
72-
},
73-
Suitelet: {
57+
{ name: 'MassUpdateScript', entryPoints: ['each'] },
58+
{ name: 'PluginTypeImpl', entryPoints: [] },
59+
{ name: 'Portlet', entryPoints: ['render'] },
60+
{ name: 'Restlet', entryPoints: ['delete', 'get', 'post', 'put'] },
61+
{ name: 'ScheduledScript', entryPoints: ['execute'] },
62+
{ name: 'SDFInstallationScript', entryPoints: ['run'] },
63+
{
64+
name: 'Suitelet',
7465
entryPoints: ['onRequest'],
7566
},
76-
UserEventScript: {
67+
{
68+
name: 'UserEventScript',
7769
entryPoints: ['afterSubmit', 'beforeLoad', 'beforeSubmit'],
7870
},
79-
WorkbookBbuilderPlugin: {
71+
{
72+
name: 'WorkbookBbuilderPlugin',
8073
entryPoints: ['createWorkbook'],
8174
},
82-
WorkflowActionScript: {
75+
{
76+
name: 'WorkflowActionScript',
8377
entryPoints: ['onAction'],
8478
},
85-
};
79+
];
8680

87-
const scriptTypes = Object.keys(scriptTypeMap).map(function (x) {
88-
return x.toLowerCase();
89-
});
81+
function getScriptTypeDef(scriptType) {
82+
return (
83+
!!scriptType &&
84+
scriptTypes.find((x) => x.name.toLowerCase() === scriptType.toLowerCase())
85+
);
86+
}
9087

9188
module.exports = {
92-
scriptTypeMap,
9389
scriptTypes,
90+
getScriptTypeDef,
9491
};

0 commit comments

Comments
 (0)