-
Notifications
You must be signed in to change notification settings - Fork 3
Shared tsconfig.json & update options #29
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
Changes from all commits
2c88e8a
ab8f1eb
200bf3c
166ba41
1dea84d
cb3a089
d7fc237
246c361
372bfa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,43 +34,50 @@ export function resolveHunkReferencesInComments(comments: AiReview["comments"], | |
| core.warning(`Could not find file for comment on ${comment.path}, start ${comment.start}, end ${comment.end}, ${comment.comment}, skipping.`) | ||
| } else { | ||
| const hunkChangeMap = currentFile.chunks.flatMap(hunk => hunk.changes.map(change => ({ change, hunk }))) | ||
| let { change: startChange, hunk: startHunk } = hunkChangeMap[comment.start - 1] // eslint-disable-line prefer-const | ||
| let { change: endChange, hunk: endHunk } = hunkChangeMap[comment.end - 1] // eslint-disable-line prefer-const | ||
| const startEntry = hunkChangeMap[comment.start - 1] | ||
| const endEntry = hunkChangeMap[comment.end - 1] | ||
|
|
||
| if (!startHunk) { | ||
| core.warning(`Could not find hunk for comment on ${comment.path}, start ${comment.start}, end ${comment.end}, ${comment.comment}, skipping.`) | ||
| if (!startEntry || !endEntry) { | ||
| core.error(`Could not find hunk for comment on ${comment.path}, start ${comment.start}, end ${comment.end}, ${comment.comment}, skipping.`) | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| if (startHunk !== endHunk) endChange = startHunk.changes.at(-1)! | ||
| const { change: startChange, hunk: startHunk } = startEntry | ||
| let { change: endChange, hunk: endHunk } = endEntry // eslint-disable-line prefer-const | ||
|
Comment on lines
36
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The nested destructuring and multiple function getHunkEntry(index: number) {
const entry = hunkChangeMap[index];
if (!entry) core.error(`Missing hunk entry at index ${index}`);
return entry;
}
const startEntry = getHunkEntry(comment.start - 1);
const endEntry = getHunkEntry(comment.end - 1);
if (!startEntry || !endEntry) return; // skipThis moves validation early, flattens the control flow, and makes the main logic more linear. |
||
|
|
||
| const startSide = startChange.type !== "del" ? "RIGHT" : "LEFT" | ||
| const endSide = endChange.type !== "del" ? "RIGHT" : "LEFT" | ||
| if (!startHunk) { | ||
| core.warning(`Could not find hunk for comment on ${comment.path}, start ${comment.start}, end ${comment.end}, ${comment.comment}, skipping.`) | ||
| } else { | ||
| if (startHunk !== endHunk) endChange = startHunk.changes.at(-1)! | ||
|
|
||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // get start line of the actual comment | ||
| let start: number | ||
| if (startChange.type === "normal") { | ||
| start = startChange.ln2 | ||
| } else if (startChange.type === "add" || startChange.type === "del") { | ||
| start = startChange.ln | ||
| } else throw new Error(`Unknown change type.`) | ||
| const startSide = startChange.type !== "del" ? "RIGHT" : "LEFT" | ||
| const endSide = endChange.type !== "del" ? "RIGHT" : "LEFT" | ||
|
Comment on lines
-45
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're repeating the same pattern to compute a line number based on function getLineNumber(change: Change): number {
switch (change.type) {
case 'normal': return change.ln2;
case 'add':
case 'del': return change.ln;
default: throw new Error(`Unknown change type: ${change.type}`);
}
}Then you can write: const start = getLineNumber(startChange);
const end = getLineNumber(endChange);This removes repetition and centralizes error handling for unexpected |
||
|
|
||
| // get end line of the actual comment | ||
| let end: number | ||
| if (endChange.type === "normal") { | ||
| end = endChange.ln2 | ||
| } else if (endChange.type === "add" || endChange.type === "del") { | ||
| end = endChange.ln | ||
| } else throw new Error(`Unknown change type.`) | ||
| // make sure start and end are within the hunk | ||
| end = Math.min(end, endSide === "RIGHT" ? startHunk.newStart + startHunk.newLines - 1 : startHunk.oldStart + startHunk.oldLines - 1) | ||
| // get start line of the actual comment | ||
| let start: number | ||
| if (startChange.type === "normal") { | ||
| start = startChange.ln2 | ||
| } else if (startChange.type === "add" || startChange.type === "del") { | ||
| start = startChange.ln | ||
| } else throw new Error(`Unknown change type.`) | ||
|
|
||
| result.push({ | ||
| path: comment.path, | ||
| start_side: startSide !== endSide ? startSide : undefined, // only set start_side if it is a multi-line comment | ||
| side: startSide !== endSide ? endSide : startSide, | ||
| start_line: start !== end && start < end ? start : undefined, // only set start_line if it is a multi-line comment, start must be less than end | ||
| line: start !== end && start < end ? end : start, | ||
| body: comment.comment, | ||
| }) | ||
| // get end line of the actual comment | ||
| let end: number | ||
| if (endChange.type === "normal") { | ||
| end = endChange.ln2 | ||
| } else if (endChange.type === "add" || endChange.type === "del") { | ||
| end = endChange.ln | ||
| } else throw new Error(`Unknown change type.`) | ||
| // make sure start and end are within the hunk | ||
| end = Math.min(end, endSide === "RIGHT" ? startHunk.newStart + startHunk.newLines - 1 : startHunk.oldStart + startHunk.oldLines - 1) | ||
|
|
||
| result.push({ | ||
| path: comment.path, | ||
| start_side: startSide !== endSide ? startSide : undefined, // only set start_side if it is a multi-line comment | ||
| side: startSide !== endSide ? endSide : startSide, | ||
| start_line: start !== end && start < end ? start : undefined, // only set start_line if it is a multi-line comment, start must be less than end | ||
| line: start !== end && start < end ? end : start, | ||
| body: comment.comment, | ||
| }) | ||
| } | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,7 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/tsconfig", | ||
| "extends": "../tsconfig.json", | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "compilerOptions": { | ||
| "target": "ES2022", | ||
| "module": "NodeNext", | ||
| "rootDir": "./src", | ||
| "moduleResolution": "NodeNext", | ||
| "baseUrl": "./", | ||
| "sourceMap": true, | ||
| "outDir": "./dist", | ||
| "noImplicitAny": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "strict": true, | ||
| "skipLibCheck": true, | ||
| "newLine": "lf" | ||
| }, | ||
| "exclude": ["./dist", "./node_modules", "./__tests__", "./coverage"] | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "rootDir": "./src" | ||
| } | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,7 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/tsconfig", | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "target": "ES2022", | ||
| "module": "NodeNext", | ||
| "rootDir": "./src", | ||
| "moduleResolution": "NodeNext", | ||
| "baseUrl": "./", | ||
| "sourceMap": true, | ||
| "outDir": "./dist", | ||
| "noImplicitAny": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "strict": true, | ||
| "skipLibCheck": true, | ||
| "newLine": "lf" | ||
| }, | ||
| "exclude": ["./dist", "./node_modules"] | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "rootDir": "./src" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/tsconfig", | ||
| "compilerOptions": { | ||
| "composite": true, | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "target": "esnext", | ||
| "module": "nodenext", | ||
| "moduleResolution": "nodenext", | ||
| "baseUrl": "./", | ||
| "sourceMap": true, | ||
| "outDir": "./dist", | ||
| "noImplicitAny": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "noUncheckedIndexedAccess": true, | ||
| "strict": true, | ||
| "skipLibCheck": true, | ||
| "newLine": "lf", | ||
| "erasableSyntaxOnly": true, | ||
| "rewriteRelativeImportExtensions": true | ||
| }, | ||
| "exclude": ["./dist", "./node_modules", "./__tests__", "./coverage"] | ||
| } | ||
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
daniel-richter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.