(arrMessages: Hint[], options: FormatOptions = {})
| 188 | } |
| 189 | |
| 190 | public format(arrMessages: Hint[], options: FormatOptions = {}) { |
| 191 | const arrLogs: string[] = [] |
| 192 | const colors = { |
| 193 | white: '', |
| 194 | grey: '', |
| 195 | red: '', |
| 196 | reset: '', |
| 197 | } |
| 198 | |
| 199 | if (options.colors) { |
| 200 | colors.white = '\x1b[37m' |
| 201 | colors.grey = '\x1b[90m' |
| 202 | colors.red = '\x1b[31m' |
| 203 | colors.reset = '\x1b[39m' |
| 204 | } |
| 205 | |
| 206 | const indent = options.indent || 0 |
| 207 | |
| 208 | arrMessages.forEach((hint) => { |
| 209 | const leftWindow = 40 |
| 210 | const rightWindow = leftWindow + 20 |
| 211 | let evidence = hint.evidence |
| 212 | const line = hint.line |
| 213 | const col = hint.col |
| 214 | const evidenceCount = evidence.length |
| 215 | let leftCol = col > leftWindow + 1 ? col - leftWindow : 1 |
| 216 | let rightCol = |
| 217 | evidence.length > col + rightWindow ? col + rightWindow : evidenceCount |
| 218 | |
| 219 | if (col < leftWindow + 1) { |
| 220 | rightCol += leftWindow - col + 1 |
| 221 | } |
| 222 | |
| 223 | evidence = evidence.replace(/\t/g, ' ').substring(leftCol - 1, rightCol) |
| 224 | |
| 225 | // add ... |
| 226 | if (leftCol > 1) { |
| 227 | evidence = `...${evidence}` |
| 228 | leftCol -= 3 |
| 229 | } |
| 230 | if (rightCol < evidenceCount) { |
| 231 | evidence += '...' |
| 232 | } |
| 233 | |
| 234 | // show evidence |
| 235 | arrLogs.push( |
| 236 | `${colors.white + repeatStr(indent)}L${line} |${ |
| 237 | colors.grey |
| 238 | }${evidence}${colors.reset}` |
| 239 | ) |
| 240 | |
| 241 | // show pointer & message |
| 242 | let pointCol = col - leftCol |
| 243 | // add double byte character |
| 244 | // eslint-disable-next-line no-control-regex |
| 245 | const match = evidence.substring(0, pointCol).match(/[^\u0000-\u00ff]/g) |
| 246 | if (match !== null) { |
| 247 | pointCol += match.length |
no test coverage detected