isml-linter 5.43.2 → 5.43.3
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.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/util/RuleUtils.js +1 -1
- package/src/util/TempRuleUtils.js +114 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [5.43.3] - 2023-02-20
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Issue that blocked process due to a missing return value in some rules;
|
|
7
|
+
|
|
3
8
|
## [5.43.2] - 2023-02-12
|
|
4
9
|
|
|
5
10
|
### Security
|
|
@@ -1098,6 +1103,7 @@
|
|
|
1098
1103
|
### Added
|
|
1099
1104
|
- Linter is published;
|
|
1100
1105
|
|
|
1106
|
+
[5.43.3]: https://github.com/FabiowQuixada/isml-linter/compare/v5.43.2...v5.43.3
|
|
1101
1107
|
[5.43.2]: https://github.com/FabiowQuixada/isml-linter/compare/v5.43.1...v5.43.2
|
|
1102
1108
|
[5.43.1]: https://github.com/FabiowQuixada/isml-linter/compare/v5.43.0...v5.43.1
|
|
1103
1109
|
[5.43.0]: https://github.com/FabiowQuixada/isml-linter/compare/v5.42.4...v5.43.0
|
package/package.json
CHANGED
package/src/util/RuleUtils.js
CHANGED
|
@@ -96,7 +96,7 @@ const fixTemplateOrReportIssuesForRuleList = (ruleArray, templatePath, rootNodeO
|
|
|
96
96
|
const ruleResults = rule.check(tempRootNodeOrTemplateContent, templateResults.data);
|
|
97
97
|
templateResults.finalContent = ruleResults.fixedContent;
|
|
98
98
|
|
|
99
|
-
if (typeof rootNodeOrTemplateContent === 'string') {
|
|
99
|
+
if (ruleResults.fixedContent && typeof rootNodeOrTemplateContent === 'string') {
|
|
100
100
|
tempRootNodeOrTemplateContent = ruleResults.fixedContent;
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
===========================================================================
|
|
7
7
|
**/
|
|
8
8
|
|
|
9
|
+
const path = require('path');
|
|
9
10
|
const fs = require('fs');
|
|
10
11
|
const Constants = require('../Constants');
|
|
11
12
|
const TreeBuilder = require('../isml_tree/TreeBuilder');
|
|
@@ -13,10 +14,41 @@ const ConfigUtils = require('./ConfigUtils');
|
|
|
13
14
|
const lowercaseFilenameRule = require('../rules/line_by_line/lowercase-filename');
|
|
14
15
|
const CustomTagContainer = require('./CustomTagContainer');
|
|
15
16
|
const CustomModulesRule = require('../rules/tree/custom-tags');
|
|
17
|
+
const ConsoleUtils = require('./ConsoleUtils');
|
|
18
|
+
const ExceptionUtils = require('./ExceptionUtils');
|
|
16
19
|
|
|
17
20
|
const lineByLineRules = [];
|
|
18
21
|
const treeRules = [];
|
|
19
22
|
|
|
23
|
+
(() => {
|
|
24
|
+
const lineRuleFileArray = fs.readdirSync(Constants.lineByLineRulesDir);
|
|
25
|
+
const treeRuleFileArray = fs.readdirSync(Constants.treeRulesDir);
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < lineRuleFileArray.length; i++) {
|
|
28
|
+
const file = lineRuleFileArray[i];
|
|
29
|
+
|
|
30
|
+
if (file.endsWith('.js')) {
|
|
31
|
+
const rulePath = path.join(__dirname, '..', 'rules', 'line_by_line', file);
|
|
32
|
+
lineByLineRules.push(require(rulePath));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < treeRuleFileArray.length; i++) {
|
|
37
|
+
const file = treeRuleFileArray[i];
|
|
38
|
+
|
|
39
|
+
if (file.endsWith('.js')) {
|
|
40
|
+
const rulePath = path.join(__dirname, '..', 'rules', 'tree', file);
|
|
41
|
+
treeRules.push(require(rulePath));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
|
|
46
|
+
const getLevelGroup = level => {
|
|
47
|
+
return level === 'errors' ? 'errors' :
|
|
48
|
+
level === 'warning' ? 'warnings' :
|
|
49
|
+
'info';
|
|
50
|
+
};
|
|
51
|
+
|
|
20
52
|
const checkCustomTag = tag => {
|
|
21
53
|
if (Object.prototype.hasOwnProperty.call(CustomTagContainer, tag)) {
|
|
22
54
|
const attrList = CustomTagContainer[tag].attrList;
|
|
@@ -25,12 +57,14 @@ const checkCustomTag = tag => {
|
|
|
25
57
|
const attr = attrList[i];
|
|
26
58
|
if (attr !== attr.toLowerCase()) {
|
|
27
59
|
return {
|
|
28
|
-
line
|
|
29
|
-
globalPos
|
|
30
|
-
length
|
|
31
|
-
lineNumber
|
|
32
|
-
|
|
33
|
-
|
|
60
|
+
line : '',
|
|
61
|
+
globalPos : 0,
|
|
62
|
+
length : 10,
|
|
63
|
+
lineNumber : 1,
|
|
64
|
+
columnNumber : 1,
|
|
65
|
+
level : CustomModulesRule.level,
|
|
66
|
+
rule : CustomModulesRule.id,
|
|
67
|
+
message : `Module properties need to be lower case: "${tag}" module has the invalid "${attr}" attribute`
|
|
34
68
|
};
|
|
35
69
|
}
|
|
36
70
|
}
|
|
@@ -43,22 +77,42 @@ const fixTemplateOrReportIssues = (config, ruleResult, templatePath, templateRes
|
|
|
43
77
|
templateResults.fixed = true;
|
|
44
78
|
}
|
|
45
79
|
else if (ruleResult.occurrenceList && ruleResult.occurrenceList.length) {
|
|
46
|
-
const occurrenceObj
|
|
47
|
-
|
|
80
|
+
const occurrenceObj = getOccurrenceObj(rule, ruleResult.occurrenceList);
|
|
81
|
+
|
|
82
|
+
templateResults.errors = Object.assign(templateResults.errors, occurrenceObj.errors);
|
|
83
|
+
templateResults.warnings = Object.assign(templateResults.warnings, occurrenceObj.warnings);
|
|
84
|
+
templateResults.info = Object.assign(templateResults.info, occurrenceObj.info);
|
|
48
85
|
}
|
|
49
86
|
};
|
|
50
87
|
|
|
51
|
-
const fixTemplateOrReportIssuesForRuleList = (ruleArray, templatePath,
|
|
88
|
+
const fixTemplateOrReportIssuesForRuleList = (ruleArray, templatePath, rootNodeOrTemplateContent, config, data) => {
|
|
52
89
|
const templateResults = {
|
|
53
|
-
fixed
|
|
54
|
-
errors
|
|
90
|
+
fixed : false,
|
|
91
|
+
errors : {},
|
|
92
|
+
warnings : {},
|
|
93
|
+
info : {},
|
|
94
|
+
data
|
|
55
95
|
};
|
|
56
96
|
|
|
97
|
+
let tempRootNodeOrTemplateContent = rootNodeOrTemplateContent;
|
|
98
|
+
|
|
57
99
|
for (let i = 0; i < ruleArray.length; i++) {
|
|
58
100
|
const rule = ruleArray[i];
|
|
59
101
|
if (!rule.shouldIgnore(templatePath)) {
|
|
60
|
-
|
|
61
|
-
|
|
102
|
+
try {
|
|
103
|
+
ConsoleUtils.displayVerboseMessage(`Applying "${rule.id}" rule`, 1);
|
|
104
|
+
const ruleResults = rule.check(tempRootNodeOrTemplateContent, templateResults.data);
|
|
105
|
+
templateResults.finalContent = ruleResults.fixedContent;
|
|
106
|
+
|
|
107
|
+
if (ruleResults.fixedContent && typeof rootNodeOrTemplateContent === 'string') {
|
|
108
|
+
tempRootNodeOrTemplateContent = ruleResults.fixedContent;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fixTemplateOrReportIssues(config, ruleResults, templatePath, templateResults, rule);
|
|
112
|
+
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw ExceptionUtils.ruleApplianceError(rule, error, templatePath);
|
|
115
|
+
}
|
|
62
116
|
}
|
|
63
117
|
}
|
|
64
118
|
|
|
@@ -72,10 +126,10 @@ const findNodeOfType = (node, type) => {
|
|
|
72
126
|
if (child.isOfType(type)) {
|
|
73
127
|
result = child;
|
|
74
128
|
return true;
|
|
75
|
-
} else {
|
|
76
|
-
result = findNodeOfType(child, type) || result;
|
|
77
129
|
}
|
|
78
130
|
|
|
131
|
+
result = findNodeOfType(child, type) || result;
|
|
132
|
+
|
|
79
133
|
return false;
|
|
80
134
|
});
|
|
81
135
|
|
|
@@ -95,9 +149,7 @@ const isTypeAmongTheFirstElements = (rootNode, type) => {
|
|
|
95
149
|
};
|
|
96
150
|
|
|
97
151
|
const getOccurrenceObj = (rule, occurrenceArray) => {
|
|
98
|
-
const occurrenceGroup = rule.level
|
|
99
|
-
rule.level === 'warning' ? 'warnings' :
|
|
100
|
-
'info';
|
|
152
|
+
const occurrenceGroup = getLevelGroup(rule.level);
|
|
101
153
|
|
|
102
154
|
const occurrenceObj = {};
|
|
103
155
|
occurrenceObj[occurrenceGroup] = {};
|
|
@@ -112,25 +164,29 @@ const getOccurrenceObj = (rule, occurrenceArray) => {
|
|
|
112
164
|
};
|
|
113
165
|
|
|
114
166
|
const checkFileName = (filename, templateContent) => {
|
|
167
|
+
const occurrenceGroup = getLevelGroup(lowercaseFilenameRule.level);
|
|
115
168
|
const templateResults = {
|
|
116
|
-
fixed
|
|
117
|
-
errors
|
|
169
|
+
fixed : false,
|
|
170
|
+
errors : {},
|
|
171
|
+
warnings : {},
|
|
172
|
+
info : {}
|
|
118
173
|
};
|
|
119
174
|
|
|
120
175
|
if (lowercaseFilenameRule.isEnabled()) {
|
|
121
176
|
const ruleResult = lowercaseFilenameRule.check(filename, templateContent);
|
|
122
177
|
|
|
123
|
-
if (ruleResult) {
|
|
124
|
-
const occurrenceObj
|
|
125
|
-
templateResults
|
|
178
|
+
if (ruleResult.occurrenceList.length > 0) {
|
|
179
|
+
const occurrenceObj = getOccurrenceObj(lowercaseFilenameRule, ruleResult.occurrenceList);
|
|
180
|
+
templateResults[occurrenceGroup] = Object.assign(templateResults[occurrenceGroup], occurrenceObj[occurrenceGroup]);
|
|
126
181
|
}
|
|
127
182
|
}
|
|
128
183
|
|
|
129
184
|
return templateResults;
|
|
130
185
|
};
|
|
131
186
|
|
|
132
|
-
const checkAndPossiblyFixTreeRules = (templatePath, templateContent, config) => {
|
|
187
|
+
const checkAndPossiblyFixTreeRules = (templatePath, templateContent, config, data) => {
|
|
133
188
|
if (!config.disableTreeParse) {
|
|
189
|
+
ConsoleUtils.displayVerboseMessage(`Building tree for "${templatePath}"`, 1);
|
|
134
190
|
const tree = TreeBuilder.build(templatePath, templateContent);
|
|
135
191
|
|
|
136
192
|
if (!tree.rootNode) {
|
|
@@ -143,31 +199,36 @@ const checkAndPossiblyFixTreeRules = (templatePath, templateContent, config) =>
|
|
|
143
199
|
ruleArray,
|
|
144
200
|
templatePath,
|
|
145
201
|
tree.rootNode,
|
|
146
|
-
config
|
|
202
|
+
config,
|
|
203
|
+
data);
|
|
147
204
|
}
|
|
148
205
|
};
|
|
149
206
|
|
|
150
|
-
const checkAndPossiblyFixLineByLineRules = (templatePath, templateContent, config) => {
|
|
207
|
+
const checkAndPossiblyFixLineByLineRules = (templatePath, templateContent, config, data) => {
|
|
151
208
|
const ruleArray = getEnabledLineRules();
|
|
152
209
|
|
|
153
210
|
return fixTemplateOrReportIssuesForRuleList(
|
|
154
211
|
ruleArray,
|
|
155
212
|
templatePath,
|
|
156
213
|
templateContent,
|
|
157
|
-
config
|
|
214
|
+
config,
|
|
215
|
+
data);
|
|
158
216
|
};
|
|
159
217
|
|
|
160
218
|
const checkCustomModules = () => {
|
|
161
|
-
const
|
|
162
|
-
|
|
219
|
+
const occurrenceGroup = getLevelGroup(CustomModulesRule.level);
|
|
220
|
+
const moduleResults = {
|
|
221
|
+
errors : [],
|
|
222
|
+
warnings : [],
|
|
223
|
+
info : []
|
|
163
224
|
};
|
|
164
225
|
|
|
165
226
|
if (CustomModulesRule.isEnabled()) {
|
|
166
227
|
for (const tag in CustomTagContainer) {
|
|
167
|
-
const
|
|
228
|
+
const occurrenceObj = checkCustomTag(tag);
|
|
168
229
|
|
|
169
|
-
if (
|
|
170
|
-
moduleResults.
|
|
230
|
+
if (occurrenceObj) {
|
|
231
|
+
moduleResults[occurrenceGroup].push(occurrenceObj);
|
|
171
232
|
}
|
|
172
233
|
}
|
|
173
234
|
}
|
|
@@ -175,11 +236,12 @@ const checkCustomModules = () => {
|
|
|
175
236
|
return moduleResults;
|
|
176
237
|
};
|
|
177
238
|
|
|
178
|
-
const parseAndPossiblyFixTemplate = (templatePath, content, templateName) => {
|
|
239
|
+
const parseAndPossiblyFixTemplate = (templatePath, data, content = '', templateName = '') => {
|
|
240
|
+
ConsoleUtils.displayVerboseMessage(`\nChecking "${templatePath}" template`);
|
|
179
241
|
const config = ConfigUtils.load();
|
|
180
242
|
const templateContent = content || fs.readFileSync(templatePath, 'utf-8');
|
|
181
|
-
const lineResults = checkAndPossiblyFixLineByLineRules(templatePath, templateContent, config);
|
|
182
|
-
const treeResults = checkAndPossiblyFixTreeRules(templatePath,
|
|
243
|
+
const lineResults = checkAndPossiblyFixLineByLineRules(templatePath, templateContent, config, data);
|
|
244
|
+
const treeResults = checkAndPossiblyFixTreeRules(templatePath, lineResults.finalContent, config, data) || { errors : [] };
|
|
183
245
|
const filenameResults = checkFileName(templateName, templateContent);
|
|
184
246
|
|
|
185
247
|
return {
|
|
@@ -189,6 +251,16 @@ const parseAndPossiblyFixTemplate = (templatePath, content, templateName) => {
|
|
|
189
251
|
...lineResults.errors,
|
|
190
252
|
...treeResults.errors,
|
|
191
253
|
...filenameResults.errors
|
|
254
|
+
},
|
|
255
|
+
warnings : {
|
|
256
|
+
...lineResults.warnings,
|
|
257
|
+
...treeResults.warnings,
|
|
258
|
+
...filenameResults.warnings
|
|
259
|
+
},
|
|
260
|
+
info : {
|
|
261
|
+
...lineResults.info,
|
|
262
|
+
...treeResults.info,
|
|
263
|
+
...filenameResults.info
|
|
192
264
|
}
|
|
193
265
|
};
|
|
194
266
|
};
|
|
@@ -201,6 +273,9 @@ const getEnabledLineRules = () => {
|
|
|
201
273
|
for (let i = 0; i < lineByLineRules.length; i++) {
|
|
202
274
|
const rule = lineByLineRules[i];
|
|
203
275
|
|
|
276
|
+
// TODO Do this in a better way;
|
|
277
|
+
rule.level = rule.getConfigs().level || 'errors';
|
|
278
|
+
|
|
204
279
|
if (rule.isEnabled() && rule.id !== 'lowercase-filename') {
|
|
205
280
|
result.push(rule);
|
|
206
281
|
}
|
|
@@ -215,6 +290,9 @@ const getEnabledTreeRules = () => {
|
|
|
215
290
|
for (let i = 0; i < treeRules.length; i++) {
|
|
216
291
|
const rule = treeRules[i];
|
|
217
292
|
|
|
293
|
+
// TODO Do this in a better way;
|
|
294
|
+
rule.level = rule.getConfigs().level || 'errors';
|
|
295
|
+
|
|
218
296
|
if (rule.isEnabled()) {
|
|
219
297
|
result.push(rule);
|
|
220
298
|
}
|
|
@@ -229,3 +307,4 @@ module.exports.isTypeAmongTheFirstElements = isTypeAmongTheFirstElements;
|
|
|
229
307
|
module.exports.parseAndPossiblyFixTemplate = parseAndPossiblyFixTemplate;
|
|
230
308
|
module.exports.checkCustomModules = checkCustomModules;
|
|
231
309
|
module.exports.getAvailableRulesQty = getAvailableRulesQty;
|
|
310
|
+
module.exports.getLevelGroup = getLevelGroup;
|