-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ignore message indentation #22340
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for the other code path for multiple entries.. i can split it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked for this at top, so should always be true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is a different position
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Could this line be isValidSuppressLocation(sourceFile, startPosition);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
}, | ||
}); | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be neater if changes
handled the newlines itself -- see discussion at #20574.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to return makeChange
, it returns void.
Use change tracker instead of direct text edits to add
// @ts-check
above statements.Fixes #21355