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.
- package/CHANGELOG.md +1167 -1133
- package/LICENSE +21 -21
- package/README.md +245 -245
- package/bin/isml-linter.js +32 -32
- package/ismllinter.config.js +33 -33
- package/package.json +53 -53
- package/scaffold_files/ismllinter.config.js +47 -47
- package/src/Builder.js +15 -15
- package/src/Constants.js +139 -139
- package/src/IsmlLinter.js +255 -255
- package/src/enums/ParseStatus.js +5 -5
- package/src/enums/SfccTagContainer.js +287 -287
- package/src/isml_tree/ContainerNode.js +38 -38
- package/src/isml_tree/IsmlNode.js +684 -658
- package/src/isml_tree/MaskUtils.js +421 -419
- package/src/isml_tree/ParseUtils.js +514 -434
- package/src/isml_tree/TreeBuilder.js +273 -271
- package/src/publicApi.js +24 -24
- package/src/rules/line_by_line/enforce-isprint.js +53 -53
- package/src/rules/line_by_line/enforce-require.js +35 -35
- package/src/rules/line_by_line/lowercase-filename.js +29 -29
- package/src/rules/line_by_line/max-lines.js +37 -37
- package/src/rules/line_by_line/no-br.js +36 -36
- package/src/rules/line_by_line/no-git-conflict.js +43 -43
- package/src/rules/line_by_line/no-import-package.js +34 -34
- package/src/rules/line_by_line/no-inline-style.js +34 -34
- package/src/rules/line_by_line/no-isscript.js +34 -34
- package/src/rules/line_by_line/no-space-only-lines.js +47 -47
- package/src/rules/line_by_line/no-tabs.js +38 -38
- package/src/rules/line_by_line/no-trailing-spaces.js +52 -52
- package/src/rules/prototypes/RulePrototype.js +79 -79
- package/src/rules/prototypes/SingleLineRulePrototype.js +47 -47
- package/src/rules/prototypes/TreeRulePrototype.js +84 -84
- package/src/rules/tree/align-isset.js +87 -87
- package/src/rules/tree/contextual-attrs.js +105 -105
- package/src/rules/tree/custom-tags.js +54 -54
- package/src/rules/tree/disallow-tags.js +39 -39
- package/src/rules/tree/empty-eof.js +66 -66
- package/src/rules/tree/enforce-security.js +85 -85
- package/src/rules/tree/eslint-to-isscript.js +179 -179
- package/src/rules/tree/indent.js +853 -853
- package/src/rules/tree/leading-iscache.js +39 -43
- package/src/rules/tree/leading-iscontent.js +35 -39
- package/src/rules/tree/max-depth.js +54 -54
- package/src/rules/tree/no-deprecated-attrs.js +67 -67
- package/src/rules/tree/no-embedded-isml.js +17 -17
- package/src/rules/tree/no-hardcode.js +51 -51
- package/src/rules/tree/no-iselse-slash.js +35 -35
- package/src/rules/tree/no-redundant-context.js +134 -134
- package/src/rules/tree/no-require-in-loop.js +63 -63
- package/src/rules/tree/one-element-per-line.js +76 -76
- package/src/util/CommandLineUtils.js +19 -19
- package/src/util/ConfigUtils.js +219 -219
- package/src/util/ConsoleUtils.js +327 -327
- package/src/util/CustomTagContainer.js +45 -45
- package/src/util/ExceptionUtils.js +149 -131
- package/src/util/FileUtils.js +79 -79
- package/src/util/GeneralUtils.js +60 -60
- package/src/util/NativeExtensionUtils.js +6 -6
- package/src/util/RuleUtils.js +295 -295
- package/src/util/TempRuleUtils.js +232 -232
package/src/util/ConsoleUtils.js
CHANGED
|
@@ -1,327 +1,327 @@
|
|
|
1
|
-
const chalk = require('chalk');
|
|
2
|
-
const Constants = require('../Constants');
|
|
3
|
-
const ExceptionUtils = require('./ExceptionUtils');
|
|
4
|
-
const ConfigUtils = require('./ConfigUtils');
|
|
5
|
-
|
|
6
|
-
const MAX_LISTED_ERRORS = 30;
|
|
7
|
-
|
|
8
|
-
const printExceptionMsg = e => {
|
|
9
|
-
if (!e.isCustom) {
|
|
10
|
-
console.log();
|
|
11
|
-
console.log('An error has occurred:');
|
|
12
|
-
console.log(e.stack || e);
|
|
13
|
-
console.log('If you think this is a bug, please open an issue at:');
|
|
14
|
-
console.log(`${Constants.EOL}${Constants.repositoryUrl}${Constants.EOL}${Constants.EOL}`);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const displayLintingOccurrenceList = lintResult => {
|
|
19
|
-
|
|
20
|
-
const config = ConfigUtils.load();
|
|
21
|
-
const occurrenceLevels = Constants.occurrenceLevels.toArray();
|
|
22
|
-
const errorData = getErrorsData(lintResult);
|
|
23
|
-
const warningData = getWarningsData(lintResult);
|
|
24
|
-
const infoData = getInfoData(lintResult);
|
|
25
|
-
|
|
26
|
-
const data = {
|
|
27
|
-
error : {
|
|
28
|
-
messages : errorData.outputMsgList,
|
|
29
|
-
qty : errorData.qty
|
|
30
|
-
},
|
|
31
|
-
warning : {
|
|
32
|
-
messages : warningData.outputMsgList,
|
|
33
|
-
qty : warningData.qty
|
|
34
|
-
},
|
|
35
|
-
info : {
|
|
36
|
-
messages : infoData.outputMsgList,
|
|
37
|
-
qty : infoData.qty
|
|
38
|
-
},
|
|
39
|
-
total : errorData.qty + warningData.qty + infoData.qty
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
for (let j = 0; j < occurrenceLevels.length; j++) {
|
|
43
|
-
const occurrenceGroup = occurrenceLevels[j];
|
|
44
|
-
|
|
45
|
-
if (data[occurrenceGroup].qty > 0) {
|
|
46
|
-
for (let i = 0; i < data[occurrenceGroup].messages.length; i++) {
|
|
47
|
-
if (config.printPartialResults && i > MAX_LISTED_ERRORS) {
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
console.log(data[occurrenceGroup].messages[i]);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return data;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const displayUnparseableErrors = lintResult => {
|
|
59
|
-
|
|
60
|
-
const config = ConfigUtils.load();
|
|
61
|
-
let partialSum = 0;
|
|
62
|
-
|
|
63
|
-
if (!config.ignoreUnparseable) {
|
|
64
|
-
|
|
65
|
-
const INVALID_TEMPLATE = ExceptionUtils.types.INVALID_TEMPLATE;
|
|
66
|
-
|
|
67
|
-
if (lintResult[INVALID_TEMPLATE] && lintResult[INVALID_TEMPLATE].length > 0) {
|
|
68
|
-
console.log(chalk`{red.bold ${Constants.EOL}An Isml abstract syntax tree could not be built for the following templates:}`);
|
|
69
|
-
|
|
70
|
-
for (let i = 0; i < lintResult[INVALID_TEMPLATE].length; i++) {
|
|
71
|
-
if (config.printPartialResults && i > MAX_LISTED_ERRORS) {
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const error = lintResult[INVALID_TEMPLATE][i];
|
|
76
|
-
console.log(chalk.gray(i) + ' ' + error.templatePath + ':' + error.lineNumber);
|
|
77
|
-
console.log('\t' + chalk`{red.bold >> }` + `${error.message}${Constants.EOL}`);
|
|
78
|
-
partialSum++;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return partialSum;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const displayRuleErrors = lintResult => {
|
|
87
|
-
|
|
88
|
-
const RULE_ERROR = ExceptionUtils.types.RULE_ERROR;
|
|
89
|
-
const config = ConfigUtils.load();
|
|
90
|
-
let partialSum = 0;
|
|
91
|
-
|
|
92
|
-
if (lintResult[RULE_ERROR] && lintResult[RULE_ERROR].length > 0) {
|
|
93
|
-
console.log(chalk`{red.bold ${Constants.EOL}An unexpected error occurred while applying rules to the following templates:}`);
|
|
94
|
-
|
|
95
|
-
for (let i = 0; i < lintResult[RULE_ERROR].length; i++) {
|
|
96
|
-
if (config.printPartialResults && i > MAX_LISTED_ERRORS) {
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const error = lintResult[RULE_ERROR][i];
|
|
101
|
-
console.log(chalk.gray(i) + '\t' + error.ruleID + ' :\t' + error.templatePath);
|
|
102
|
-
partialSum++;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return partialSum;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const displayUnknownErrors = lintResult => {
|
|
110
|
-
const UNKNOWN_ERROR = ExceptionUtils.types.UNKNOWN_ERROR;
|
|
111
|
-
let partialSum = 0;
|
|
112
|
-
|
|
113
|
-
if (lintResult[UNKNOWN_ERROR] && lintResult[UNKNOWN_ERROR].length > 0) {
|
|
114
|
-
console.log(chalk`{red.bold ${Constants.EOL}An unexpected error happened while parsing the following templates:}`);
|
|
115
|
-
|
|
116
|
-
const unknownErrorArray = lintResult[UNKNOWN_ERROR];
|
|
117
|
-
|
|
118
|
-
for (let i = 0; i < unknownErrorArray.length; i++) {
|
|
119
|
-
console.log(chalk.gray(i) + '\t' + unknownErrorArray[i]);
|
|
120
|
-
partialSum++;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
console.log(`${Constants.EOL}Please check if your node version is >=10.0.0. If it is, please report the above issues to ${chalk.cyan(Constants.repositoryUrl + '/issues')} and add these files to the ignore list while a fix is not available.`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return partialSum;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const displayOccurrenceList = lintResult => {
|
|
130
|
-
|
|
131
|
-
displayUnparseableErrors(lintResult);
|
|
132
|
-
displayUnknownErrors(lintResult);
|
|
133
|
-
displayRuleErrors(lintResult);
|
|
134
|
-
|
|
135
|
-
// TODO Add this 'config' as a global const;
|
|
136
|
-
const config = ConfigUtils.load();
|
|
137
|
-
const occurrenceList = displayLintingOccurrenceList(lintResult);
|
|
138
|
-
|
|
139
|
-
const isThereAnyOccurrence = occurrenceList.error.qty > 0 ||
|
|
140
|
-
occurrenceList.warning.qty > 0 ||
|
|
141
|
-
occurrenceList.info.qty > 0 ||
|
|
142
|
-
lintResult.INVALID_TEMPLATE && lintResult.INVALID_TEMPLATE.length > 0 ||
|
|
143
|
-
lintResult.UNKNOWN_ERROR && lintResult.UNKNOWN_ERROR.length > 0;
|
|
144
|
-
|
|
145
|
-
if (isThereAnyOccurrence) {
|
|
146
|
-
|
|
147
|
-
console.log(Constants.EOL + '=====================================================');
|
|
148
|
-
console.log(Constants.EOL + chalk`{bold Linted ${lintResult.totalTemplatesQty} templates in ${lintResult.elapsedTime} seconds.}`);
|
|
149
|
-
|
|
150
|
-
if (occurrenceList.error.qty > 0) {
|
|
151
|
-
console.log(chalk`{bold ${occurrenceList.error.qty} error(s) found.}`);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (occurrenceList.warning.qty > 0) {
|
|
155
|
-
console.log(chalk`{bold ${occurrenceList.warning.qty} warning(s) found.}`);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (occurrenceList.info.qty > 0) {
|
|
159
|
-
console.log(chalk`{bold ${occurrenceList.info.qty} info(s) found.}`);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (lintResult.INVALID_TEMPLATE && lintResult.INVALID_TEMPLATE.length > 0) {
|
|
163
|
-
console.log(chalk`{bold ${lintResult.INVALID_TEMPLATE.length} template(s) have an invalid ISML tree.}`);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (lintResult.UNKNOWN_ERROR && lintResult.UNKNOWN_ERROR.length > 0) {
|
|
167
|
-
if (lintResult.UNKNOWN_ERROR.length > 1) {
|
|
168
|
-
console.log(chalk`{bold There were ${lintResult.UNKNOWN_ERROR.length} unknown errors while parsing templates.}`);
|
|
169
|
-
} else {
|
|
170
|
-
console.log(chalk`{bold There was 1 unknown error while parsing templates.}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (config.printPartialResults) {
|
|
175
|
-
console.log(chalk`{bold Displaying the first ${MAX_LISTED_ERRORS} occurrences of each group.}` + Constants.EOL);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const displayInvalidTemplatesPaths = templatePathArray => {
|
|
181
|
-
console.log(Constants.EOL + chalk`{red.bold Could not find the following templates:}`);
|
|
182
|
-
|
|
183
|
-
for (let i = 0; i < templatePathArray.length; i++) {
|
|
184
|
-
const invalidPath = templatePathArray[i];
|
|
185
|
-
console.log(chalk.gray(i) + '\t' + invalidPath);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
console.log(Constants.EOL);
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const displayConfigError = () => {
|
|
192
|
-
console.log('No configuration found. Please run the following command to create a default configuration file:');
|
|
193
|
-
console.log(Constants.EOL + '\t' + chalk.yellow('./node_modules/.bin/isml-linter --init') + Constants.EOL);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
const displayInvalidCommandError = () => {
|
|
197
|
-
console.log('\nInvalid command detected. Please use the following format:');
|
|
198
|
-
console.log(Constants.EOL + '\t' + chalk.yellow('./node_modules/.bin/isml-linter [options] [file|dir]*') + Constants.EOL);
|
|
199
|
-
console.log('For example:');
|
|
200
|
-
console.log(Constants.EOL + '\t' + chalk.yellow('./node_modules/.bin/isml-linter --autofix template1.isml directory1/ directory2/') + Constants.EOL);
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const displayEslintConfigError = () => {
|
|
204
|
-
const config = ConfigUtils.load();
|
|
205
|
-
const eslintConfigFileName = config.eslintConfig;
|
|
206
|
-
|
|
207
|
-
console.log(`The "eslint-to-isscript" rule is enabled, but an ESLint configuration file ${eslintConfigFileName ? '"' + eslintConfigFileName + '" ' : ''}could not be found in the project root directory.'`);
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const getErrorsData = lintResult => {
|
|
211
|
-
const outputMsgList = [];
|
|
212
|
-
let qty = 0;
|
|
213
|
-
|
|
214
|
-
outputMsgList.push(chalk`{red.bold ${Constants.EOL}The following linting errors were found in the templates:}`);
|
|
215
|
-
|
|
216
|
-
for (const rule in lintResult.errors) {
|
|
217
|
-
for (const template in lintResult.errors[rule]) {
|
|
218
|
-
outputMsgList.push(Constants.EOL + template);
|
|
219
|
-
|
|
220
|
-
const occurrenceList = lintResult.errors[rule][template];
|
|
221
|
-
|
|
222
|
-
for (let i = 0; i < occurrenceList.length; i++) {
|
|
223
|
-
const occurrence = occurrenceList[i];
|
|
224
|
-
|
|
225
|
-
outputMsgList.push(
|
|
226
|
-
chalk.gray(occurrence.lineNumber) + '\t' +
|
|
227
|
-
chalk.red('error') + '\t' +
|
|
228
|
-
occurrence.message
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
qty++;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
outputMsgList,
|
|
238
|
-
qty
|
|
239
|
-
};
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
const getWarningsData = lintResult => {
|
|
243
|
-
const outputMsgList = [];
|
|
244
|
-
let qty = 0;
|
|
245
|
-
|
|
246
|
-
outputMsgList.push(chalk`{yellow.bold ${Constants.EOL}The following linting warnings were found in the templates:}`);
|
|
247
|
-
|
|
248
|
-
for (const rule in lintResult.warnings) {
|
|
249
|
-
for (const template in lintResult.warnings[rule]) {
|
|
250
|
-
outputMsgList.push(Constants.EOL + template);
|
|
251
|
-
|
|
252
|
-
const occurrenceList = lintResult.warnings[rule][template];
|
|
253
|
-
|
|
254
|
-
for (let i = 0; i < occurrenceList.length; i++) {
|
|
255
|
-
const occurrence = occurrenceList[i];
|
|
256
|
-
|
|
257
|
-
outputMsgList.push(
|
|
258
|
-
chalk.gray(occurrence.lineNumber) + '\t' +
|
|
259
|
-
chalk.yellow('warning') + '\t' +
|
|
260
|
-
occurrence.message
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
qty++;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return {
|
|
269
|
-
outputMsgList,
|
|
270
|
-
qty
|
|
271
|
-
};
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const getInfoData = lintResult => {
|
|
275
|
-
const outputMsgList = [];
|
|
276
|
-
let qty = 0;
|
|
277
|
-
|
|
278
|
-
outputMsgList.push(chalk`{cyan.bold ${Constants.EOL}The following linting info items were found in the templates:}`);
|
|
279
|
-
|
|
280
|
-
for (const rule in lintResult.info) {
|
|
281
|
-
for (const template in lintResult.info[rule]) {
|
|
282
|
-
outputMsgList.push(Constants.EOL + template);
|
|
283
|
-
|
|
284
|
-
const occurrenceList = lintResult.info[rule][template];
|
|
285
|
-
|
|
286
|
-
for (let i = 0; i < occurrenceList.length; i++) {
|
|
287
|
-
const occurrence = occurrenceList[i];
|
|
288
|
-
|
|
289
|
-
outputMsgList.push(
|
|
290
|
-
chalk.gray(occurrence.lineNumber) + '\t' +
|
|
291
|
-
chalk.cyan('info') + '\t' +
|
|
292
|
-
occurrence.message
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
qty++;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return {
|
|
301
|
-
outputMsgList,
|
|
302
|
-
qty
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
const displayVerboseMessage = (message, depth = 0) => {
|
|
307
|
-
const config = ConfigUtils.load();
|
|
308
|
-
let indentation = '';
|
|
309
|
-
|
|
310
|
-
for (let i = 0; i < depth; i++) {
|
|
311
|
-
indentation += ' ';
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (config.verbose) {
|
|
315
|
-
console.log(indentation + message);
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
module.exports = {
|
|
320
|
-
displayOccurrenceList,
|
|
321
|
-
displayConfigError,
|
|
322
|
-
displayEslintConfigError,
|
|
323
|
-
displayInvalidTemplatesPaths,
|
|
324
|
-
displayInvalidCommandError,
|
|
325
|
-
printExceptionMsg,
|
|
326
|
-
displayVerboseMessage
|
|
327
|
-
};
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
const Constants = require('../Constants');
|
|
3
|
+
const ExceptionUtils = require('./ExceptionUtils');
|
|
4
|
+
const ConfigUtils = require('./ConfigUtils');
|
|
5
|
+
|
|
6
|
+
const MAX_LISTED_ERRORS = 30;
|
|
7
|
+
|
|
8
|
+
const printExceptionMsg = e => {
|
|
9
|
+
if (!e.isCustom) {
|
|
10
|
+
console.log();
|
|
11
|
+
console.log('An error has occurred:');
|
|
12
|
+
console.log(e.stack || e);
|
|
13
|
+
console.log('If you think this is a bug, please open an issue at:');
|
|
14
|
+
console.log(`${Constants.EOL}${Constants.repositoryUrl}${Constants.EOL}${Constants.EOL}`);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const displayLintingOccurrenceList = lintResult => {
|
|
19
|
+
|
|
20
|
+
const config = ConfigUtils.load();
|
|
21
|
+
const occurrenceLevels = Constants.occurrenceLevels.toArray();
|
|
22
|
+
const errorData = getErrorsData(lintResult);
|
|
23
|
+
const warningData = getWarningsData(lintResult);
|
|
24
|
+
const infoData = getInfoData(lintResult);
|
|
25
|
+
|
|
26
|
+
const data = {
|
|
27
|
+
error : {
|
|
28
|
+
messages : errorData.outputMsgList,
|
|
29
|
+
qty : errorData.qty
|
|
30
|
+
},
|
|
31
|
+
warning : {
|
|
32
|
+
messages : warningData.outputMsgList,
|
|
33
|
+
qty : warningData.qty
|
|
34
|
+
},
|
|
35
|
+
info : {
|
|
36
|
+
messages : infoData.outputMsgList,
|
|
37
|
+
qty : infoData.qty
|
|
38
|
+
},
|
|
39
|
+
total : errorData.qty + warningData.qty + infoData.qty
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
for (let j = 0; j < occurrenceLevels.length; j++) {
|
|
43
|
+
const occurrenceGroup = occurrenceLevels[j];
|
|
44
|
+
|
|
45
|
+
if (data[occurrenceGroup].qty > 0) {
|
|
46
|
+
for (let i = 0; i < data[occurrenceGroup].messages.length; i++) {
|
|
47
|
+
if (config.printPartialResults && i > MAX_LISTED_ERRORS) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
console.log(data[occurrenceGroup].messages[i]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return data;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const displayUnparseableErrors = lintResult => {
|
|
59
|
+
|
|
60
|
+
const config = ConfigUtils.load();
|
|
61
|
+
let partialSum = 0;
|
|
62
|
+
|
|
63
|
+
if (!config.ignoreUnparseable) {
|
|
64
|
+
|
|
65
|
+
const INVALID_TEMPLATE = ExceptionUtils.types.INVALID_TEMPLATE;
|
|
66
|
+
|
|
67
|
+
if (lintResult[INVALID_TEMPLATE] && lintResult[INVALID_TEMPLATE].length > 0) {
|
|
68
|
+
console.log(chalk`{red.bold ${Constants.EOL}An Isml abstract syntax tree could not be built for the following templates:}`);
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < lintResult[INVALID_TEMPLATE].length; i++) {
|
|
71
|
+
if (config.printPartialResults && i > MAX_LISTED_ERRORS) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const error = lintResult[INVALID_TEMPLATE][i];
|
|
76
|
+
console.log(chalk.gray(i) + ' ' + error.templatePath + ':' + error.lineNumber);
|
|
77
|
+
console.log('\t' + chalk`{red.bold >> }` + `${error.message}${Constants.EOL}`);
|
|
78
|
+
partialSum++;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return partialSum;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const displayRuleErrors = lintResult => {
|
|
87
|
+
|
|
88
|
+
const RULE_ERROR = ExceptionUtils.types.RULE_ERROR;
|
|
89
|
+
const config = ConfigUtils.load();
|
|
90
|
+
let partialSum = 0;
|
|
91
|
+
|
|
92
|
+
if (lintResult[RULE_ERROR] && lintResult[RULE_ERROR].length > 0) {
|
|
93
|
+
console.log(chalk`{red.bold ${Constants.EOL}An unexpected error occurred while applying rules to the following templates:}`);
|
|
94
|
+
|
|
95
|
+
for (let i = 0; i < lintResult[RULE_ERROR].length; i++) {
|
|
96
|
+
if (config.printPartialResults && i > MAX_LISTED_ERRORS) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const error = lintResult[RULE_ERROR][i];
|
|
101
|
+
console.log(chalk.gray(i) + '\t' + error.ruleID + ' :\t' + error.templatePath);
|
|
102
|
+
partialSum++;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return partialSum;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const displayUnknownErrors = lintResult => {
|
|
110
|
+
const UNKNOWN_ERROR = ExceptionUtils.types.UNKNOWN_ERROR;
|
|
111
|
+
let partialSum = 0;
|
|
112
|
+
|
|
113
|
+
if (lintResult[UNKNOWN_ERROR] && lintResult[UNKNOWN_ERROR].length > 0) {
|
|
114
|
+
console.log(chalk`{red.bold ${Constants.EOL}An unexpected error happened while parsing the following templates:}`);
|
|
115
|
+
|
|
116
|
+
const unknownErrorArray = lintResult[UNKNOWN_ERROR];
|
|
117
|
+
|
|
118
|
+
for (let i = 0; i < unknownErrorArray.length; i++) {
|
|
119
|
+
console.log(chalk.gray(i) + '\t' + unknownErrorArray[i]);
|
|
120
|
+
partialSum++;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
console.log(`${Constants.EOL}Please check if your node version is >=10.0.0. If it is, please report the above issues to ${chalk.cyan(Constants.repositoryUrl + '/issues')} and add these files to the ignore list while a fix is not available.`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return partialSum;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const displayOccurrenceList = lintResult => {
|
|
130
|
+
|
|
131
|
+
displayUnparseableErrors(lintResult);
|
|
132
|
+
displayUnknownErrors(lintResult);
|
|
133
|
+
displayRuleErrors(lintResult);
|
|
134
|
+
|
|
135
|
+
// TODO Add this 'config' as a global const;
|
|
136
|
+
const config = ConfigUtils.load();
|
|
137
|
+
const occurrenceList = displayLintingOccurrenceList(lintResult);
|
|
138
|
+
|
|
139
|
+
const isThereAnyOccurrence = occurrenceList.error.qty > 0 ||
|
|
140
|
+
occurrenceList.warning.qty > 0 ||
|
|
141
|
+
occurrenceList.info.qty > 0 ||
|
|
142
|
+
lintResult.INVALID_TEMPLATE && lintResult.INVALID_TEMPLATE.length > 0 ||
|
|
143
|
+
lintResult.UNKNOWN_ERROR && lintResult.UNKNOWN_ERROR.length > 0;
|
|
144
|
+
|
|
145
|
+
if (isThereAnyOccurrence) {
|
|
146
|
+
|
|
147
|
+
console.log(Constants.EOL + '=====================================================');
|
|
148
|
+
console.log(Constants.EOL + chalk`{bold Linted ${lintResult.totalTemplatesQty} templates in ${lintResult.elapsedTime} seconds.}`);
|
|
149
|
+
|
|
150
|
+
if (occurrenceList.error.qty > 0) {
|
|
151
|
+
console.log(chalk`{bold ${occurrenceList.error.qty} error(s) found.}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (occurrenceList.warning.qty > 0) {
|
|
155
|
+
console.log(chalk`{bold ${occurrenceList.warning.qty} warning(s) found.}`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (occurrenceList.info.qty > 0) {
|
|
159
|
+
console.log(chalk`{bold ${occurrenceList.info.qty} info(s) found.}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (lintResult.INVALID_TEMPLATE && lintResult.INVALID_TEMPLATE.length > 0) {
|
|
163
|
+
console.log(chalk`{bold ${lintResult.INVALID_TEMPLATE.length} template(s) have an invalid ISML tree.}`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (lintResult.UNKNOWN_ERROR && lintResult.UNKNOWN_ERROR.length > 0) {
|
|
167
|
+
if (lintResult.UNKNOWN_ERROR.length > 1) {
|
|
168
|
+
console.log(chalk`{bold There were ${lintResult.UNKNOWN_ERROR.length} unknown errors while parsing templates.}`);
|
|
169
|
+
} else {
|
|
170
|
+
console.log(chalk`{bold There was 1 unknown error while parsing templates.}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (config.printPartialResults) {
|
|
175
|
+
console.log(chalk`{bold Displaying the first ${MAX_LISTED_ERRORS} occurrences of each group.}` + Constants.EOL);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const displayInvalidTemplatesPaths = templatePathArray => {
|
|
181
|
+
console.log(Constants.EOL + chalk`{red.bold Could not find the following templates:}`);
|
|
182
|
+
|
|
183
|
+
for (let i = 0; i < templatePathArray.length; i++) {
|
|
184
|
+
const invalidPath = templatePathArray[i];
|
|
185
|
+
console.log(chalk.gray(i) + '\t' + invalidPath);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
console.log(Constants.EOL);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const displayConfigError = () => {
|
|
192
|
+
console.log('No configuration found. Please run the following command to create a default configuration file:');
|
|
193
|
+
console.log(Constants.EOL + '\t' + chalk.yellow('./node_modules/.bin/isml-linter --init') + Constants.EOL);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const displayInvalidCommandError = () => {
|
|
197
|
+
console.log('\nInvalid command detected. Please use the following format:');
|
|
198
|
+
console.log(Constants.EOL + '\t' + chalk.yellow('./node_modules/.bin/isml-linter [options] [file|dir]*') + Constants.EOL);
|
|
199
|
+
console.log('For example:');
|
|
200
|
+
console.log(Constants.EOL + '\t' + chalk.yellow('./node_modules/.bin/isml-linter --autofix template1.isml directory1/ directory2/') + Constants.EOL);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const displayEslintConfigError = () => {
|
|
204
|
+
const config = ConfigUtils.load();
|
|
205
|
+
const eslintConfigFileName = config.eslintConfig;
|
|
206
|
+
|
|
207
|
+
console.log(`The "eslint-to-isscript" rule is enabled, but an ESLint configuration file ${eslintConfigFileName ? '"' + eslintConfigFileName + '" ' : ''}could not be found in the project root directory.'`);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const getErrorsData = lintResult => {
|
|
211
|
+
const outputMsgList = [];
|
|
212
|
+
let qty = 0;
|
|
213
|
+
|
|
214
|
+
outputMsgList.push(chalk`{red.bold ${Constants.EOL}The following linting errors were found in the templates:}`);
|
|
215
|
+
|
|
216
|
+
for (const rule in lintResult.errors) {
|
|
217
|
+
for (const template in lintResult.errors[rule]) {
|
|
218
|
+
outputMsgList.push(Constants.EOL + template);
|
|
219
|
+
|
|
220
|
+
const occurrenceList = lintResult.errors[rule][template];
|
|
221
|
+
|
|
222
|
+
for (let i = 0; i < occurrenceList.length; i++) {
|
|
223
|
+
const occurrence = occurrenceList[i];
|
|
224
|
+
|
|
225
|
+
outputMsgList.push(
|
|
226
|
+
chalk.gray(occurrence.lineNumber) + '\t' +
|
|
227
|
+
chalk.red('error') + '\t' +
|
|
228
|
+
occurrence.message
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
qty++;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
outputMsgList,
|
|
238
|
+
qty
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const getWarningsData = lintResult => {
|
|
243
|
+
const outputMsgList = [];
|
|
244
|
+
let qty = 0;
|
|
245
|
+
|
|
246
|
+
outputMsgList.push(chalk`{yellow.bold ${Constants.EOL}The following linting warnings were found in the templates:}`);
|
|
247
|
+
|
|
248
|
+
for (const rule in lintResult.warnings) {
|
|
249
|
+
for (const template in lintResult.warnings[rule]) {
|
|
250
|
+
outputMsgList.push(Constants.EOL + template);
|
|
251
|
+
|
|
252
|
+
const occurrenceList = lintResult.warnings[rule][template];
|
|
253
|
+
|
|
254
|
+
for (let i = 0; i < occurrenceList.length; i++) {
|
|
255
|
+
const occurrence = occurrenceList[i];
|
|
256
|
+
|
|
257
|
+
outputMsgList.push(
|
|
258
|
+
chalk.gray(occurrence.lineNumber) + '\t' +
|
|
259
|
+
chalk.yellow('warning') + '\t' +
|
|
260
|
+
occurrence.message
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
qty++;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
outputMsgList,
|
|
270
|
+
qty
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const getInfoData = lintResult => {
|
|
275
|
+
const outputMsgList = [];
|
|
276
|
+
let qty = 0;
|
|
277
|
+
|
|
278
|
+
outputMsgList.push(chalk`{cyan.bold ${Constants.EOL}The following linting info items were found in the templates:}`);
|
|
279
|
+
|
|
280
|
+
for (const rule in lintResult.info) {
|
|
281
|
+
for (const template in lintResult.info[rule]) {
|
|
282
|
+
outputMsgList.push(Constants.EOL + template);
|
|
283
|
+
|
|
284
|
+
const occurrenceList = lintResult.info[rule][template];
|
|
285
|
+
|
|
286
|
+
for (let i = 0; i < occurrenceList.length; i++) {
|
|
287
|
+
const occurrence = occurrenceList[i];
|
|
288
|
+
|
|
289
|
+
outputMsgList.push(
|
|
290
|
+
chalk.gray(occurrence.lineNumber) + '\t' +
|
|
291
|
+
chalk.cyan('info') + '\t' +
|
|
292
|
+
occurrence.message
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
qty++;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
outputMsgList,
|
|
302
|
+
qty
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const displayVerboseMessage = (message, depth = 0) => {
|
|
307
|
+
const config = ConfigUtils.load();
|
|
308
|
+
let indentation = '';
|
|
309
|
+
|
|
310
|
+
for (let i = 0; i < depth; i++) {
|
|
311
|
+
indentation += ' ';
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (config.verbose) {
|
|
315
|
+
console.log(indentation + message);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
module.exports = {
|
|
320
|
+
displayOccurrenceList,
|
|
321
|
+
displayConfigError,
|
|
322
|
+
displayEslintConfigError,
|
|
323
|
+
displayInvalidTemplatesPaths,
|
|
324
|
+
displayInvalidCommandError,
|
|
325
|
+
printExceptionMsg,
|
|
326
|
+
displayVerboseMessage
|
|
327
|
+
};
|