MCPcopy
hub / github.com/htmlhint/HTMLHint / format

Method format

src/core/core.ts:190–260  ·  view source on GitHub ↗
(arrMessages: Hint[], options: FormatOptions = {})

Source from the content-addressed store, hash-verified

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

Callers 4

core.spec.jsFile · 0.80
defaultFormatterFunction · 0.80
markdownFormatterFunction · 0.80
junitFormatterFunction · 0.80

Calls 1

repeatStrFunction · 0.85

Tested by

no test coverage detected