(ctx, rawEntry, versionInfo)
| 79 | } |
| 80 | |
| 81 | function readVersionEntry(ctx, rawEntry, versionInfo) { |
| 82 | // Check for the '- ' prefix |
| 83 | var text = rawEntry.text; |
| 84 | if (!text.startsWith("- ")) { |
| 85 | reportLineError(rawEntry, "Expected entry prefix '- '"); |
| 86 | } |
| 87 | text = text.substr(2); |
| 88 | |
| 89 | // Extract the change type |
| 90 | const changeTypeIdx = text.indexOf(":"); |
| 91 | if (changeTypeIdx == -1) { |
| 92 | reportLineError(rawEntry, "Expected change type"); |
| 93 | } |
| 94 | var changeType = text.substring(0, changeTypeIdx).trim(); |
| 95 | text = text.substring(changeTypeIdx + 1).trim(); |
| 96 | |
| 97 | // Check if changeType is valid |
| 98 | if (!ChangeTypes.includes(changeType)) { |
| 99 | // Check for substitution |
| 100 | if (changeType in ChangeTypeSubstitutions) { |
| 101 | changeType = ChangeTypeSubstitutions[changeType]; |
| 102 | } else { |
| 103 | reportLineError(rawEntry, `Invalid change type '${changeType}', types can be ${ChangeTypes.join(", ")}`); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // Extract the references. |
| 108 | var refs = []; |
| 109 | if (text.startsWith("[")) { |
| 110 | const refsEndIdx = text.indexOf("]"); |
| 111 | if (refsEndIdx == -1) { |
| 112 | reportLineError(rawEntry, "Open reference bracket '[' without closing bracket ']'"); |
| 113 | } |
| 114 | refs = text.substring(1, refsEndIdx).split(",").map(ref => ref.trim()); |
| 115 | text = text.substring(refsEndIdx + 1).trim(); |
| 116 | } else { |
| 117 | // Text must start with '[', allow having this missing in older versions. |
| 118 | if (versionInfo.date == "???") { |
| 119 | reportLineError(rawEntry, "Expected reference [#REF]"); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // Make sure the message starts with text and not special characters. |
| 124 | if (text.length == 0) { |
| 125 | reportLineError(rawEntry, "Expected description text"); |
| 126 | } |
| 127 | |
| 128 | // Check that messages start correctly. |
| 129 | if (text[0] == '-' || text[0] == ':') { |
| 130 | reportLineError(rawEntry, `Description must start with text, '${text[0]}' is not allowed`); |
| 131 | } |
| 132 | |
| 133 | // Check if reference is correct, can be '#123' or 'project#123' |
| 134 | for (const ref of refs) { |
| 135 | if (!isValidReference(ref)) { |
| 136 | reportLineError(rawEntry, `Invalid reference '${ref}', must be '#123' or 'project#123'`); |
| 137 | } |
| 138 | } |
no test coverage detected