Feat: ability to handle inline comment

This commit is contained in:
SukkaW
2025-08-17 17:35:02 +08:00
parent fe7278c7fa
commit 373f862c6d
7 changed files with 22 additions and 10 deletions

View File

@@ -45,9 +45,11 @@ export function fetchRemoteTextByLine(url: string, processLine = false): Promise
export async function readFileIntoProcessedArray(file: string /* | FileHandle */) {
const results = [];
let processed: string | null = '';
for await (const line of readFileByLine(file)) {
if (processLine(line)) {
results.push(line);
processed = processLine(line);
if (processed) {
results.push(processed);
}
}
return results;

View File

@@ -37,6 +37,12 @@ export function processLine(line: string): string | null {
*/
}
const otherPoundSign = trimmed.indexOf('#');
if (otherPoundSign > 0) {
return trimmed.slice(0, otherPoundSign).trimEnd();
}
return trimmed;
}

View File

@@ -9,8 +9,9 @@ export default async function runAgainstSourceFile(
/** Secret keyword collection, only use for special purpose */
keywordSet?: Set<string> | null
) {
let l: string | null = '';
for await (const line of readFileByLine(filePath)) {
const l = processLine(line);
l = processLine(line);
if (!l) {
continue;
}