Conversation
|
|
||
| function getIgnoreCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string): { lineNumber: number, change: TextChange } { | ||
| function makeChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, position: number, newLineCharacter: string, seenLines?: Map<true>) { | ||
| if (isInComment(sourceFile, position) || isInString(sourceFile, position) || isInTemplateString(sourceFile, position)) { |
There was a problem hiding this comment.
When we call makeChange we're about to unconditionally return the codefix -- so this would advertise the fix as available and do nothing?
There was a problem hiding this comment.
this is for the other code path for multiple entries.. i can split it.
There was a problem hiding this comment.
and we already had a test for it.
| } | ||
| // If so, we do not want to separate the node from its comment if we can. | ||
| // Otherwise, add an extra new line immediately before the error span. | ||
| const insertAtLineStart = !isInComment(sourceFile, startPosition) && |
There was a problem hiding this comment.
Just checked for this at top, so should always be true?
There was a problem hiding this comment.
that is a different position
There was a problem hiding this comment.
OK. Could this line be isValidSuppressLocation(sourceFile, startPosition);?
| }); | ||
|
|
||
| function getIgnoreCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string): { lineNumber: number, change: TextChange } { | ||
| function makeChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, position: number, newLineCharacter: string, seenLines?: Map<true>) { |
There was a problem hiding this comment.
It would be neater if changes handled the newlines itself -- see discussion at #20574.
There was a problem hiding this comment.
it is the only place where we do something like this with comments. i did not make much sense to put it in the tracker.
There was a problem hiding this comment.
You could also make changes.newLineCharacter public to avoid computing it yourself. There's no particular reason for it to be private if you want to handle newlines yourself in this use.
src/services/textChanges.ts
Outdated
| /** | ||
| * Do not trim leading white spaces in the edit range | ||
| */ | ||
| preseveLeadingWhiteSpaces?: boolean; |
There was a problem hiding this comment.
preserveLeadingWhitespace
| const seenLines = createMap<true>(); | ||
| return codeFixAll(context, errorCodes, (changes, diag) => { | ||
| if (isValidSuppressLocation(diag.file!, diag.start!)) { | ||
| return makeChange(changes, diag.file!, diag.start!, seenLines); |
There was a problem hiding this comment.
No need to return makeChange, it returns void.
Use change tracker instead of direct text edits to add
// @ts-checkabove statements.Fixes #21355