@iobroker/repochecker 5.15.0 → 5.16.0
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/README.md +11 -0
- package/index.js +1 -0
- package/lib/M0000_PackageJson.js +93 -3
- package/lib/M1000_IOPackageJson.js +9 -124
- package/lib/M2000_Npm.js +2 -1
- package/lib/M3000_Testing.js +7 -6
- package/lib/M5000_Code.js +44 -33
- package/lib/M5500__JsonConfig.js +6 -0
- package/lib/M5600__I18n.js +110 -20
- package/lib/M8000_Github.js +4 -0
- package/lib/config.js +11 -1
- package/lib/config_StateRoles.js +1127 -0
- package/lib/postprocessing.js +3 -0
- package/package.json +1 -1
package/lib/M5600__I18n.js
CHANGED
|
@@ -25,6 +25,60 @@ const TRANSLATABLE_ATTRS = [
|
|
|
25
25
|
'placeholder',
|
|
26
26
|
'validatorErrorText',
|
|
27
27
|
];
|
|
28
|
+
const MAX_W5612_WARNINGS = 10;
|
|
29
|
+
const MAX_56XX_ISSUES_PER_CODE = 10;
|
|
30
|
+
const ISSUE_CODE_56XX_REGEX = /^\[((?:E|W|S)56\d{2})\]/;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Limit every E/W/S56xx issue code in the list to MAX_56XX_ISSUES_PER_CODE messages
|
|
34
|
+
* plus one additional "maximum reached" message.
|
|
35
|
+
*
|
|
36
|
+
* @param {string[]} issues - Issue list (errors, warnings, or suggestions).
|
|
37
|
+
* @returns {string[]} - Limited issue list.
|
|
38
|
+
*/
|
|
39
|
+
function limit56xxIssues(issues) {
|
|
40
|
+
const limited = [];
|
|
41
|
+
const perCodeCount = new Map();
|
|
42
|
+
|
|
43
|
+
for (const issue of issues) {
|
|
44
|
+
const match = issue.match(ISSUE_CODE_56XX_REGEX);
|
|
45
|
+
if (!match) {
|
|
46
|
+
limited.push(issue);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const code = match[1];
|
|
51
|
+
const count = perCodeCount.get(code) ?? 0;
|
|
52
|
+
|
|
53
|
+
if (count < MAX_56XX_ISSUES_PER_CODE) {
|
|
54
|
+
limited.push(issue);
|
|
55
|
+
perCodeCount.set(code, count + 1);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (count === MAX_56XX_ISSUES_PER_CODE) {
|
|
60
|
+
limited.push(
|
|
61
|
+
`[${code}] Maximum number of ${code} issues (${MAX_56XX_ISSUES_PER_CODE}) has been reached. Additional ${code} issues exist.`,
|
|
62
|
+
);
|
|
63
|
+
perCodeCount.set(code, count + 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return limited;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Apply issue limits for all E/W/S56xx codes.
|
|
72
|
+
*
|
|
73
|
+
* @param {object} context - The repochecker context object.
|
|
74
|
+
*/
|
|
75
|
+
function apply56xxIssueLimits(context) {
|
|
76
|
+
context.errors = limit56xxIssues(context.errors);
|
|
77
|
+
context.warnings = limit56xxIssues(context.warnings);
|
|
78
|
+
if (Array.isArray(context.suggestions)) {
|
|
79
|
+
context.suggestions = limit56xxIssues(context.suggestions);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
28
82
|
|
|
29
83
|
/**
|
|
30
84
|
* Escape a string for use as a literal in a regular expression.
|
|
@@ -267,9 +321,16 @@ function checkI18nDirectory(context, i18nDir) {
|
|
|
267
321
|
*
|
|
268
322
|
* @param {any} node - jsonConfig node to scan
|
|
269
323
|
* @param {string} currentPath - path in the jsonConfig for error reporting
|
|
270
|
-
* @
|
|
324
|
+
* @param {{insideSelectOptions: boolean}} [state] - recursion state tracking if traversal is currently inside options of a select* component.
|
|
325
|
+
* @returns {Array<{
|
|
326
|
+
* attr: string,
|
|
327
|
+
* value: any,
|
|
328
|
+
* path: string,
|
|
329
|
+
* noTranslation: boolean,
|
|
330
|
+
* isSelectOptionLabel: boolean
|
|
331
|
+
* }>} - Collected attribute entries. isSelectOptionLabel is true for label attributes found inside select* options.
|
|
271
332
|
*/
|
|
272
|
-
function collectTranslatableValues(node, currentPath) {
|
|
333
|
+
function collectTranslatableValues(node, currentPath, state = { insideSelectOptions: false }) {
|
|
273
334
|
if (!node || typeof node !== 'object') {
|
|
274
335
|
return [];
|
|
275
336
|
}
|
|
@@ -278,7 +339,7 @@ function collectTranslatableValues(node, currentPath) {
|
|
|
278
339
|
|
|
279
340
|
if (Array.isArray(node)) {
|
|
280
341
|
node.forEach((item, i) => {
|
|
281
|
-
results.push(...collectTranslatableValues(item, `${currentPath}[${i}]
|
|
342
|
+
results.push(...collectTranslatableValues(item, `${currentPath}[${i}]`, state));
|
|
282
343
|
});
|
|
283
344
|
return results;
|
|
284
345
|
}
|
|
@@ -286,18 +347,28 @@ function collectTranslatableValues(node, currentPath) {
|
|
|
286
347
|
// If this node has noTranslation set, its string values should not be checked
|
|
287
348
|
const noTranslation = node.noTranslation === true;
|
|
288
349
|
|
|
350
|
+
const nodeType = typeof node.type === 'string' ? node.type : '';
|
|
351
|
+
const isSelectComponent = nodeType.startsWith('select');
|
|
352
|
+
|
|
289
353
|
for (const [key, value] of Object.entries(node)) {
|
|
290
354
|
if (TRANSLATABLE_ATTRS.includes(key) && value !== undefined && value !== null) {
|
|
291
|
-
results.push({
|
|
355
|
+
results.push({
|
|
356
|
+
attr: key,
|
|
357
|
+
value,
|
|
358
|
+
path: currentPath,
|
|
359
|
+
noTranslation,
|
|
360
|
+
isSelectOptionLabel: key === 'label' && state.insideSelectOptions,
|
|
361
|
+
});
|
|
292
362
|
}
|
|
293
363
|
|
|
294
364
|
// Recurse into child objects and arrays
|
|
365
|
+
const childState = key === 'options' && isSelectComponent ? { insideSelectOptions: true } : state;
|
|
295
366
|
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
296
|
-
results.push(...collectTranslatableValues(value, `${currentPath}/${key}
|
|
367
|
+
results.push(...collectTranslatableValues(value, `${currentPath}/${key}`, childState));
|
|
297
368
|
} else if (Array.isArray(value)) {
|
|
298
369
|
value.forEach((item, i) => {
|
|
299
370
|
if (typeof item === 'object' && item !== null) {
|
|
300
|
-
results.push(...collectTranslatableValues(item, `${currentPath}/${key}[${i}]
|
|
371
|
+
results.push(...collectTranslatableValues(item, `${currentPath}/${key}[${i}]`, childState));
|
|
301
372
|
}
|
|
302
373
|
});
|
|
303
374
|
}
|
|
@@ -341,7 +412,7 @@ function getI18nDirForJsonConfig(context, configFile, jsonConfig) {
|
|
|
341
412
|
* @param {object} jsonConfig - parsed jsonConfig object
|
|
342
413
|
* @param {string} i18nDir - associated i18n directory path like '/admin/i18n'
|
|
343
414
|
*/
|
|
344
|
-
function checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir) {
|
|
415
|
+
function checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir, w5612State) {
|
|
345
416
|
const displayConfig = configFile.replace(/^\//, '');
|
|
346
417
|
const { allowedLanguages, requiredLanguages } = context.cfg;
|
|
347
418
|
const i18nMode = jsonConfig.i18n;
|
|
@@ -394,21 +465,16 @@ function checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir) {
|
|
|
394
465
|
|
|
395
466
|
const translatables = collectTranslatableValues(jsonConfig, displayConfig);
|
|
396
467
|
|
|
397
|
-
for (const { attr, value, path, noTranslation } of translatables) {
|
|
468
|
+
for (const { attr, value, path, noTranslation, isSelectOptionLabel } of translatables) {
|
|
398
469
|
// Skip attributes where the component declares noTranslation: true
|
|
399
470
|
if (noTranslation) {
|
|
400
471
|
continue;
|
|
401
472
|
}
|
|
402
473
|
|
|
403
474
|
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
//
|
|
407
|
-
// context.warnings.push(
|
|
408
|
-
// `[W5616] "${path}" attribute "${attr}" defines inline i18n object while i18n is enabled. Consider using a translation key string instead.`,
|
|
409
|
-
// );
|
|
410
|
-
} else {
|
|
411
|
-
// i18n=false: check that required languages are present in the object
|
|
475
|
+
if (isSelectOptionLabel || i18nMode === false) {
|
|
476
|
+
// When i18n=false, or for select-option labels regardless of i18n mode,
|
|
477
|
+
// all inline i18n objects must be complete.
|
|
412
478
|
for (const lang of requiredLanguages) {
|
|
413
479
|
if (!Object.prototype.hasOwnProperty.call(value, lang)) {
|
|
414
480
|
context.errors.push(
|
|
@@ -423,6 +489,15 @@ function checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir) {
|
|
|
423
489
|
);
|
|
424
490
|
}
|
|
425
491
|
}
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Value is an inline i18n object (e.g. { en: "Name", de: "Name" })
|
|
496
|
+
if (i18nMode === true || typeof i18nMode === 'string') {
|
|
497
|
+
// When i18n files are used, translatable attributes should be string keys
|
|
498
|
+
// context.warnings.push(
|
|
499
|
+
// `[W5616] "${path}" attribute "${attr}" defines inline i18n object while i18n is enabled. Consider using a translation key string instead.`,
|
|
500
|
+
// );
|
|
426
501
|
}
|
|
427
502
|
} else if (typeof value === 'string') {
|
|
428
503
|
if (i18nMode === false) {
|
|
@@ -431,13 +506,24 @@ function checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir) {
|
|
|
431
506
|
`[W5617] "${path}" attribute "${attr}" uses a plain string while jsonConfig has i18n=false. Consider using an inline i18n object instead.`,
|
|
432
507
|
);
|
|
433
508
|
} else if (enTranslations !== null) {
|
|
509
|
+
if (isSelectOptionLabel) {
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
434
512
|
// i18n enabled: check that the string is a valid key in the English translations
|
|
435
513
|
if (!Object.prototype.hasOwnProperty.call(enTranslations, value)) {
|
|
436
514
|
if (value.match(/[a-zA-Z]/) && value.length >= 3) {
|
|
437
515
|
// do not force translations of labels containing no characters
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
516
|
+
if (w5612State.count < MAX_W5612_WARNINGS) {
|
|
517
|
+
context.warnings.push(
|
|
518
|
+
`[W5612] "${path}" attribute "${attr}" uses key "${value}" which is not found in the English translation file at "${i18nDir.replace(/^\//, '')}/en".`,
|
|
519
|
+
);
|
|
520
|
+
w5612State.count++;
|
|
521
|
+
} else if (!w5612State.limitWarningAdded) {
|
|
522
|
+
context.warnings.push(
|
|
523
|
+
`[W5612] Maximum number of W5612 warnings (${MAX_W5612_WARNINGS}) has been reached. Additional W5612 warnings exist.`,
|
|
524
|
+
);
|
|
525
|
+
w5612State.limitWarningAdded = true;
|
|
526
|
+
}
|
|
441
527
|
}
|
|
442
528
|
}
|
|
443
529
|
}
|
|
@@ -464,6 +550,8 @@ function checkAllI18n(context) {
|
|
|
464
550
|
|
|
465
551
|
// 2. Check jsonConfig files for correct i18n attribute usage and translatable attribute consistency
|
|
466
552
|
const jsonConfigFiles = ['/admin/jsonConfig.json', '/admin/jsonConfig.json5'];
|
|
553
|
+
// Limit W5612 globally across all jsonConfig files processed in one run.
|
|
554
|
+
const w5612State = { count: 0, limitWarningAdded: false };
|
|
467
555
|
|
|
468
556
|
for (const configFile of jsonConfigFiles) {
|
|
469
557
|
if (!context[configFile]) {
|
|
@@ -481,8 +569,10 @@ function checkAllI18n(context) {
|
|
|
481
569
|
}
|
|
482
570
|
|
|
483
571
|
const i18nDir = getI18nDirForJsonConfig(context, configFile, jsonConfig);
|
|
484
|
-
checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir);
|
|
572
|
+
checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir, w5612State);
|
|
485
573
|
}
|
|
574
|
+
|
|
575
|
+
apply56xxIssueLimits(context);
|
|
486
576
|
}
|
|
487
577
|
|
|
488
578
|
exports.checkAllI18n = checkAllI18n;
|
package/lib/M8000_Github.js
CHANGED
|
@@ -30,6 +30,10 @@ axios.defaults.headers.common = {
|
|
|
30
30
|
Expires: '0',
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
if (process.env.OWN_GITHUB_TOKEN) {
|
|
34
|
+
axios.defaults.headers.common['Authorization'] = `Bearer ${process.env.OWN_GITHUB_TOKEN}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
const common = require('./common.js');
|
|
34
38
|
const M8900__Dependabot = require('./M8900__Dependabot.js');
|
|
35
39
|
|
package/lib/config.js
CHANGED
|
@@ -508,7 +508,8 @@ async function updateConfig(context) {
|
|
|
508
508
|
);
|
|
509
509
|
|
|
510
510
|
// Check for JSON5 files in the repository
|
|
511
|
-
const filesList = await common.getFilesList(context);
|
|
511
|
+
const filesList = context.filesList || (await common.getFilesList(context));
|
|
512
|
+
context.filesList = filesList;
|
|
512
513
|
context.cfg.usesJson5 = filesList.some(file => file.endsWith('.json5') && !file.includes('node_modules'));
|
|
513
514
|
|
|
514
515
|
return context;
|
|
@@ -534,6 +535,15 @@ function logEnvironment(context) {
|
|
|
534
535
|
common.info(` usesJson5: ${context.cfg.usesJson5 ? 'true' : 'false'}`);
|
|
535
536
|
common.info(` isNewAdapter: ${context.cfg.isNewAdapter ? 'true' : 'false'}`);
|
|
536
537
|
common.info(` strict: ${common.isStrict() ? 'true' : 'false'}`);
|
|
538
|
+
common.info(' ');
|
|
539
|
+
|
|
540
|
+
common.info('Statistics:');
|
|
541
|
+
common.info(` cached filenames: ${context.filesList?.length || 0}`);
|
|
542
|
+
|
|
543
|
+
// add some global verifications
|
|
544
|
+
if (!context.filesList) {
|
|
545
|
+
throw new Error('FATAL: context.filesList is undefined or empty');
|
|
546
|
+
}
|
|
537
547
|
|
|
538
548
|
return context;
|
|
539
549
|
}
|