|
| 1 | +'use strict'; |
| 2 | +/* |
| 3 | + This module contains postprocessing tasks for iobroker.repochecker. |
| 4 | +
|
| 5 | + Postprocessing tasks are run after all check modules have completed and |
| 6 | + can manipulate errors, warnings, suggestions, and infos in the context. |
| 7 | +
|
| 8 | +*/ |
| 9 | + |
| 10 | +// --------------------------------------------------------------------------- |
| 11 | +// Configuration tables |
| 12 | +// --------------------------------------------------------------------------- |
| 13 | + |
| 14 | +/** |
| 15 | + * Severity remapping table for new adapters (used by adaptSeverity4New). |
| 16 | + * |
| 17 | + * Key : original issue key (e.g. "W0028") |
| 18 | + * Value : target severity – one of 'E' (error), 'W' (warning), 'S' (suggestion), |
| 19 | + * or 'N' (none / drop the issue entirely). |
| 20 | + * |
| 21 | + * When context.cfg.isNewAdapter is set, every raised issue whose key appears |
| 22 | + * in this table will be removed from its current storage array and re-inserted |
| 23 | + * with the new severity (or silently dropped for 'N'). |
| 24 | + */ |
| 25 | +const mapSeverity4New = { |
| 26 | + W0028: 'E', // [W0028] Minimum node.js version 20 recommended. |
| 27 | + W1027: 'E', // [W1027] Missing suggested translation into ru,pt,nl,fr,it,es,pl,uk,zh-cn of "common.titleLang" |
| 28 | + W1032: 'E', // [W1032] Many "common.news" found in io-package.json |
| 29 | + W1034: 'E', // [W1034] Missing suggested translation into ru,pt,nl,fr,it,es,pl,uk,zh-cn of "common.desc" |
| 30 | + S0062: 'W', // [S0062] Consider adding and using package "@alcalzone/release-script". |
| 31 | + S6008: 'E', // [S6008] Changelog for version 0.7.0-beta.19 should be added to README.md |
| 32 | + S6020: 'W', // [S6020] Consider adding a CHANGELOG_OLD.md file to store older changelog entries. This is supported by @alcalzone/releasescript. |
| 33 | + S8901: 'W', // [S8901] Dependabot configuration file ".github/dependabot.yml" not found. Consider adding dependabot to keep dependencies up to date. |
| 34 | + S9006: 'E', // [S9006] .commitinfo file should be excluded by .gitignore, please add a line with text ".commitinfo" to .gitignore |
| 35 | +}; |
| 36 | + |
| 37 | +// --------------------------------------------------------------------------- |
| 38 | +// Postprocessing tasks |
| 39 | +// --------------------------------------------------------------------------- |
| 40 | + |
| 41 | +/** |
| 42 | + * Remaps the severity of issues for new adapters according to mapSeverity4New. |
| 43 | + * |
| 44 | + * If context.cfg.isNewAdapter is not set the function returns immediately |
| 45 | + * without any changes. |
| 46 | + * |
| 47 | + * For each entry in context.errors and context.warnings the issue key is |
| 48 | + * extracted (e.g. "W1234" from "[W1234] …"). If the key is present in |
| 49 | + * mapSeverity4New the entry is removed from its current array and either |
| 50 | + * re-inserted with the new severity prefix or dropped (when target is 'N'). |
| 51 | + * |
| 52 | + * @param {object} context - The checker context |
| 53 | + * @returns {object} The (possibly modified) context |
| 54 | + */ |
| 55 | +function adaptSeverity4New(context) { |
| 56 | + if (!context.cfg || !context.cfg.isNewAdapter) { |
| 57 | + return context; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Process a single array of issue strings in-place. |
| 62 | + * Entries that need to change severity are removed and collected for |
| 63 | + * re-insertion so that the iteration index stays consistent. |
| 64 | + * |
| 65 | + * @param {string[]} sourceArray - The array to scan (errors or warnings) |
| 66 | + */ |
| 67 | + function processArray(sourceArray) { |
| 68 | + // Collect items to re-route so we don't mutate while iterating |
| 69 | + const toReroute = []; |
| 70 | + |
| 71 | + for (let i = sourceArray.length - 1; i >= 0; i--) { |
| 72 | + const entry = sourceArray[i]; |
| 73 | + const match = entry.match(/^\[([EWSI]\d+)\]/); |
| 74 | + if (!match) { |
| 75 | + continue; |
| 76 | + } |
| 77 | + |
| 78 | + const issueKey = match[1]; // e.g. "W1234" |
| 79 | + if (!Object.prototype.hasOwnProperty.call(mapSeverity4New, issueKey)) { |
| 80 | + continue; |
| 81 | + } |
| 82 | + |
| 83 | + const targetSeverity = mapSeverity4New[issueKey]; |
| 84 | + |
| 85 | + // Remove from current position |
| 86 | + sourceArray.splice(i, 1); |
| 87 | + |
| 88 | + if (targetSeverity !== 'N') { |
| 89 | + // Replace the key prefix in the message, e.g. [W1234] -> [E1234] |
| 90 | + const numPart = issueKey.slice(1); // "1234" |
| 91 | + const newKey = `${targetSeverity}${numPart}`; |
| 92 | + const newEntry = entry.replace(`[${issueKey}]`, `[${newKey}]`); |
| 93 | + toReroute.push({ severity: targetSeverity, entry: newEntry }); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + // Re-insert into the correct arrays |
| 98 | + for (const { severity, entry } of toReroute) { |
| 99 | + if (severity === 'E') { |
| 100 | + context.errors.push(entry); |
| 101 | + } else { |
| 102 | + // 'W' and 'S' both live in context.warnings |
| 103 | + context.warnings.push(entry); |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + processArray(context.errors); |
| 109 | + processArray(context.warnings); |
| 110 | + |
| 111 | + return context; |
| 112 | +} |
| 113 | + |
| 114 | +// --------------------------------------------------------------------------- |
| 115 | +// Main postprocessing orchestrator |
| 116 | +// --------------------------------------------------------------------------- |
| 117 | + |
| 118 | +/** |
| 119 | + * Runs all postprocessing tasks sequentially. |
| 120 | + * Each task receives the full context and may modify errors, warnings, |
| 121 | + * suggestions, and infos before the results are returned to the caller. |
| 122 | + * |
| 123 | + * @param {object} context - The checker context |
| 124 | + * @returns {object} The context after all postprocessing tasks have run |
| 125 | + */ |
| 126 | +function postprocessing(context) { |
| 127 | + console.log('\n[postprocessing] running postprocessing tasks'); |
| 128 | + |
| 129 | + adaptSeverity4New(context); |
| 130 | + |
| 131 | + return context; |
| 132 | +} |
| 133 | + |
| 134 | +exports.postprocessing = postprocessing; |
0 commit comments