Skip to content
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

Merged
merged 9 commits into from
Mar 6, 2018
Merged

Fix ignore message indentation #22340

merged 9 commits into from
Mar 6, 2018

Conversation

mhegazy
Copy link
Contributor

@mhegazy mhegazy commented Mar 5, 2018

Use change tracker instead of direct text edits to add // @ts-check above statements.

Fixes #21355

@mhegazy mhegazy requested a review from a user March 5, 2018 20:19
},
});

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)) {
Copy link

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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) &&
Copy link

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?

Copy link
Contributor Author

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

Copy link

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);?

Copy link
Contributor Author

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>) {
Copy link

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.

Copy link
Contributor Author

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.

Copy link

@ghost ghost Mar 5, 2018

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.

/**
* Do not trim leading white spaces in the edit range
*/
preseveLeadingWhiteSpaces?: boolean;
Copy link
Member

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);
Copy link

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.

@mhegazy mhegazy merged commit b2dd610 into master Mar 6, 2018
@mhegazy mhegazy deleted the fixIgnoreMessageIndentation branch March 6, 2018 20:19
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants