Skip to content

Commit 52adcd0

Browse files
committed
Make script type case insensitive, improve naming
1 parent f907242 commit 52adcd0

File tree

6 files changed

+60
-46
lines changed

6 files changed

+60
-46
lines changed

lib/rules/entry-points.js

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

3-
const metadataUtil = require('../util/metadata');
4-
const scriptTypeMap = require('../util/scriptTypes');
3+
const { getScriptType } = require('../util/metadata');
4+
const { scriptTypes } = require('../util/scriptTypes');
55

66
module.exports = {
77
meta: {
@@ -15,8 +15,7 @@ module.exports = {
1515
return {
1616
'CallExpression[callee.name=define]': function (node) {
1717
let hasValidEntryPoint = false;
18-
let scriptType = metadataUtil.getScriptType(context);
19-
const scriptTypes = Object.keys(scriptTypeMap);
18+
let scriptType = getScriptType(context);
2019

2120
scriptType = scriptType && scriptType.value;
2221

lib/rules/script-type.js

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

3-
const metadataUtil = require('../util/metadata');
4-
const scriptTypeMap = require('../util/scriptTypes');
3+
const { getScriptType } = require('../util/metadata');
4+
const { scriptTypes } = require('../util/scriptTypes');
55

66
module.exports = {
77
meta: {
@@ -15,8 +15,7 @@ module.exports = {
1515
create: function (context) {
1616
return {
1717
Program: function () {
18-
const scriptType = metadataUtil.getScriptType(context);
19-
const scriptTypes = Object.keys(scriptTypeMap);
18+
const scriptType = getScriptType(context);
2019

2120
if (!scriptType) return;
2221

lib/util/metadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function getScriptType(context) {
2525
const typeIndex = tagIndex + SCRIPT_TAG.length + 1;
2626

2727
return {
28-
value: scriptType,
28+
value: scriptType.toLowerCase(),
2929
locs: {
3030
tag: {
3131
start: sourceCode.getLocFromIndex(tagIndex),

lib/util/scriptTypes.js

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
'use strict';
22

3-
module.exports = {
3+
const scriptTypeMap = {
4+
BankConnectivityPlugin: {
5+
entryPoints: [
6+
'getRequiredConfigurationFields',
7+
'downloadPreviousDayBankStatementFile',
8+
],
9+
},
410
BundleInstallationScript: {
511
entryPoints: [
612
'afterInstall',
@@ -26,12 +32,29 @@ module.exports = {
2632
'localizationContextExit',
2733
],
2834
},
35+
DatasetBuilderPlugin: {
36+
entryPoints: ['createDataset'],
37+
},
38+
FiConnectivityPlugin: {
39+
entryPoints: ['getConfigurationIFrameUrl', 'getAccounts', 'getTransactionData'],
40+
},
41+
FiParserPlugin: {
42+
entryPoints: [
43+
'parseData',
44+
'getStandardTransactionCodes',
45+
'getExpenseCodes',
46+
'getConfigurationPageUrl',
47+
],
48+
},
2949
MapReduceScript: {
3050
entryPoints: ['getInputData', 'map', 'reduce', 'summarize'],
3151
},
3252
MassUpdateScript: {
3353
entryPoints: ['each'],
3454
},
55+
PluginTypeImpl: {
56+
entryPoints: [],
57+
},
3558
Portlet: {
3659
entryPoints: ['render'],
3760
},
@@ -50,33 +73,19 @@ module.exports = {
5073
UserEventScript: {
5174
entryPoints: ['afterSubmit', 'beforeLoad', 'beforeSubmit'],
5275
},
53-
WorkflowActionScript: {
54-
entryPoints: ['onAction'],
55-
},
56-
bankConnectivityPlugin: {
57-
entryPoints: [
58-
'getRequiredConfigurationFields',
59-
'downloadPreviousDayBankStatementFile',
60-
],
61-
},
62-
datasetbuilderplugin: {
63-
entryPoints: ['createDataset'],
64-
},
65-
fiConnectivityPlugin: {
66-
entryPoints: ['getConfigurationIFrameUrl', 'getAccounts', 'getTransactionData'],
67-
},
68-
fiParserPlugin: {
69-
entryPoints: [
70-
'parseData',
71-
'getStandardTransactionCodes',
72-
'getExpenseCodes',
73-
'getConfigurationPageUrl',
74-
],
75-
},
76-
workbookbuilderplugin: {
76+
WorkbookBbuilderPlugin: {
7777
entryPoints: ['createWorkbook'],
7878
},
79-
plugintypeimpl: {
80-
entryPoints: [],
79+
WorkflowActionScript: {
80+
entryPoints: ['onAction'],
8181
},
8282
};
83+
84+
const scriptTypes = Object.keys(scriptTypeMap).map(function (x) {
85+
return x.toLowerCase();
86+
});
87+
88+
module.exports = {
89+
scriptTypeMap,
90+
scriptTypes,
91+
};

scripts/generate_docs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
33
const { MODULE_NAMES } = require('./../lib/util/modules');
4-
const SCRIPT_TYPES = require('./../lib/util/scriptTypes');
4+
const { scriptTypeMap } = require('./../lib/util/scriptTypes');
55

66
const SRC_DIR = './docs/src';
77
const OUT_DIR = './docs/rules';
@@ -10,7 +10,7 @@ const SCRIPT_NAME = path.basename(__filename);
1010
const docsToModify = {
1111
'entry-points.md': {
1212
old: '<ENTRY_POINTS>',
13-
new: Object.entries(SCRIPT_TYPES).reduce((str, [scriptType, st]) => {
13+
new: Object.entries(scriptTypeMap).reduce((str, [scriptType, st]) => {
1414
str += `- ${scriptType}\n`;
1515
st.entryPoints.forEach((ep) => (str += ` - ${ep}\n`));
1616
return str;
@@ -25,7 +25,7 @@ const docsToModify = {
2525
},
2626
'script-type.md': {
2727
old: '<SCRIPT_TYPES>',
28-
new: Object.keys(SCRIPT_TYPES).reduce((str, x) => {
28+
new: Object.keys(scriptTypeMap).reduce((str, x) => {
2929
str += `- ${x}\n`;
3030
return str;
3131
}, ''),

tests/rules/script-type.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,27 @@ ruleTester.run('script-type', rule, {
2020
},
2121
{
2222
code: `
23+
/**
24+
* @NScriptType bundleinstallationscript
25+
*/
26+
`,
27+
},
28+
{
29+
code: `
2330
/**
2431
* @NScriptType ClientScript
2532
*/
2633
`,
2734
},
2835
{
2936
code: `
37+
/**
38+
* @NScriptType FiParserPlugin
39+
*/
40+
`,
41+
},
42+
{
43+
code: `
3044
/**
3145
* @NScriptType MapReduceScript
3246
*/
@@ -108,13 +122,6 @@ ruleTester.run('script-type', rule, {
108122
{
109123
code: '// @NScriptType SuiteletScript',
110124
},
111-
{
112-
code: `
113-
/**
114-
* @NScriptType fiParserPlugin
115-
*/
116-
`,
117-
},
118125
],
119126

120127
invalid: [

0 commit comments

Comments
 (0)