@iobroker/repochecker 5.14.2 → 5.15.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.
package/README.md CHANGED
@@ -25,6 +25,14 @@ Example:
25
25
  Placeholder for the next version (at the beginning of the line):
26
26
  ### **WORK IN PROGRESS**
27
27
  -->
28
+ ### 5.15.1 (2026-05-27)
29
+
30
+ - (mcm1957) X56xx issues have been count-limited
31
+
32
+ ### 5.15.0 (2026-05-27)
33
+
34
+ - (mcm1957) I18n checks have been extended
35
+
28
36
  ### 5.14.2 (2026-05-27)
29
37
 
30
38
  - (mcm1957) Crash when checking github dependencies has been fixed
package/lib/M2000_Npm.js CHANGED
@@ -122,6 +122,14 @@ async function checkNpm(context) {
122
122
  }
123
123
 
124
124
  if (body['dist-tags'] && body['dist-tags'].latest) {
125
+ context.npmLatestVersion = body['dist-tags'].latest;
126
+ const latestVersionData = body.versions && body.versions[context.npmLatestVersion];
127
+ context.npmLatestHasProvenance = !!(
128
+ latestVersionData &&
129
+ latestVersionData.dist &&
130
+ latestVersionData.dist.provenance
131
+ );
132
+
125
133
  if (common.isAlphaVersion(body['dist-tags'].latest)) {
126
134
  context.warnings.push(
127
135
  `[W2007] Version ${body['dist-tags'].latest} is tagged as "latest" at npm. Pre-release versions must not be tagged as "latest" and will be ignored by repository updates.`,
@@ -130,6 +138,14 @@ async function checkNpm(context) {
130
138
  context.checks.push(`Latest npm version ${body['dist-tags'].latest} is a normal release`);
131
139
  }
132
140
 
141
+ if (context.npmLatestHasProvenance) {
142
+ context.checks.push(`Latest npm version ${body['dist-tags'].latest} is signed with provenance`);
143
+ } else {
144
+ context.warnings.push(
145
+ `[S2008] Version ${body['dist-tags'].latest} tagged as "latest" at npm is not signed with provenance. Trusted publishing is recommended.`,
146
+ );
147
+ }
148
+
133
149
  if (context.packageJson.version !== body['dist-tags'].latest) {
134
150
  if (compareVersions.compare(body['dist-tags'].latest, context.packageJson.version, '>=')) {
135
151
  context.errors.push(
@@ -205,3 +221,4 @@ exports.getNpm = getNpm;
205
221
  // [2004] Versions "${missingVersions.join(', ')}" listed at common.news at io-package.json do not exist at NPM. Please remove from news section.
206
222
  // [2006] Package iobroker.${context.adapterName} has no valid published version on npm. Please publish a version.
207
223
  // [W2007] Version ${body['dist-tags'].latest} is tagged as "latest" at npm but is a pre-release version. Alpha/pre-release versions must not be tagged as "latest" and will be ignored by repository updates.
224
+ // [S2008] Version ${body['dist-tags'].latest} tagged as "latest" at npm is not signed with provenance.
package/lib/M5000_Code.js CHANGED
@@ -16,6 +16,7 @@ const yaml = require('js-yaml');
16
16
 
17
17
  const common = require('./common.js');
18
18
  const M5500__jsonConfig = require('./M5500__JsonConfig.js');
19
+ const M5600__I18n = require('./M5600__I18n.js');
19
20
 
20
21
  // YAML file extensions for validation
21
22
  const yamlExtensions = ['.yml', '.yaml'];
@@ -445,6 +446,14 @@ async function checkCode(context) {
445
446
  }
446
447
  });
447
448
 
449
+ // Add all i18n translation files discovered across the entire repository tree
450
+ M5600__I18n.getI18nFilesToRead(tempFilesList).forEach(filePath => {
451
+ const normalizedPath = filePath.startsWith('/') ? filePath : `/${filePath}`;
452
+ if (!readFiles.includes(normalizedPath)) {
453
+ readFiles.push(normalizedPath);
454
+ }
455
+ });
456
+
448
457
  // if (!context.ioPackageJson.common.noConfig) {
449
458
  // if (context.ioPackageJson.common.materialize || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'materialize')) {
450
459
  // readFiles.push('admin/index_m.html');
@@ -792,27 +801,37 @@ async function checkCode(context) {
792
801
  }
793
802
 
794
803
  if (jsonConfig) {
795
- if (jsonConfig.i18n === true) {
804
+ // Resolve the i18n directory: default is admin/i18n, but may be overridden by a string attribute
805
+ // Note that i18n value is relative to the location of jsonConfig
806
+ const i18nAttr = jsonConfig.i18n;
807
+ const i18nDir =
808
+ typeof i18nAttr === 'string' && i18nAttr.trim() !== '' ? `/admin/${i18nAttr.trim()}` : '/admin/i18n';
809
+
810
+ if (i18nAttr === true || typeof i18nAttr === 'string') {
796
811
  context.cfg.allowedLanguages.forEach(lang => {
797
- if (context[`/admin/i18n/${lang}/translations.json`]) {
812
+ if (context[`${i18nDir}/${lang}/translations.json`]) {
798
813
  try {
799
- JSON.parse(context[`/admin/i18n/${lang}/translations.json`]);
814
+ JSON.parse(context[`${i18nDir}/${lang}/translations.json`]);
800
815
  } catch (e) {
801
- context.errors.push(`[E5009] Cannot parse "admin/i18n/${lang}/translations.json": ${e}`);
816
+ context.errors.push(
817
+ `[E5009] Cannot parse "${i18nDir.replace(/^\//, '')}/${lang}/translations.json": ${e}`,
818
+ );
802
819
  }
803
- } else if (context[`/admin/i18n/${lang}.json`]) {
820
+ } else if (context[`${i18nDir}/${lang}.json`]) {
804
821
  try {
805
- JSON.parse(context[`/admin/i18n/${lang}.json`]);
822
+ JSON.parse(context[`${i18nDir}/${lang}.json`]);
806
823
  } catch (e) {
807
- context.errors.push(`[E5009] Cannot parse "admin/i18n/${lang}.json": ${e}`);
824
+ context.errors.push(
825
+ `[E5009] Cannot parse "${i18nDir.replace(/^\//, '')}/${lang}.json": ${e}`,
826
+ );
808
827
  }
809
828
  } else {
810
829
  context.errors.push(
811
- `[E5010] "/admin/i18n/${lang}/translations.json" or "admin/i18n/${lang}.json" not found, but admin support is declared. Please add.`,
830
+ `[E5010] "${i18nDir.replace(/^\//, '')}/${lang}/translations.json" or "${i18nDir.replace(/^\//, '')}/${lang}.json" not found, but admin support is declared. Please add.`,
812
831
  );
813
832
  }
814
833
  });
815
- } else if (jsonConfig.i18n === false) {
834
+ } else if (i18nAttr === false) {
816
835
  context.warnings.push(`[W5015] Why did you decide to disable i18n support?`);
817
836
  } else {
818
837
  context.warnings.push(`[W5022] Why did you decide not to use i18n support?`);
@@ -1772,6 +1791,9 @@ async function checkCode(context) {
1772
1791
 
1773
1792
  // 5500 - xxx reserved for jsonConfig module
1774
1793
 
1794
+ // 5600 - 5699: comprehensive i18n checks across the full repository
1795
+ M5600__I18n.checkAllI18n(context);
1796
+
1775
1797
  return context;
1776
1798
  }
1777
1799
 
@@ -0,0 +1,598 @@
1
+ 'use strict';
2
+ /*
3
+ This module is a support module for iobroker.repochecker
4
+
5
+ Area checked: i18n translation files
6
+ Numbering : 5600 - 5699
7
+
8
+ */
9
+
10
+ const JSON5 = require('json5');
11
+
12
+ const common = require('./common.js');
13
+
14
+ // Directories to always exclude when scanning for i18n content
15
+ const I18N_EXCLUDED_DIRS = new Set(['node_modules', '.git', '.vscode', '.dev-server']);
16
+
17
+ // Translatable attributes in jsonConfig to scan for proper i18n usage.
18
+ // Add new attribute names here to extend the list of attributes checked.
19
+ const TRANSLATABLE_ATTRS = [
20
+ 'label',
21
+ 'textAlive',
22
+ 'textNotAlive',
23
+ 'tooltip',
24
+ 'help',
25
+ 'placeholder',
26
+ 'validatorErrorText',
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
+ }
82
+
83
+ /**
84
+ * Escape a string for use as a literal in a regular expression.
85
+ *
86
+ * @param {string} str - The string to escape.
87
+ * @returns {string} - The escaped string safe for use in a RegExp constructor.
88
+ */
89
+ function escapeRegex(str) {
90
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
91
+ }
92
+
93
+ /**
94
+ * Discover all i18n directory paths from the repository file list.
95
+ * Recognises both long format ({lang}/translations.json) and short format ({lang}.json).
96
+ *
97
+ * @param {string[]} filesList - list of file paths (each with a leading slash)
98
+ * @returns {string[]} - unique i18n directory paths (with leading slash), e.g. ['/admin/i18n']
99
+ */
100
+ function discoverI18nDirs(filesList) {
101
+ const i18nDirs = new Set();
102
+
103
+ for (const filePath of filesList) {
104
+ // Skip files inside excluded directories
105
+ const parts = filePath.split('/').filter(p => p !== '');
106
+ if (parts.some(p => I18N_EXCLUDED_DIRS.has(p))) {
107
+ continue;
108
+ }
109
+
110
+ // Long format: .../i18n/{lang}/translations.json
111
+ const longMatch = filePath.match(/^(.*\/i18n)\/([^/]+)\/translations\.json$/);
112
+ if (longMatch) {
113
+ i18nDirs.add(longMatch[1]);
114
+ continue;
115
+ }
116
+
117
+ // Short format: .../i18n/{lang}.json
118
+ const shortMatch = filePath.match(/^(.*\/i18n)\/([^/]+)\.json$/);
119
+ if (shortMatch) {
120
+ i18nDirs.add(shortMatch[1]);
121
+ }
122
+ }
123
+
124
+ return [...i18nDirs];
125
+ }
126
+
127
+ /**
128
+ * Return the list of i18n-related file paths that need to be loaded.
129
+ * Called before the main file-loading phase to ensure all i18n files are available.
130
+ *
131
+ * @param {string[]} filesList - List of all repository file paths (each with a leading slash).
132
+ * @returns {string[]} - i18n file paths to include in the readFiles list.
133
+ */
134
+ function getI18nFilesToRead(filesList) {
135
+ const filesToRead = [];
136
+
137
+ for (const filePath of filesList) {
138
+ // Skip files inside excluded directories
139
+ const parts = filePath.split('/').filter(p => p !== '');
140
+ if (parts.some(p => I18N_EXCLUDED_DIRS.has(p))) {
141
+ continue;
142
+ }
143
+
144
+ // Long format: .../i18n/{lang}/translations.json
145
+ if (/\/i18n\/[^/]+\/translations\.json$/.test(filePath)) {
146
+ filesToRead.push(filePath);
147
+ } else if (/\/i18n\/[^/]+\.json$/.test(filePath)) {
148
+ // Short format: .../i18n/{lang}.json
149
+ filesToRead.push(filePath);
150
+ }
151
+ }
152
+
153
+ return filesToRead;
154
+ }
155
+
156
+ /**
157
+ * Determine which language files exist in an i18n directory and in which format.
158
+ *
159
+ * @param {string} i18nDir - Directory path like '/admin/i18n'.
160
+ * @param {string[]} filesList - List of all repository file paths.
161
+ * @returns {{ longFormat: Set<string>, shortFormat: Set<string> }} - Sets of language codes per format.
162
+ */
163
+ function getI18nFormats(i18nDir, filesList) {
164
+ const longFormat = new Set();
165
+ const shortFormat = new Set();
166
+ const escaped = escapeRegex(i18nDir);
167
+
168
+ for (const filePath of filesList) {
169
+ const longMatch = filePath.match(new RegExp(`^${escaped}/([^/]+)/translations\\.json$`));
170
+ if (longMatch) {
171
+ longFormat.add(longMatch[1]);
172
+ continue;
173
+ }
174
+ const shortMatch = filePath.match(new RegExp(`^${escaped}/([^/]+)\\.json$`));
175
+ if (shortMatch) {
176
+ shortFormat.add(shortMatch[1]);
177
+ }
178
+ }
179
+
180
+ return { longFormat, shortFormat };
181
+ }
182
+
183
+ /**
184
+ * Load and parse translation objects for all available languages in an i18n directory.
185
+ *
186
+ * @param {string} i18nDir - The i18n directory path, e.g. '/admin/i18n'.
187
+ * @param {Set<string>} longFormat - languages present in long format
188
+ * @param {Set<string>} shortFormat - languages present in short format
189
+ * @param {object} context - The repochecker context object.
190
+ * @returns {Map<string, object>} - lang → parsed translations object
191
+ */
192
+ function loadTranslations(i18nDir, longFormat, shortFormat, context) {
193
+ const translations = new Map();
194
+
195
+ // Long format: {lang}/translations.json
196
+ for (const lang of longFormat) {
197
+ const key = `${i18nDir}/${lang}/translations.json`;
198
+ if (context[key]) {
199
+ try {
200
+ translations.set(lang, JSON.parse(context[key]));
201
+ } catch {
202
+ // Parse errors are reported elsewhere (E5009)
203
+ }
204
+ }
205
+ }
206
+
207
+ // Short format: {lang}.json – only when not already loaded via long format
208
+ for (const lang of shortFormat) {
209
+ if (!translations.has(lang)) {
210
+ const key = `${i18nDir}/${lang}.json`;
211
+ if (context[key]) {
212
+ try {
213
+ translations.set(lang, JSON.parse(context[key]));
214
+ } catch {
215
+ // Parse errors are reported elsewhere (E5009)
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ return translations;
222
+ }
223
+
224
+ /**
225
+ * Check a single i18n directory for format consistency, language completeness,
226
+ * and translation key consistency.
227
+ *
228
+ * @param {object} context - The repochecker context object.
229
+ * @param {string} i18nDir - Absolute path like '/admin/i18n'.
230
+ */
231
+ function checkI18nDirectory(context, i18nDir) {
232
+ const displayDir = i18nDir.replace(/^\//, '');
233
+ const { allowedLanguages, requiredLanguages } = context.cfg;
234
+ const { longFormat, shortFormat } = getI18nFormats(i18nDir, context.filesList);
235
+
236
+ // E5600: Both formats coexist for the same language in the same directory
237
+ const bothFormats = [...longFormat].filter(lang => shortFormat.has(lang));
238
+ if (bothFormats.length > 0) {
239
+ context.errors.push(
240
+ `[E5600] i18n directory "${displayDir}" contains both long format ({lang}/translations.json) and short format ({lang}.json) for language(s): ${bothFormats.join(', ')}. Please use only one format.`,
241
+ );
242
+ }
243
+
244
+ // S5601: Long format in use → suggest migration to short format
245
+ if (longFormat.size > 0) {
246
+ context.warnings.push(
247
+ `[S5601] i18n directory "${displayDir}" uses long format ({lang}/translations.json). Consider migrating to short format ({lang}.json) using "npm run translate convert".`,
248
+ );
249
+ }
250
+
251
+ // All detected languages (union of both formats)
252
+ const allDetected = new Set([...longFormat, ...shortFormat]);
253
+
254
+ // E5602: Required language missing → error
255
+ for (const lang of requiredLanguages) {
256
+ if (!allDetected.has(lang)) {
257
+ context.errors.push(`[E5602] i18n directory "${displayDir}" is missing required language "${lang}".`);
258
+ }
259
+ }
260
+
261
+ // W5603: Non-required allowed language missing → warning
262
+ for (const lang of allowedLanguages) {
263
+ if (!requiredLanguages.includes(lang) && !allDetected.has(lang)) {
264
+ context.warnings.push(`[W5603] i18n directory "${displayDir}" is missing language "${lang}".`);
265
+ }
266
+ }
267
+
268
+ // Load translations for key-consistency checks
269
+ const translations = loadTranslations(i18nDir, longFormat, shortFormat, context);
270
+ const enTranslations = translations.get('en');
271
+
272
+ if (!enTranslations) {
273
+ common.debug(`No English translations available for "${displayDir}", skipping key-consistency checks.`);
274
+ return;
275
+ }
276
+
277
+ const enKeys = new Set(Object.keys(enTranslations));
278
+
279
+ for (const [lang, langTranslations] of translations) {
280
+ if (lang === 'en') {
281
+ continue;
282
+ }
283
+
284
+ const langKeys = new Set(Object.keys(langTranslations));
285
+
286
+ // W5604: Keys in English not present in other language (missing translations)
287
+ const missingInLang = [...enKeys].filter(k => !langKeys.has(k));
288
+ if (missingInLang.length > 0) {
289
+ context.warnings.push(
290
+ `[W5604] i18n "${displayDir}" language "${lang}" is missing ${missingInLang.length} key(s) present in English: ${missingInLang.slice(0, 5).join(', ')}${missingInLang.length > 5 ? ', ...' : ''}`,
291
+ );
292
+ }
293
+
294
+ // W5605: Keys in other language not present in English (outdated translations)
295
+ const outdated = [...langKeys].filter(k => !enKeys.has(k));
296
+ if (outdated.length > 0) {
297
+ context.warnings.push(
298
+ `[W5605] i18n "${displayDir}" language "${lang}" has ${outdated.length} outdated key(s) not present in English: ${outdated.slice(0, 5).join(', ')}${outdated.length > 5 ? ', ...' : ''}`,
299
+ );
300
+ }
301
+
302
+ // W5606: Too many identical translations (>5 non-trivial identical strings)
303
+ const identical = [...enKeys].filter(
304
+ k =>
305
+ langKeys.has(k) &&
306
+ typeof enTranslations[k] === 'string' &&
307
+ typeof langTranslations[k] === 'string' &&
308
+ enTranslations[k].length > 1 &&
309
+ enTranslations[k] === langTranslations[k],
310
+ );
311
+ if (identical.length > [...enKeys].length * 0.75) {
312
+ context.warnings.push(
313
+ `[W5606] i18n "${displayDir}" language "${lang}" has ${identical.length} translation(s) identical to English (i.e. ${identical[0]}). This may indicate untranslated content.`,
314
+ );
315
+ }
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Recursively collect translatable attribute values from a jsonConfig node.
321
+ *
322
+ * @param {any} node - jsonConfig node to scan
323
+ * @param {string} currentPath - path in the jsonConfig for error reporting
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.
332
+ */
333
+ function collectTranslatableValues(node, currentPath, state = { insideSelectOptions: false }) {
334
+ if (!node || typeof node !== 'object') {
335
+ return [];
336
+ }
337
+
338
+ const results = [];
339
+
340
+ if (Array.isArray(node)) {
341
+ node.forEach((item, i) => {
342
+ results.push(...collectTranslatableValues(item, `${currentPath}[${i}]`, state));
343
+ });
344
+ return results;
345
+ }
346
+
347
+ // If this node has noTranslation set, its string values should not be checked
348
+ const noTranslation = node.noTranslation === true;
349
+
350
+ const nodeType = typeof node.type === 'string' ? node.type : '';
351
+ const isSelectComponent = nodeType.startsWith('select');
352
+
353
+ for (const [key, value] of Object.entries(node)) {
354
+ if (TRANSLATABLE_ATTRS.includes(key) && value !== undefined && value !== null) {
355
+ results.push({
356
+ attr: key,
357
+ value,
358
+ path: currentPath,
359
+ noTranslation,
360
+ isSelectOptionLabel: key === 'label' && state.insideSelectOptions,
361
+ });
362
+ }
363
+
364
+ // Recurse into child objects and arrays
365
+ const childState = key === 'options' && isSelectComponent ? { insideSelectOptions: true } : state;
366
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
367
+ results.push(...collectTranslatableValues(value, `${currentPath}/${key}`, childState));
368
+ } else if (Array.isArray(value)) {
369
+ value.forEach((item, i) => {
370
+ if (typeof item === 'object' && item !== null) {
371
+ results.push(...collectTranslatableValues(item, `${currentPath}/${key}[${i}]`, childState));
372
+ }
373
+ });
374
+ }
375
+ }
376
+
377
+ return results;
378
+ }
379
+
380
+ /**
381
+ * Determine the i18n directory associated with a jsonConfig file.
382
+ * The default is the same directory as the jsonConfig file + '/i18n'.
383
+ * If the jsonConfig has an `i18n` string attribute, that path is used instead
384
+ * (interpreted as relative to the repository root).
385
+ *
386
+ * @param {string} configFile - file path like '/admin/jsonConfig.json'
387
+ * @param {object} jsonConfig - parsed jsonConfig object
388
+ * @returns {string} - resolved i18n directory path like '/admin/i18n'
389
+ */
390
+ function getI18nDirForJsonConfig(context, configFile, jsonConfig) {
391
+ const configDir = configFile.replace(/\/[^/]+$/, '') || ''; // e.g. '/admin', or '' for root-level files
392
+ if (typeof jsonConfig.i18n === 'string' && jsonConfig.i18n.trim() !== '') {
393
+ const customPath = jsonConfig.i18n.trim();
394
+ if (!customPath.endsWith('/i18n')){
395
+ context.errors.push(
396
+ `[E5618] "Custom path specified at i18n attribute (${customPath}) must end with '/i18n'`,
397
+ );
398
+ }
399
+ // Interpret as absolute path from repo root (with leading slash) or relative to admin
400
+ return customPath.startsWith('/') ? customPath : `/admin/${customPath}`;
401
+ }
402
+
403
+ // Default: directory of the jsonConfig file + '/i18n'
404
+ return `${configDir}/i18n`;
405
+ }
406
+
407
+ /**
408
+ * Check translatable attributes in a jsonConfig for proper i18n handling.
409
+ *
410
+ * @param {object} context - The repochecker context object.
411
+ * @param {string} configFile - file path like '/admin/jsonConfig.json'
412
+ * @param {object} jsonConfig - parsed jsonConfig object
413
+ * @param {string} i18nDir - associated i18n directory path like '/admin/i18n'
414
+ */
415
+ function checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir, w5612State) {
416
+ const displayConfig = configFile.replace(/^\//, '');
417
+ const { allowedLanguages, requiredLanguages } = context.cfg;
418
+ const i18nMode = jsonConfig.i18n;
419
+
420
+ // Load English translations for string-key checking
421
+ let enTranslations = null;
422
+ const enLongKey = `${i18nDir}/en/translations.json`;
423
+ const enShortKey = `${i18nDir}/en.json`;
424
+ if (context[enLongKey]) {
425
+ try {
426
+ enTranslations = JSON.parse(context[enLongKey]);
427
+ } catch {
428
+ /* parse errors are reported elsewhere */
429
+ }
430
+ } else if (context[enShortKey]) {
431
+ try {
432
+ enTranslations = JSON.parse(context[enShortKey]);
433
+ } catch {
434
+ /* parse errors are reported elsewhere */
435
+ }
436
+ }
437
+
438
+ // Determine whether any i18n files exist at the expected directory
439
+ const escaped = escapeRegex(i18nDir);
440
+ const i18nDirExists = context.filesList.some(f => new RegExp(`^${escaped}/`).test(f));
441
+
442
+ // W5615: i18n enabled but the i18n directory is absent
443
+ if (i18nMode === true || typeof i18nMode === 'string') {
444
+ if (!i18nDirExists) {
445
+ context.warnings.push(
446
+ `[W5615] "${displayConfig}" has i18n enabled but no i18n directory found at "${i18nDir.replace(/^\//, '')}". Please create translation files.`,
447
+ );
448
+ }
449
+ }
450
+
451
+ // W5614: i18n=false but an i18n directory exists (will not be used)
452
+ if (i18nMode === false) {
453
+ if (i18nDirExists) {
454
+ context.warnings.push(
455
+ `[W5614] "${displayConfig}" has i18n=false but an i18n directory exists at "${i18nDir.replace(/^\//, '')}". This i18n directory will not be used by this jsonConfig.`,
456
+ );
457
+ }
458
+ }
459
+
460
+ // Scan for translatable attributes only when i18n is explicitly configured
461
+ // (skip when i18n is not set to avoid flooding adapters that use words.js or other mechanisms)
462
+ if (i18nMode === undefined || i18nMode === null) {
463
+ return;
464
+ }
465
+
466
+ const translatables = collectTranslatableValues(jsonConfig, displayConfig);
467
+
468
+ for (const { attr, value, path, noTranslation, isSelectOptionLabel } of translatables) {
469
+ // Skip attributes where the component declares noTranslation: true
470
+ if (noTranslation) {
471
+ continue;
472
+ }
473
+
474
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
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.
478
+ for (const lang of requiredLanguages) {
479
+ if (!Object.prototype.hasOwnProperty.call(value, lang)) {
480
+ context.errors.push(
481
+ `[E5610] "${path}" attribute "${attr}" is missing required language "${lang}" in i18n object.`,
482
+ );
483
+ }
484
+ }
485
+ for (const lang of allowedLanguages) {
486
+ if (!requiredLanguages.includes(lang) && !Object.prototype.hasOwnProperty.call(value, lang)) {
487
+ context.warnings.push(
488
+ `[W5611] "${path}" attribute "${attr}" is missing language "${lang}" in i18n object.`,
489
+ );
490
+ }
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
+ // );
501
+ }
502
+ } else if (typeof value === 'string') {
503
+ if (i18nMode === false) {
504
+ // When i18n=false, translatable attributes should be inline objects
505
+ context.warnings.push(
506
+ `[W5617] "${path}" attribute "${attr}" uses a plain string while jsonConfig has i18n=false. Consider using an inline i18n object instead.`,
507
+ );
508
+ } else if (enTranslations !== null) {
509
+ if (isSelectOptionLabel) {
510
+ continue;
511
+ }
512
+ // i18n enabled: check that the string is a valid key in the English translations
513
+ if (!Object.prototype.hasOwnProperty.call(enTranslations, value)) {
514
+ if (value.match(/[a-zA-Z]/) && value.length >= 3) {
515
+ // do not force translations of labels containing no characters
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
+ }
527
+ }
528
+ }
529
+ }
530
+ }
531
+ }
532
+ }
533
+
534
+ /**
535
+ * Main entry point: check all i18n directories found in the repository and
536
+ * validate jsonConfig files for correct i18n attribute usage.
537
+ *
538
+ * @param {object} context - The repochecker context object.
539
+ */
540
+ function checkAllI18n(context) {
541
+ //console.log('\n[5600 - 5699] checkAllI18n');
542
+
543
+ // 1. Check every discovered i18n directory
544
+ const i18nDirs = discoverI18nDirs(context.filesList);
545
+ common.debug(`Discovered ${i18nDirs.length} i18n director(ies): ${i18nDirs.join(', ')}`);
546
+
547
+ for (const i18nDir of i18nDirs) {
548
+ checkI18nDirectory(context, i18nDir);
549
+ }
550
+
551
+ // 2. Check jsonConfig files for correct i18n attribute usage and translatable attribute consistency
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 };
555
+
556
+ for (const configFile of jsonConfigFiles) {
557
+ if (!context[configFile]) {
558
+ continue;
559
+ }
560
+
561
+ let jsonConfig;
562
+ try {
563
+ jsonConfig = configFile.endsWith('.json5')
564
+ ? JSON5.parse(context[configFile])
565
+ : JSON.parse(context[configFile]);
566
+ } catch {
567
+ // Parse errors are reported elsewhere (E5007)
568
+ continue;
569
+ }
570
+
571
+ const i18nDir = getI18nDirForJsonConfig(context, configFile, jsonConfig);
572
+ checkJsonConfigTranslations(context, configFile, jsonConfig, i18nDir, w5612State);
573
+ }
574
+
575
+ apply56xxIssueLimits(context);
576
+ }
577
+
578
+ exports.checkAllI18n = checkAllI18n;
579
+ exports.getI18nFilesToRead = getI18nFilesToRead;
580
+
581
+ // List of error and warning codes used by this module
582
+ // ----------------------------------------------------
583
+
584
+ // [E5600] i18n directory contains both long and short format for the same language
585
+ // [S5601] Suggest migrating from long format to short format using npm run translate convert
586
+ // [E5602] i18n directory is missing a required language
587
+ // [W5603] i18n directory is missing a non-required language
588
+ // [W5604] English translation key not present in another language (missing translation)
589
+ // [W5605] Translation key in non-English file not present in English (outdated translation)
590
+ // [W5606] More than 5 translations are identical between English and another language
591
+ // [E5610] jsonConfig translatable attribute i18n object missing a required language
592
+ // [W5611] jsonConfig translatable attribute i18n object missing a non-required language
593
+ // [W5612] jsonConfig translatable attribute string key not found in English translation file
594
+ // [W5614] jsonConfig has i18n=false but an i18n directory exists (will not be used)
595
+ // [W5615] jsonConfig has i18n enabled but the expected i18n directory does not exist
596
+ // [W5616] jsonConfig has i18n enabled but a translatable attribute uses an inline i18n object
597
+ // [W5617] jsonConfig has i18n=false but a translatable attribute uses a plain string
598
+ // [E5618] "Custom path specified at i18n attribute (${customPath}) must end with '/i18n'
@@ -93,6 +93,38 @@ async function checkGithubRepo(context) {
93
93
  context.errors.push(`[E8003] Archived repositories are not allowed.`);
94
94
  }
95
95
 
96
+ let releases = [];
97
+ try {
98
+ const releasesResponse = await axios(`${context.githubUrlApi}/releases?per_page=20`);
99
+ releases = Array.isArray(releasesResponse.data) ? releasesResponse.data : [];
100
+ } catch (e) {
101
+ common.error(`error downloading release info from ${context.githubUrlApi}/releases - ${e}`);
102
+ }
103
+
104
+ if (!releases.length) {
105
+ context.warnings.push(
106
+ '[S8005] No GitHub release found. Please use GitHub releases for easier identification of the current release and consider using "@iobroker/action-deploy".',
107
+ );
108
+ } else if (context.npmLatestVersion) {
109
+ const latestGithubRelease =
110
+ releases.find(release => !release.draft && !release.prerelease) ||
111
+ releases.find(release => !release.draft) ||
112
+ releases[0];
113
+ const latestGithubTag = latestGithubRelease && latestGithubRelease.tag_name ? latestGithubRelease.tag_name : '';
114
+ const normalizedGithubTag = latestGithubTag.replace(/^v/i, '');
115
+ const normalizedNpmVersion = context.npmLatestVersion.replace(/^v/i, '');
116
+
117
+ if (normalizedGithubTag !== normalizedNpmVersion) {
118
+ context.warnings.push(
119
+ `[W8005] Latest GitHub release tag (${latestGithubTag}) does not match latest npm version (${context.npmLatestVersion}).`,
120
+ );
121
+ } else {
122
+ context.checks.push(
123
+ `Latest GitHub release tag ${latestGithubTag} matches latest npm version ${context.npmLatestVersion}`,
124
+ );
125
+ }
126
+ }
127
+
96
128
  const issues = await getAllIssues(context);
97
129
  for (const issue of issues) {
98
130
  // if (issue.pull_request) {
@@ -138,5 +170,7 @@ exports.checkGithubRepo = checkGithubRepo;
138
170
  // [E8001] No repository about text found. Please go to "${context.githubUrlOriginal}", press the settings button beside the about title and add the description.
139
171
  // [E8002] No topics found in the repository. Please go to "${context.githubUrlOriginal}", press the settings button beside the about title and add some topics.
140
172
  // [E8003] Archived repositories are not allowed.
173
+ // [W8005] Latest GitHub release tag does not match latest npm version.
174
+ // [S8005] No GitHub release found. Please use GitHub releases and consider using "@iobroker/action-deploy".
141
175
  //
142
176
  // [E8900 - E8999] Dependabot checks - see M8900__Dependabot.js
@@ -43,10 +43,12 @@ const mapSeverity4New = {
43
43
  W8916: 'E', // [W8916] Dependabot configuration "/.github/dependabot.yml" has no entry with "package-ecosystem: github-actions".
44
44
  W8917: 'E', // [W8917] At least major versions of @types/node should not be updated by dependabot.
45
45
  S0062: 'W', // [S0062] Consider adding and using package "@alcalzone/release-script".
46
+ S2008: 'E', // [S2008] Version 0.5.1 tagged as "latest" at npm is not signed with provenance. Trusted publishing is recommended.
46
47
  S3012: 'E', // [S3012] Workflow "test-and-release.yml": job "deploy" is not defined.
47
48
  S5022: 'W', // [S5022] Please consider migrating to admin 5 UI (jsonConfig) or react based UI.
48
49
  S5043: 'E', // [S5043] Package "xx" is a built-in Node.js module. Please use "node:fs" instead.
49
50
  S5051: 'W', // [S5051] Custom sleep/wait function(s) found in source files (src/lib/adsb.ts).
51
+ W5611: 'E', // [W5611] "admin/jsonConfig.json/items/tab_region/items/country/options[0]" attribute "label" is missing language "uk" in i18n object.
50
52
  S6008: 'E', // [S6008] Changelog for version 0.7.0-beta.19 should be added to README.md
51
53
  S6020: 'W', // [S6020] Consider adding a CHANGELOG_OLD.md file to store older changelog entries. This is supported by @alcalzone/releasescript.
52
54
  S8901: 'W', // [S8901] Dependabot configuration file ".github/dependabot.yml" not found. Consider adding dependabot to keep dependencies up to date.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.14.2",
2
+ "version": "5.15.1",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
5
  "ajv": "^8.20.0",