isml-linter 5.39.3 → 5.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +1184 -1159
  2. package/LICENSE +21 -21
  3. package/README.md +245 -245
  4. package/bin/isml-linter.js +32 -32
  5. package/ismllinter.config.js +33 -33
  6. package/package.json +53 -53
  7. package/scaffold_files/ismllinter.config.js +47 -47
  8. package/src/Builder.js +15 -15
  9. package/src/Constants.js +139 -139
  10. package/src/IsmlLinter.js +255 -255
  11. package/src/enums/ParseStatus.js +5 -5
  12. package/src/enums/SfccTagContainer.js +287 -287
  13. package/src/isml_tree/ContainerNode.js +38 -38
  14. package/src/isml_tree/IsmlNode.js +692 -684
  15. package/src/isml_tree/MaskUtils.js +421 -421
  16. package/src/isml_tree/ParseUtils.js +532 -506
  17. package/src/isml_tree/TreeBuilder.js +273 -273
  18. package/src/publicApi.js +24 -24
  19. package/src/rules/line_by_line/enforce-isprint.js +53 -53
  20. package/src/rules/line_by_line/enforce-require.js +35 -35
  21. package/src/rules/line_by_line/lowercase-filename.js +29 -29
  22. package/src/rules/line_by_line/max-lines.js +37 -37
  23. package/src/rules/line_by_line/no-br.js +36 -36
  24. package/src/rules/line_by_line/no-git-conflict.js +43 -43
  25. package/src/rules/line_by_line/no-import-package.js +34 -34
  26. package/src/rules/line_by_line/no-inline-style.js +34 -34
  27. package/src/rules/line_by_line/no-isscript.js +34 -34
  28. package/src/rules/line_by_line/no-space-only-lines.js +47 -47
  29. package/src/rules/line_by_line/no-tabs.js +38 -38
  30. package/src/rules/line_by_line/no-trailing-spaces.js +52 -52
  31. package/src/rules/prototypes/RulePrototype.js +79 -79
  32. package/src/rules/prototypes/SingleLineRulePrototype.js +47 -47
  33. package/src/rules/prototypes/TreeRulePrototype.js +84 -84
  34. package/src/rules/tree/align-isset.js +87 -87
  35. package/src/rules/tree/contextual-attrs.js +105 -105
  36. package/src/rules/tree/custom-tags.js +54 -54
  37. package/src/rules/tree/disallow-tags.js +39 -39
  38. package/src/rules/tree/empty-eof.js +66 -66
  39. package/src/rules/tree/enforce-security.js +85 -85
  40. package/src/rules/tree/eslint-to-isscript.js +179 -179
  41. package/src/rules/tree/indent.js +856 -853
  42. package/src/rules/tree/leading-iscache.js +39 -39
  43. package/src/rules/tree/leading-iscontent.js +35 -35
  44. package/src/rules/tree/max-depth.js +54 -54
  45. package/src/rules/tree/no-deprecated-attrs.js +67 -67
  46. package/src/rules/tree/no-embedded-isml.js +17 -17
  47. package/src/rules/tree/no-hardcode.js +51 -51
  48. package/src/rules/tree/no-iselse-slash.js +35 -35
  49. package/src/rules/tree/no-redundant-context.js +134 -134
  50. package/src/rules/tree/no-require-in-loop.js +63 -63
  51. package/src/rules/tree/one-element-per-line.js +82 -76
  52. package/src/util/CommandLineUtils.js +19 -19
  53. package/src/util/ConfigUtils.js +219 -219
  54. package/src/util/ConsoleUtils.js +327 -327
  55. package/src/util/CustomTagContainer.js +45 -45
  56. package/src/util/ExceptionUtils.js +173 -149
  57. package/src/util/FileUtils.js +79 -79
  58. package/src/util/GeneralUtils.js +60 -60
  59. package/src/util/NativeExtensionUtils.js +6 -6
  60. package/src/util/RuleUtils.js +295 -295
  61. package/src/util/TempRuleUtils.js +232 -232
