-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ensure cli-reporter displays the correct message. (#1774)
* fix: Ensure cli-reporter displays the correct message. - Use a substitution function to ensure Issue formatting is correct. * Update snapshots impacted.
- Loading branch information
Showing
6 changed files
with
117 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { __testing__, ReporterIssue } from './cli-reporter'; | ||
|
||
const { formatIssue } = __testing__; | ||
|
||
const doc = ` | ||
This is a simple document with a bit of text. | ||
It has more than one line. | ||
$myPhpOffset := $row + $col; | ||
$uri:$filename:$row:$col$padRowCol,$message,$text,$padContext,$contextLeft,$text,$contextRight,[$suggestions] | ||
And some words to be used for some spelling issues. | ||
There are many options. | ||
`; | ||
|
||
describe('cli-reporter', () => { | ||
test.each` | ||
issue | template | expected | ||
${genIssue('line')} | ${''} | ${''} | ||
${genIssue('line')} | ${'$row:$col:$text'} | ${'4:21:line'} | ||
${genIssue('$col')} | ${'$row:$col:$text'} | ${'6:23:$col'} | ||
${genIssue('$col')} | ${'$row:$col:$text - $contextFull'} | ${'6:23:$col - := $row + $col;'} | ||
${genIssue('message')} | ${'$row:$col:$text - $contextFull'} | ${'8:36:message - adRowCol,$message,$text,$pa'} | ||
${genIssue('used')} | ${'$contextLeft:$text:$contextRight - $contextFull'} | ${'rds to be :used: for some - rds to be used for some '} | ||
`('formatIssue', ({ issue, template, expected }) => { | ||
expect(formatIssue(template, issue, 200)).toBe(expected); | ||
}); | ||
}); | ||
|
||
function genIssue(word: string): ReporterIssue { | ||
const offset = doc.indexOf(word); | ||
const text = word; | ||
const beforeText = doc.slice(0, offset); | ||
const prevLines = beforeText.split('\n'); | ||
const lines = doc.split('\n'); | ||
const row = prevLines.length; | ||
const lineText = lines[row - 1]; | ||
const line = { offset: doc.indexOf(lineText), text: lineText }; | ||
const col = offset - line.offset; | ||
|
||
const contextL = Math.max(0, col - 10); | ||
const contextR = Math.min(lineText.length, col + text.length + 10); | ||
const context = { offset: line.offset + contextL, text: line.text.slice(contextL, contextR) }; | ||
|
||
const issue: ReporterIssue = { | ||
filename: 'path/filename', | ||
offset, | ||
uri: 'file://uri/path/filename', | ||
context, | ||
doc, | ||
line, | ||
col, | ||
row, | ||
text, | ||
}; | ||
|
||
return issue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters