isml-linter 5.39.0 → 5.39.4

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 +1167 -1133
  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 +684 -658
  15. package/src/isml_tree/MaskUtils.js +421 -419
  16. package/src/isml_tree/ParseUtils.js +514 -434
  17. package/src/isml_tree/TreeBuilder.js +273 -271
  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 +853 -853
  42. package/src/rules/tree/leading-iscache.js +39 -43
  43. package/src/rules/tree/leading-iscontent.js +35 -39
  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 +76 -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 +149 -131
  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
@@ -1,232 +1,232 @@
1
- /*
2
- ===========================================================================
3
- THIS FILE EXISTS ONLY TO AVOID CIRCULAR DEPENDENCY.
4
- DUE TO A PRESSING BUG, IT WAS TEMPORARILY CREATED.
5
- IT WILL SOON BE REMOVED.
6
- ===========================================================================
7
- **/
8
-
9
- const path = require('path');
10
- const fs = require('fs');
11
- const Constants = require('../Constants');
12
- const TreeBuilder = require('../isml_tree/TreeBuilder');
13
- const ConfigUtils = require('./ConfigUtils');
14
- const lowercaseFilenameRule = require('../rules/line_by_line/lowercase-filename');
15
- const CustomTagContainer = require('./CustomTagContainer');
16
- const CustomModulesRule = require('../rules/tree/custom-tags');
17
-
18
- const lineByLineRules = [];
19
- const treeRules = [];
20
-
21
- const checkCustomTag = tag => {
22
- if (Object.prototype.hasOwnProperty.call(CustomTagContainer, tag)) {
23
- const attrList = CustomTagContainer[tag].attrList;
24
-
25
- for (let i = 0; i < attrList.length; i++) {
26
- const attr = attrList[i];
27
- if (attr !== attr.toLowerCase()) {
28
- return {
29
- line : '',
30
- globalPos : 0,
31
- length : 10,
32
- lineNumber : 1,
33
- rule : CustomModulesRule.id,
34
- message : `Module properties need to be lower case: "${tag}" module has the invalid "${attr}" attribute`
35
- };
36
- }
37
- }
38
- }
39
- };
40
-
41
- const applyRuleResult = (config, ruleResult, templatePath, templateResults, rule) => {
42
- if (config.autoFix && ruleResult.fixedContent) {
43
- fs.writeFileSync(templatePath, ruleResult.fixedContent);
44
- templateResults.fixed = true;
45
- }
46
- else if (ruleResult.occurrenceList && ruleResult.occurrenceList.length) {
47
- const occurrenceObj = getOccurrenceObj(rule, ruleResult.occurrenceList);
48
- templateResults.errors = Object.assign(templateResults.errors, occurrenceObj.errors);
49
- }
50
- };
51
-
52
- const applyRuleOnTemplate = (ruleArray, templatePath, root, config) => {
53
- const templateResults = {
54
- fixed : false,
55
- errors : {}
56
- };
57
-
58
- for (let i = 0; i < ruleArray.length; i++) {
59
- const rule = ruleArray[i];
60
- if (!rule.shouldIgnore(templatePath)) {
61
- const ruleResults = rule.check(root, templateResults.data);
62
- applyRuleResult(config, ruleResults, templatePath, templateResults, rule);
63
- }
64
- }
65
-
66
- return templateResults;
67
- };
68
-
69
- const findNodeOfType = (node, type) => {
70
- let result = null;
71
-
72
- node.children.some( child => {
73
- if (child.isOfType(type)) {
74
- result = child;
75
- return true;
76
- } else {
77
- result = findNodeOfType(child, type) || result;
78
- }
79
-
80
- return false;
81
- });
82
-
83
- return result;
84
- };
85
-
86
- const isTypeAmongTheFirstElements = (rootNode, type) => {
87
- let result = false;
88
-
89
- for (let i = 0; i < Constants.leadingElementsChecking; i++) {
90
- result = result ||
91
- rootNode.children[i] &&
92
- rootNode.children[i].isOfType(type);
93
- }
94
-
95
- return result;
96
- };
97
-
98
- const getOccurrenceObj = (rule, occurrenceArray) => {
99
- const occurrenceGroup = rule.level === 'error' ? 'errors' :
100
- rule.level === 'warning' ? 'warnings' :
101
- 'info';
102
-
103
- const occurrenceObj = {};
104
- occurrenceObj[occurrenceGroup] = {};
105
- occurrenceObj[occurrenceGroup][rule.id] = [];
106
-
107
- for (let i = 0; i < occurrenceArray.length; i++) {
108
- const occurrence = occurrenceArray[i];
109
- occurrenceObj[occurrenceGroup][rule.id].push(occurrence);
110
- }
111
-
112
- return occurrenceObj;
113
- };
114
-
115
- const checkFileName = (filename, templateContent) => {
116
- const templateResults = {
117
- fixed : false,
118
- errors : {}
119
- };
120
-
121
- if (lowercaseFilenameRule.isEnabled()) {
122
- const ruleResult = lowercaseFilenameRule.check(filename, templateContent);
123
-
124
- if (ruleResult) {
125
- const occurrenceObj = getOccurrenceObj(lowercaseFilenameRule, ruleResult.occurrenceList);
126
- templateResults.errors = Object.assign(templateResults.errors, occurrenceObj.errors);
127
- }
128
- }
129
-
130
- return templateResults;
131
- };
132
-
133
- const checkTreeRules = (templatePath, templateContent, config) => {
134
- if (!config.disableTreeParse) {
135
- const tree = TreeBuilder.build(templatePath, templateContent);
136
-
137
- if (!tree.rootNode) {
138
- throw tree.exception;
139
- }
140
-
141
- const ruleArray = getEnabledTreeRules();
142
-
143
- return applyRuleOnTemplate(
144
- ruleArray,
145
- templatePath,
146
- tree.rootNode,
147
- config);
148
- }
149
- };
150
-
151
- const checkLineByLineRules = (templatePath, templateContent, config) => {
152
- const ruleArray = getEnabledLineRules();
153
-
154
- return applyRuleOnTemplate(
155
- ruleArray,
156
- templatePath,
157
- templateContent,
158
- config);
159
- };
160
-
161
- const checkCustomModules = () => {
162
- const moduleResults = {
163
- errors : []
164
- };
165
-
166
- if (CustomModulesRule.isEnabled()) {
167
- for (const tag in CustomTagContainer) {
168
- const errorObj = checkCustomTag(tag);
169
-
170
- if (errorObj) {
171
- moduleResults.errors.push(errorObj);
172
- }
173
- }
174
- }
175
-
176
- return moduleResults;
177
- };
178
-
179
- const checkTemplate = (templatePath, content, templateName) => {
180
- const config = ConfigUtils.load();
181
- const templateContent = content || fs.readFileSync(templatePath, 'utf-8');
182
- const lineResults = checkLineByLineRules(templatePath, templateContent, config);
183
- const treeResults = checkTreeRules(templatePath, templateContent, config) || { errors : [] };
184
- const filenameResults = checkFileName(templateName, templateContent);
185
-
186
- return {
187
- fixed : lineResults.fixed || treeResults.fixed,
188
- treeData : treeResults.data,
189
- errors : {
190
- ...lineResults.errors,
191
- ...treeResults.errors,
192
- ...filenameResults.errors
193
- }
194
- };
195
- };
196
-
197
- const getAvailableRulesQty = () => treeRules.length + lineByLineRules.length;
198
-
199
- const getEnabledLineRules = () => {
200
- const result = [];
201
-
202
- for (let i = 0; i < lineByLineRules.length; i++) {
203
- const rule = lineByLineRules[i];
204
-
205
- if (rule.isEnabled() && rule.id !== 'lowercase-filename') {
206
- result.push(rule);
207
- }
208
- }
209
-
210
- return result;
211
- };
212
-
213
- const getEnabledTreeRules = () => {
214
- const result = [];
215
-
216
- for (let i = 0; i < treeRules.length; i++) {
217
- const rule = treeRules[i];
218
-
219
- if (rule.isEnabled()) {
220
- result.push(rule);
221
- }
222
- }
223
-
224
- return result;
225
- };
226
-
227
- module.exports.getAllLineRules = () => lineByLineRules;
228
- module.exports.findNodeOfType = findNodeOfType;
229
- module.exports.isTypeAmongTheFirstElements = isTypeAmongTheFirstElements;
230
- module.exports.checkTemplate = checkTemplate;
231
- module.exports.checkCustomModules = checkCustomModules;
232
- module.exports.getAvailableRulesQty = getAvailableRulesQty;
1
+ /*
2
+ ===========================================================================
3
+ THIS FILE EXISTS ONLY TO AVOID CIRCULAR DEPENDENCY.
4
+ DUE TO A PRESSING BUG, IT WAS TEMPORARILY CREATED.
5
+ IT WILL SOON BE REMOVED.
6
+ ===========================================================================
7
+ **/
8
+
9
+ const path = require('path');
10
+ const fs = require('fs');
11
+ const Constants = require('../Constants');
12
+ const TreeBuilder = require('../isml_tree/TreeBuilder');
13
+ const ConfigUtils = require('./ConfigUtils');
14
+ const lowercaseFilenameRule = require('../rules/line_by_line/lowercase-filename');
15
+ const CustomTagContainer = require('./CustomTagContainer');
16
+ const CustomModulesRule = require('../rules/tree/custom-tags');
17
+
18
+ const lineByLineRules = [];
19
+ const treeRules = [];
20
+
21
+ const checkCustomTag = tag => {
22
+ if (Object.prototype.hasOwnProperty.call(CustomTagContainer, tag)) {
23
+ const attrList = CustomTagContainer[tag].attrList;
24
+
25
+ for (let i = 0; i < attrList.length; i++) {
26
+ const attr = attrList[i];
27
+ if (attr !== attr.toLowerCase()) {
28
+ return {
29
+ line : '',
30
+ globalPos : 0,
31
+ length : 10,
32
+ lineNumber : 1,
33
+ rule : CustomModulesRule.id,
34
+ message : `Module properties need to be lower case: "${tag}" module has the invalid "${attr}" attribute`
35
+ };
36
+ }
37
+ }
38
+ }
39
+ };
40
+
41
+ const applyRuleResult = (config, ruleResult, templatePath, templateResults, rule) => {
42
+ if (config.autoFix && ruleResult.fixedContent) {
43
+ fs.writeFileSync(templatePath, ruleResult.fixedContent);
44
+ templateResults.fixed = true;
45
+ }
46
+ else if (ruleResult.occurrenceList && ruleResult.occurrenceList.length) {
47
+ const occurrenceObj = getOccurrenceObj(rule, ruleResult.occurrenceList);
48
+ templateResults.errors = Object.assign(templateResults.errors, occurrenceObj.errors);
49
+ }
50
+ };
51
+
52
+ const applyRuleOnTemplate = (ruleArray, templatePath, root, config) => {
53
+ const templateResults = {
54
+ fixed : false,
55
+ errors : {}
56
+ };
57
+
58
+ for (let i = 0; i < ruleArray.length; i++) {
59
+ const rule = ruleArray[i];
60
+ if (!rule.shouldIgnore(templatePath)) {
61
+ const ruleResults = rule.check(root, templateResults.data);
62
+ applyRuleResult(config, ruleResults, templatePath, templateResults, rule);
63
+ }
64
+ }
65
+
66
+ return templateResults;
67
+ };
68
+
69
+ const findNodeOfType = (node, type) => {
70
+ let result = null;
71
+
72
+ node.children.some( child => {
73
+ if (child.isOfType(type)) {
74
+ result = child;
75
+ return true;
76
+ } else {
77
+ result = findNodeOfType(child, type) || result;
78
+ }
79
+
80
+ return false;
81
+ });
82
+
83
+ return result;
84
+ };
85
+
86
+ const isTypeAmongTheFirstElements = (rootNode, type) => {
87
+ let result = false;
88
+
89
+ for (let i = 0; i < Constants.leadingElementsChecking; i++) {
90
+ result = result ||
91
+ rootNode.children[i] &&
92
+ rootNode.children[i].isOfType(type);
93
+ }
94
+
95
+ return result;
96
+ };
97
+
98
+ const getOccurrenceObj = (rule, occurrenceArray) => {
99
+ const occurrenceGroup = rule.level === 'error' ? 'errors' :
100
+ rule.level === 'warning' ? 'warnings' :
101
+ 'info';
102
+
103
+ const occurrenceObj = {};
104
+ occurrenceObj[occurrenceGroup] = {};
105
+ occurrenceObj[occurrenceGroup][rule.id] = [];
106
+
107
+ for (let i = 0; i < occurrenceArray.length; i++) {
108
+ const occurrence = occurrenceArray[i];
109
+ occurrenceObj[occurrenceGroup][rule.id].push(occurrence);
110
+ }
111
+
112
+ return occurrenceObj;
113
+ };
114
+
115
+ const checkFileName = (filename, templateContent) => {
116
+ const templateResults = {
117
+ fixed : false,
118
+ errors : {}
119
+ };
120
+
121
+ if (lowercaseFilenameRule.isEnabled()) {
122
+ const ruleResult = lowercaseFilenameRule.check(filename, templateContent);
123
+
124
+ if (ruleResult) {
125
+ const occurrenceObj = getOccurrenceObj(lowercaseFilenameRule, ruleResult.occurrenceList);
126
+ templateResults.errors = Object.assign(templateResults.errors, occurrenceObj.errors);
127
+ }
128
+ }
129
+
130
+ return templateResults;
131
+ };
132
+
133
+ const checkTreeRules = (templatePath, templateContent, config) => {
134
+ if (!config.disableTreeParse) {
135
+ const tree = TreeBuilder.build(templatePath, templateContent);
136
+
137
+ if (!tree.rootNode) {
138
+ throw tree.exception;
139
+ }
140
+
141
+ const ruleArray = getEnabledTreeRules();
142
+
143
+ return applyRuleOnTemplate(
144
+ ruleArray,
145
+ templatePath,
146
+ tree.rootNode,
147
+ config);
148
+ }
149
+ };
150
+
151
+ const checkLineByLineRules = (templatePath, templateContent, config) => {
152
+ const ruleArray = getEnabledLineRules();
153
+
154
+ return applyRuleOnTemplate(
155
+ ruleArray,
156
+ templatePath,
157
+ templateContent,
158
+ config);
159
+ };
160
+
161
+ const checkCustomModules = () => {
162
+ const moduleResults = {
163
+ errors : []
164
+ };
165
+
166
+ if (CustomModulesRule.isEnabled()) {
167
+ for (const tag in CustomTagContainer) {
168
+ const errorObj = checkCustomTag(tag);
169
+
170
+ if (errorObj) {
171
+ moduleResults.errors.push(errorObj);
172
+ }
173
+ }
174
+ }
175
+
176
+ return moduleResults;
177
+ };
178
+
179
+ const checkTemplate = (templatePath, content, templateName) => {
180
+ const config = ConfigUtils.load();
181
+ const templateContent = content || fs.readFileSync(templatePath, 'utf-8');
182
+ const lineResults = checkLineByLineRules(templatePath, templateContent, config);
183
+ const treeResults = checkTreeRules(templatePath, templateContent, config) || { errors : [] };
184
+ const filenameResults = checkFileName(templateName, templateContent);
185
+
186
+ return {
187
+ fixed : lineResults.fixed || treeResults.fixed,
188
+ treeData : treeResults.data,
189
+ errors : {
190
+ ...lineResults.errors,
191
+ ...treeResults.errors,
192
+ ...filenameResults.errors
193
+ }
194
+ };
195
+ };
196
+
197
+ const getAvailableRulesQty = () => treeRules.length + lineByLineRules.length;
198
+
199
+ const getEnabledLineRules = () => {
200
+ const result = [];
201
+
202
+ for (let i = 0; i < lineByLineRules.length; i++) {
203
+ const rule = lineByLineRules[i];
204
+
205
+ if (rule.isEnabled() && rule.id !== 'lowercase-filename') {
206
+ result.push(rule);
207
+ }
208
+ }
209
+
210
+ return result;
211
+ };
212
+
213
+ const getEnabledTreeRules = () => {
214
+ const result = [];
215
+
216
+ for (let i = 0; i < treeRules.length; i++) {
217
+ const rule = treeRules[i];
218
+
219
+ if (rule.isEnabled()) {
220
+ result.push(rule);
221
+ }
222
+ }
223
+
224
+ return result;
225
+ };
226
+
227
+ module.exports.getAllLineRules = () => lineByLineRules;
228
+ module.exports.findNodeOfType = findNodeOfType;
229
+ module.exports.isTypeAmongTheFirstElements = isTypeAmongTheFirstElements;
230
+ module.exports.checkTemplate = checkTemplate;
231
+ module.exports.checkCustomModules = checkCustomModules;
232
+ module.exports.getAvailableRulesQty = getAvailableRulesQty;