package/src/IsmlLinter.js CHANGED
@@ -1,255 +1,255 @@
1
- const readDir = require('readdir');
2
- const path = require('path');
3
- const appRoot = require('app-root-path');
4
- const fs = require('fs');
5
- const ConfigUtils = require('./util/ConfigUtils');
6
- const ExceptionUtils = require('./util/ExceptionUtils');
7
- const FileUtils = require('./util/FileUtils');
8
- const GeneralUtils = require('./util/GeneralUtils');
9
- let RuleUtils = null;
10
-
11
- const UNKNOWN_ERROR = ExceptionUtils.types.UNKNOWN_ERROR;
12
- const UNPARSEABLE = ExceptionUtils.types.INVALID_TEMPLATE;
13
- const RULE_ERROR = ExceptionUtils.types.RULE_ERROR;
14
- const Linter = {};
15
-
16
- // Configuration set through the public API;
17
- let globalConfig;
18
-
19
- const ignoreFiles = file => {
20
- if (file.indexOf('node_modules') >= 0) {
21
- return true;
22
- }
23
-
24
- const config = ConfigUtils.load();
25
-
26
- if (config.ignore && config.ignore.some( ignorePath => file.indexOf(ignorePath) >= 0)) {
27
- return true;
28
- }
29
-
30
- return false;
31
- };
32
-
33
- const addIfNotBlacklisted = (result, templatePath) => {
34
- if (!ignoreFiles(templatePath)) {
35
- result.templates.push(templatePath);
36
- }
37
- };
38
-
39
- const getTemplatePaths = pathData => {
40
- const config = ConfigUtils.load();
41
- const result = {
42
- templates : [],
43
- notFound : [],
44
- pathData : null
45
- };
46
-
47
- pathData = pathData !== undefined && (!Array.isArray(pathData) || pathData.length > 0) ?
48
- pathData :
49
- config.rootDir || appRoot.toString();
50
-
51
- result.pathData = pathData;
52
-
53
- if (Array.isArray(pathData)) {
54
- for (let i = 0; i < pathData.length; i++) {
55
- const paramPath = pathData[i];
56
-
57
- if (!fs.existsSync(paramPath)) {
58
- result.notFound.push(paramPath);
59
- continue;
60
- }
61
-
62
- if (fs.lstatSync(paramPath).isFile()) {
63
- addIfNotBlacklisted(result, paramPath);
64
- } else {
65
- const templateArray = readDir.readSync(paramPath, ['**.isml']);
66
-
67
- for (let j = 0; j < templateArray.length; j++) {
68
- const templatePath = path.join(paramPath, templateArray[j]);
69
- addIfNotBlacklisted(result, templatePath);
70
- }
71
- }
72
- }
73
- } else {
74
- if (fs.lstatSync(pathData).isFile()) {
75
- result.templates.push(pathData);
76
- } else {
77
- const templateArray = readDir.readSync(pathData, ['**.isml']);
78
-
79
- for (let i = 0; i < templateArray.length; i++) {
80
- const templatePath = templateArray[i];
81
- addIfNotBlacklisted(result, templatePath);
82
- }
83
- }
84
- }
85
-
86
- return result;
87
- };
88
-
89
- const getEmptyResult = () => {
90
- return {
91
- errors : {},
92
- warnings : {},
93
- info : {},
94
- UNKNOWN_ERROR : [],
95
- INVALID_TEMPLATE : [],
96
- RULE_ERROR : [],
97
- issueQty : 0,
98
- occurrenceQty : 0,
99
- templatesFixed : 0,
100
- totalTemplatesQty : 0
101
- };
102
- };
103
-
104
- const checkTemplate = (templatePath, data, content, templateName) => {
105
- const formattedTemplatePath = GeneralUtils.formatTemplatePath(templatePath);
106
- const templateResults = getEmptyResult();
107
-
108
- try {
109
- const parseResult = RuleUtils.checkTemplate(templatePath, data, content, templateName);
110
-
111
- if (parseResult.fixed) {
112
- templateResults.templatesFixed++;
113
- }
114
-
115
- for (const rule in parseResult.errors) {
116
- templateResults.errors[rule] = templateResults.errors[rule] || {};
117
- templateResults.errors[rule][formattedTemplatePath] = parseResult.errors[rule];
118
- templateResults.issueQty++;
119
- templateResults.occurrenceQty++;
120
- }
121
-
122
- for (const rule in parseResult.warnings) {
123
- templateResults.warnings[rule] = templateResults.warnings[rule] || {};
124
- templateResults.warnings[rule][formattedTemplatePath] = parseResult.warnings[rule];
125
- templateResults.occurrenceQty++;
126
- }
127
-
128
- for (const rule in parseResult.info) {
129
- templateResults.info[rule] = templateResults.info[rule] || {};
130
- templateResults.info[rule][formattedTemplatePath] = parseResult.info[rule];
131
- templateResults.occurrenceQty++;
132
- }
133
- }
134
- catch (e) {
135
- const config = ConfigUtils.load();
136
-
137
- if (!ExceptionUtils.isLinterException(e) || e.type === UNKNOWN_ERROR) {
138
- templateResults[UNKNOWN_ERROR].push(formattedTemplatePath);
139
-
140
- templateResults.issueQty++;
141
- templateResults.occurrenceQty++;
142
-
143
- } else if (e.type === RULE_ERROR) {
144
- templateResults[RULE_ERROR].push({
145
- templatePath : formattedTemplatePath,
146
- ruleID : e.ruleID,
147
- message : e.message,
148
- originalError : e.originalError
149
- });
150
-
151
- templateResults.issueQty++;
152
- templateResults.occurrenceQty++;
153
-
154
- } else if (!config.ignoreUnparseable) {
155
- templateResults[UNPARSEABLE].push({
156
- templatePath : formattedTemplatePath,
157
- message : e.message,
158
- globalPos : e.globalPos,
159
- length : e.length,
160
- lineNumber : e.lineNumber
161
- });
162
-
163
- templateResults.issueQty++;
164
- templateResults.occurrenceQty++;
165
- }
166
- }
167
-
168
- return templateResults;
169
- };
170
-
171
- const merge = (finalResult, templateResults) => {
172
- return {
173
- errors : GeneralUtils.mergeDeep(finalResult.errors, templateResults.errors),
174
- warnings : GeneralUtils.mergeDeep(finalResult.warnings, templateResults.warnings),
175
- info : GeneralUtils.mergeDeep(finalResult.info, templateResults.info),
176
- issueQty : finalResult.issueQty + templateResults.issueQty,
177
- templatesFixed : finalResult.templatesFixed + templateResults.templatesFixed,
178
- UNKNOWN_ERROR : [...finalResult[UNKNOWN_ERROR], ...templateResults[UNKNOWN_ERROR]],
179
- INVALID_TEMPLATE : [...finalResult[UNPARSEABLE], ...templateResults[UNPARSEABLE]],
180
- RULE_ERROR : [...finalResult[RULE_ERROR], ...templateResults[RULE_ERROR]],
181
- totalTemplatesQty : finalResult.totalTemplatesQty
182
- };
183
- };
184
-
185
- const addCustomModuleResults = finalResult => {
186
- const CustomModulesRule = require('./rules/tree/custom-tags');
187
- const customModuleResults = RuleUtils.checkCustomModules();
188
- const occurrenceGroup = RuleUtils.getLevelGroup(CustomModulesRule.level);
189
-
190
- if (customModuleResults[occurrenceGroup].length) {
191
- finalResult[occurrenceGroup][CustomModulesRule.id] = finalResult[occurrenceGroup][CustomModulesRule.id] || {};
192
- // TODO: Add actual modules template path;
193
- finalResult[occurrenceGroup][CustomModulesRule.id]['modules.isml'] = customModuleResults[occurrenceGroup];
194
- }
195
- };
196
-
197
- Linter.setConfig = newConfig => {
198
- globalConfig = newConfig;
199
- };
200
-
201
- Linter.getConfig = () => globalConfig;
202
-
203
- Linter.run = (pathData, content, data = {}) => {
204
- const ConsoleUtils = require('./util/ConsoleUtils');
205
-
206
- ConfigUtils.setLocalConfig(globalConfig);
207
- ConfigUtils.setLocalEslintConfig();
208
-
209
- if (!ConfigUtils.isConfigSet()) {
210
- ConsoleUtils.displayConfigError();
211
- throw ExceptionUtils.noConfigError();
212
- }
213
-
214
- RuleUtils = require('./util/RuleUtils');
215
-
216
- const templateData = getTemplatePaths(pathData);
217
- const templatePathArray = templateData.templates;
218
- let finalResult = getEmptyResult();
219
-
220
- if (templateData.notFound.length > 0) {
221
- ConsoleUtils.displayInvalidTemplatesPaths(templateData.notFound);
222
- }
223
-
224
- try {
225
- const lintStartTime = new Date();
226
-
227
- for (let i = 0; i < templatePathArray.length; i++) {
228
- const templateName = templatePathArray[i];
229
- const templatePath = Array.isArray(templateData.pathData) || path.isAbsolute(templateName) || templateData.pathData === templateName ?
230
- templateName :
231
- path.join(templateData.pathData, templateName);
232
- const isIgnored = FileUtils.isIgnored(templatePath);
233
-
234
- if (!isIgnored) {
235
- const templateResults = checkTemplate(templatePath, data, content, templateName);
236
-
237
- finalResult = merge(finalResult, templateResults);
238
- }
239
- }
240
-
241
- addCustomModuleResults(finalResult);
242
-
243
- const lintEndTime = new Date();
244
- finalResult.elapsedTime = (lintEndTime.getTime() - lintStartTime.getTime()) / 1000;
245
- finalResult.totalTemplatesQty = templatePathArray.length;
246
-
247
- } catch (e) {
248
- ConsoleUtils.printExceptionMsg(e.stack || e);
249
- process.exit(1);
250
- }
251
-
252
- return finalResult;
253
- };
254
-
255
- module.exports = Linter;
1
+ const readDir = require('readdir');
2
+ const path = require('path');
3
+ const appRoot = require('app-root-path');
4
+ const fs = require('fs');
5
+ const ConfigUtils = require('./util/ConfigUtils');
6
+ const ExceptionUtils = require('./util/ExceptionUtils');
7
+ const FileUtils = require('./util/FileUtils');
8
+ const GeneralUtils = require('./util/GeneralUtils');
9
+ let RuleUtils = null;
10
+
11
+ const UNKNOWN_ERROR = ExceptionUtils.types.UNKNOWN_ERROR;
12
+ const UNPARSEABLE = ExceptionUtils.types.INVALID_TEMPLATE;
13
+ const RULE_ERROR = ExceptionUtils.types.RULE_ERROR;
14
+ const Linter = {};
15
+
16
+ // Configuration set through the public API;
17
+ let globalConfig;
18
+
19
+ const ignoreFiles = file => {
20
+ if (file.indexOf('node_modules') >= 0) {
21
+ return true;
22
+ }
23
+
24
+ const config = ConfigUtils.load();
25
+
26
+ if (config.ignore && config.ignore.some( ignorePath => file.indexOf(ignorePath) >= 0)) {
27
+ return true;
28
+ }
29
+
30
+ return false;
31
+ };
32
+
33
+ const addIfNotBlacklisted = (result, templatePath) => {
34
+ if (!ignoreFiles(templatePath)) {
35
+ result.templates.push(templatePath);
36
+ }
37
+ };
38
+
39
+ const getTemplatePaths = pathData => {
40
+ const config = ConfigUtils.load();
41
+ const result = {
42
+ templates : [],
43
+ notFound : [],
44
+ pathData : null
45
+ };
46
+
47
+ pathData = pathData !== undefined && (!Array.isArray(pathData) || pathData.length > 0) ?
48
+ pathData :
49
+ config.rootDir || appRoot.toString();
50
+
51
+ result.pathData = pathData;
52
+
53
+ if (Array.isArray(pathData)) {
54
+ for (let i = 0; i < pathData.length; i++) {
55
+ const paramPath = pathData[i];
56
+
57
+ if (!fs.existsSync(paramPath)) {
58
+ result.notFound.push(paramPath);
59
+ continue;
60
+ }
61
+
62
+ if (fs.lstatSync(paramPath).isFile()) {
63
+ addIfNotBlacklisted(result, paramPath);
64
+ } else {
65
+ const templateArray = readDir.readSync(paramPath, ['**.isml']);
66
+
67
+ for (let j = 0; j < templateArray.length; j++) {
68
+ const templatePath = path.join(paramPath, templateArray[j]);
69
+ addIfNotBlacklisted(result, templatePath);
70
+ }
71
+ }
72
+ }
73
+ } else {
74
+ if (fs.lstatSync(pathData).isFile()) {
75
+ result.templates.push(pathData);
76
+ } else {
77
+ const templateArray = readDir.readSync(pathData, ['**.isml']);
78
+
79
+ for (let i = 0; i < templateArray.length; i++) {
80
+ const templatePath = templateArray[i];
81
+ addIfNotBlacklisted(result, templatePath);
82
+ }
83
+ }
84
+ }
85
+
86
+ return result;
87
+ };
88
+
89
+ const getEmptyResult = () => {
90
+ return {
91
+ errors : {},
92
+ warnings : {},
93
+ info : {},
94
+ UNKNOWN_ERROR : [],
95
+ INVALID_TEMPLATE : [],
96
+ RULE_ERROR : [],
97
+ issueQty : 0,
98
+ occurrenceQty : 0,
99
+ templatesFixed : 0,
100
+ totalTemplatesQty : 0
101
+ };
102
+ };
103
+
104
+ const checkTemplate = (templatePath, data, content, templateName) => {
105
+ const formattedTemplatePath = GeneralUtils.formatTemplatePath(templatePath);
106
+ const templateResults = getEmptyResult();
107
+
108
+ try {
109
+ const parseResult = RuleUtils.checkTemplate(templatePath, data, content, templateName);
110
+
111
+ if (parseResult.fixed) {
112
+ templateResults.templatesFixed++;
113
+ }
114
+
115
+ for (const rule in parseResult.errors) {
116
+ templateResults.errors[rule] = templateResults.errors[rule] || {};
117
+ templateResults.errors[rule][formattedTemplatePath] = parseResult.errors[rule];
118
+ templateResults.issueQty++;
119
+ templateResults.occurrenceQty++;
120
+ }
121
+
122
+ for (const rule in parseResult.warnings) {
123
+ templateResults.warnings[rule] = templateResults.warnings[rule] || {};
124
+ templateResults.warnings[rule][formattedTemplatePath] = parseResult.warnings[rule];
125
+ templateResults.occurrenceQty++;
126
+ }
127
+
128
+ for (const rule in parseResult.info) {
129
+ templateResults.info[rule] = templateResults.info[rule] || {};
130
+ templateResults.info[rule][formattedTemplatePath] = parseResult.info[rule];
131
+ templateResults.occurrenceQty++;
132
+ }
133
+ }
134
+ catch (e) {
135
+ const config = ConfigUtils.load();
136
+
137
+ if (!ExceptionUtils.isLinterException(e) || e.type === UNKNOWN_ERROR) {
138
+ templateResults[UNKNOWN_ERROR].push(formattedTemplatePath);
139
+
140
+ templateResults.issueQty++;
141
+ templateResults.occurrenceQty++;
142
+
143
+ } else if (e.type === RULE_ERROR) {
144
+ templateResults[RULE_ERROR].push({
145
+ templatePath : formattedTemplatePath,
146
+ ruleID : e.ruleID,
147
+ message : e.message,
148
+ originalError : e.originalError
149
+ });
150
+
151
+ templateResults.issueQty++;
152
+ templateResults.occurrenceQty++;
153
+
154
+ } else if (!config.ignoreUnparseable) {
155
+ templateResults[UNPARSEABLE].push({
156
+ templatePath : formattedTemplatePath,
157
+ message : e.message,
158
+ globalPos : e.globalPos,
159
+ length : e.length,
160
+ lineNumber : e.lineNumber
161
+ });
162
+
163
+ templateResults.issueQty++;
164
+ templateResults.occurrenceQty++;
165
+ }
166
+ }
167
+
168
+ return templateResults;
169
+ };
170
+
171
+ const merge = (finalResult, templateResults) => {
172
+ return {
173
+ errors : GeneralUtils.mergeDeep(finalResult.errors, templateResults.errors),
174
+ warnings : GeneralUtils.mergeDeep(finalResult.warnings, templateResults.warnings),
175
+ info : GeneralUtils.mergeDeep(finalResult.info, templateResults.info),
176
+ issueQty : finalResult.issueQty + templateResults.issueQty,
177
+ templatesFixed : finalResult.templatesFixed + templateResults.templatesFixed,
178
+ UNKNOWN_ERROR : [...finalResult[UNKNOWN_ERROR], ...templateResults[UNKNOWN_ERROR]],
179
+ INVALID_TEMPLATE : [...finalResult[UNPARSEABLE], ...templateResults[UNPARSEABLE]],
180
+ RULE_ERROR : [...finalResult[RULE_ERROR], ...templateResults[RULE_ERROR]],
181
+ totalTemplatesQty : finalResult.totalTemplatesQty
182
+ };
183
+ };
184
+
185
+ const addCustomModuleResults = finalResult => {
186
+ const CustomModulesRule = require('./rules/tree/custom-tags');
187
+ const customModuleResults = RuleUtils.checkCustomModules();
188
+ const occurrenceGroup = RuleUtils.getLevelGroup(CustomModulesRule.level);
189
+
190
+ if (customModuleResults[occurrenceGroup].length) {
191
+ finalResult[occurrenceGroup][CustomModulesRule.id] = finalResult[occurrenceGroup][CustomModulesRule.id] || {};
192
+ // TODO: Add actual modules template path;
193
+ finalResult[occurrenceGroup][CustomModulesRule.id]['modules.isml'] = customModuleResults[occurrenceGroup];
194
+ }
195
+ };
196
+
197
+ Linter.setConfig = newConfig => {
198
+ globalConfig = newConfig;
199
+ };
200
+
201
+ Linter.getConfig = () => globalConfig;
202
+
203
+ Linter.run = (pathData, content, data = {}) => {
204
+ const ConsoleUtils = require('./util/ConsoleUtils');
205
+
206
+ ConfigUtils.setLocalConfig(globalConfig);
207
+ ConfigUtils.setLocalEslintConfig();
208
+
209
+ if (!ConfigUtils.isConfigSet()) {
210
+ ConsoleUtils.displayConfigError();
211
+ throw ExceptionUtils.noConfigError();
212
+ }
213
+
214
+ RuleUtils = require('./util/RuleUtils');
215
+
216
+ const templateData = getTemplatePaths(pathData);
217
+ const templatePathArray = templateData.templates;
218
+ let finalResult = getEmptyResult();
219
+
220
+ if (templateData.notFound.length > 0) {
221
+ ConsoleUtils.displayInvalidTemplatesPaths(templateData.notFound);
222
+ }
223
+
224
+ try {
225
+ const lintStartTime = new Date();
226
+
227
+ for (let i = 0; i < templatePathArray.length; i++) {
228
+ const templateName = templatePathArray[i];
229
+ const templatePath = Array.isArray(templateData.pathData) || path.isAbsolute(templateName) || templateData.pathData === templateName ?
230
+ templateName :
231
+ path.join(templateData.pathData, templateName);
232
+ const isIgnored = FileUtils.isIgnored(templatePath);
233
+
234
+ if (!isIgnored) {
235
+ const templateResults = checkTemplate(templatePath, data, content, templateName);
236
+
237
+ finalResult = merge(finalResult, templateResults);
238
+ }
239
+ }
240
+
241
+ addCustomModuleResults(finalResult);
242
+
243
+ const lintEndTime = new Date();
244
+ finalResult.elapsedTime = (lintEndTime.getTime() - lintStartTime.getTime()) / 1000;
245
+ finalResult.totalTemplatesQty = templatePathArray.length;
246
+
247
+ } catch (e) {
248
+ ConsoleUtils.printExceptionMsg(e.stack || e);
249
+ process.exit(1);
250
+ }
251
+
252
+ return finalResult;
253
+ };
254
+
255
+ module.exports = Linter;
@@ -1,5 +1,5 @@
1
- module.exports = {
2
- NO_ERRORS : 0,
3
- ERRORS_FOUND : 1,
4
- INVALID_DOM : 2
5
- };
1
+ module.exports = {
2
+ NO_ERRORS : 0,
3
+ ERRORS_FOUND : 1,
4
+ INVALID_DOM : 2
5
+ };