Open
Conversation
DanDaManTran
commented
Jun 25, 2024
| var useCurData = useCurData ? validCurData && (typeof curData.description === "string") && !curData.body : false;; | ||
| var markdown = '\n```' + fileType + '\n' + file2 + '\n```'; | ||
| var diffLines = diffChecker.diff(file1, file2); | ||
| var markdown = '\n```' + fileType + '\n' + diffFile.join('\n') + '\n```'; |
Contributor
Author
There was a problem hiding this comment.
To display if there removed any lines, we had to create a new "file" to display added and removed lines
| const Diff = require('diff'); | ||
|
|
||
| function normalizeLines(str) { | ||
| const strWithNewLine = str.endsWith('\n') ? str : str + '\n'; |
Contributor
Author
There was a problem hiding this comment.
When adding lines to the end of a file, the 'diff' package reads it as removing and adding the last line even though there isn't any changes. This line is to ensure a \n at the end so the package can read it as unchanged line.
| function normalizeLines(str) { | ||
| const strWithNewLine = str.endsWith('\n') ? str : str + '\n'; | ||
|
|
||
| return strWithNewLine.split('\n').map(line => line.replace(/\s+$/, '')).join('\n'); |
Contributor
Author
There was a problem hiding this comment.
This is to clear out trailing white spaces. The package has a property to ignore white spaces, but when trying to rebuild the diff file, it removed all the indentation.
| @@ -1 +1 @@ | |||
| console.log("hello world"); No newline at end of file | |||
| console.log("Hello World"); No newline at end of file | |||
Contributor
Author
There was a problem hiding this comment.
added white spaces to ensure the diffChecker, ignores white spaces
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here are the end results of the diff updates. If there is concern about red highlights for removed lines, there is a ticket to handle highlight update.