({error, yaml})
| 131 | } |
| 132 | |
| 133 | static analyzeYamlError({error, yaml}) { |
| 134 | if (error.instancePath === "" && error.keyword === "required") { |
| 135 | // There is no line/column for a missing required property on root level |
| 136 | return {line: -1, column: -1}; |
| 137 | } |
| 138 | |
| 139 | // Skip leading / |
| 140 | const objectPath = error.instancePath.substr(1).split("/"); |
| 141 | |
| 142 | if (error.keyword === "additionalProperties") { |
| 143 | objectPath.push(error.params.additionalProperty); |
| 144 | } |
| 145 | |
| 146 | let currentSubstring; |
| 147 | let currentIndex; |
| 148 | if (yaml.documentIndex) { |
| 149 | const matchDocumentSeparator = /^---/gm; |
| 150 | let currentDocumentIndex = 0; |
| 151 | let document; |
| 152 | while ((document = matchDocumentSeparator.exec(yaml.source)) !== null) { |
| 153 | // If the first separator is not at the beginning of the file |
| 154 | // we are already at document index 1 |
| 155 | // Using String#trim() to remove any whitespace characters |
| 156 | if (currentDocumentIndex === 0 && yaml.source.substring(0, document.index).trim().length > 0) { |
| 157 | currentDocumentIndex = 1; |
| 158 | } |
| 159 | |
| 160 | if (currentDocumentIndex === yaml.documentIndex) { |
| 161 | currentIndex = document.index; |
| 162 | currentSubstring = yaml.source.substring(currentIndex); |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | currentDocumentIndex++; |
| 167 | } |
| 168 | // Document could not be found |
| 169 | if (!currentSubstring) { |
| 170 | return {line: -1, column: -1}; |
| 171 | } |
| 172 | } else { |
| 173 | // In case of index 0 or no index, use whole source |
| 174 | currentIndex = 0; |
| 175 | currentSubstring = yaml.source; |
| 176 | } |
| 177 | |
| 178 | const matchArrayElementIndentation = /([ ]*)-/; |
| 179 | |
| 180 | for (let i = 0; i < objectPath.length; i++) { |
| 181 | const property = objectPath[i]; |
| 182 | let newIndex; |
| 183 | |
| 184 | if (isNaN(property)) { |
| 185 | // Try to find a property |
| 186 | |
| 187 | // Creating a regular expression that matches the property name a line |
| 188 | // except for comments, indicated by a hash sign "#". |
| 189 | const propertyRegExp = new RegExp(`^[^#]*?${escapeStringRegExp(property)}`, "m"); |
| 190 |
no outgoing calls
no test coverage detected