-
Notifications
You must be signed in to change notification settings - Fork 0
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
Displaying removal and adding of lines #2
base: master
Are you sure you want to change the base?
Conversation
var validCurData = (curData && curData.length !== 2); | ||
var fileType = convertType(path.extname(files[1]).substring(1)); | ||
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```'; |
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.
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'; |
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 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'); |
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 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.
console.log("Hello World"); |
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.
added white spaces to ensure the diffChecker, ignores white spaces
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.