diff --git a/src/diff-parser.ts b/src/diff-parser.ts index 00f597d..7a5fc5d 100644 --- a/src/diff-parser.ts +++ b/src/diff-parser.ts @@ -23,7 +23,7 @@ function getFilename(line: string, linePrefix?: string, extraPrefix?: string): s ? new RegExp(`^${escapeForRegExp(linePrefix)} "?(.+?)"?$`) : new RegExp('^"?(.+?)"?$'); - const [, filename = ""] = FilenameRegExp.exec(line) || []; // TODO: Check if this is safe + const [, filename = ""] = FilenameRegExp.exec(line) || []; const matchingPrefix = prefixes.find(p => filename.indexOf(p) === 0); const fnameWithoutPrefix = matchingPrefix ? filename.slice(matchingPrefix.length) : filename; @@ -132,7 +132,6 @@ export function parse(diffInput: string, config: DiffParserConfig = {}): DiffFil saveBlock(); saveFile(); - // TODO: Avoid disabling types // eslint-disable-next-line // @ts-ignore currentFile = { @@ -183,7 +182,6 @@ export function parse(diffInput: string, config: DiffParserConfig = {}): DiffFil } /* Create block metadata */ - // TODO: Avoid disabling types // eslint-disable-next-line // @ts-ignore currentBlock = { @@ -198,7 +196,6 @@ export function parse(diffInput: string, config: DiffParserConfig = {}): DiffFil function createLine(line: string): void { if (currentFile === null || currentBlock === null || oldLine === null || newLine === null) return; - // TODO: Avoid disabling types // eslint-disable-next-line // @ts-ignore const currentLine: DiffLine = { @@ -208,7 +205,6 @@ export function parse(diffInput: string, config: DiffParserConfig = {}): DiffFil const addedPrefixes = currentFile.isCombined ? ["+ ", " +", "++"] : ["+"]; const deletedPrefixes = currentFile.isCombined ? ["- ", " -", "--"] : ["-"]; - // TODO: Check if this makes sense for combined diff if (startsWithAny(line, addedPrefixes)) { currentFile.addedLines++; currentLine.type = LineType.INSERT; diff --git a/src/diff2html.ts b/src/diff2html.ts index 2b22b9c..1275eeb 100644 --- a/src/diff2html.ts +++ b/src/diff2html.ts @@ -39,10 +39,5 @@ export function html(diffInput: string | DiffFile[], configuration: Diff2HtmlCon ? new SideBySideRenderer(hoganUtils, config).render(diffJson) : new LineByLineRenderer(hoganUtils, config).render(diffJson); - // TODO: Review error handling - if (diffOutput === undefined) { - throw new Error("OMG we haz no diff. Why???"); - } - return fileList + diffOutput; } diff --git a/src/line-by-line-renderer.ts b/src/line-by-line-renderer.ts index 8e609de..02fd731 100644 --- a/src/line-by-line-renderer.ts +++ b/src/line-by-line-renderer.ts @@ -39,7 +39,7 @@ export default class LineByLineRenderer { this.config = { ...defaultLineByLineRendererConfig, ...config }; } - render(diffFiles: DiffFile[]): string | undefined { + render(diffFiles: DiffFile[]): string { const diffsHtml = diffFiles .map(file => { let diffs; @@ -55,7 +55,6 @@ export default class LineByLineRenderer { return this.hoganUtils.render(genericTemplatesPath, "wrapper", { content: diffsHtml }); } - // TODO: Make this private after improving tests makeFileDiffHtml(file: DiffFile, diffs: string): string { if (this.config.renderNothingWhenEmpty && Array.isArray(file.blocks) && file.blocks.length === 0) return ""; @@ -80,7 +79,6 @@ export default class LineByLineRenderer { }); } - // TODO: Make this private after improving tests generateEmptyDiff(): string { return this.hoganUtils.render(genericTemplatesPath, "empty-diff", { contentClass: "d2h-code-line", @@ -192,7 +190,6 @@ export default class LineByLineRenderer { return matches; } - // TODO: Make this private after improving tests processChangedLines(isCombined: boolean, oldLines: DiffLine[], newLines: DiffLine[]): FileHtml { const fileHtml = { right: "", @@ -253,7 +250,6 @@ export default class LineByLineRenderer { return fileHtml; } - // TODO: Make this private after improving tests generateLineHtml(oldLine?: DiffPreparedLine, newLine?: DiffPreparedLine): FileHtml { return { left: this.generateSingleLineHtml(oldLine), diff --git a/src/render-utils.ts b/src/render-utils.ts index b32317b..73a1c60 100644 --- a/src/render-utils.ts +++ b/src/render-utils.ts @@ -113,7 +113,6 @@ export function deconstructLine(line: string, isCombined: boolean): DiffLinePart * returns "my/path/{to → for}/file.js" */ export function filenameDiff(file: DiffFileName): string { - // TODO: Review this huuuuuge piece of code, do we need this? // TODO: Move unify path to parsing const oldFilename = unifyPath(file.oldName); const newFilename = unifyPath(file.newName); diff --git a/src/side-by-side-renderer.ts b/src/side-by-side-renderer.ts index d7f714b..72daa14 100644 --- a/src/side-by-side-renderer.ts +++ b/src/side-by-side-renderer.ts @@ -39,7 +39,7 @@ export default class SideBySideRenderer { this.config = { ...defaultSideBySideRendererConfig, ...config }; } - render(diffFiles: DiffFile[]): string | undefined { + render(diffFiles: DiffFile[]): string { const diffsHtml = diffFiles .map(file => { let diffs; @@ -55,7 +55,6 @@ export default class SideBySideRenderer { return this.hoganUtils.render(genericTemplatesPath, "wrapper", { content: diffsHtml }); } - // TODO: Make this private after improving tests makeFileDiffHtml(file: DiffFile, diffs: FileHtml): string { if (this.config.renderNothingWhenEmpty && Array.isArray(file.blocks) && file.blocks.length === 0) return ""; @@ -80,7 +79,6 @@ export default class SideBySideRenderer { }); } - // TODO: Make this private after improving tests generateEmptyDiff(): FileHtml { return { right: "", @@ -207,7 +205,6 @@ export default class SideBySideRenderer { return matches; } - // TODO: Make this private after improving tests makeHeaderHtml(blockHeader: string): string { return this.hoganUtils.render(genericTemplatesPath, "block-header", { CSSLineClass: renderUtils.CSSLineClass, @@ -217,7 +214,6 @@ export default class SideBySideRenderer { }); } - // TODO: Make this private after improving tests processChangedLines(isCombined: boolean, oldLines: DiffLine[], newLines: DiffLine[]): FileHtml { const fileHtml = { right: "", @@ -276,7 +272,6 @@ export default class SideBySideRenderer { return fileHtml; } - // TODO: Make this private after improving tests generateLineHtml(oldLine?: DiffPreparedLine, newLine?: DiffPreparedLine): FileHtml { return { left: this.generateSingleHtml(oldLine),