@shahmilsaari/memory-core 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +27 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -788,6 +788,30 @@ import { execSync as execSync2 } from "child_process";
|
|
|
788
788
|
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
789
789
|
import { join as join5, relative } from "path";
|
|
790
790
|
import chalk2 from "chalk";
|
|
791
|
+
function getFileLines(filePath) {
|
|
792
|
+
try {
|
|
793
|
+
return readFileSync4(filePath, "utf-8").split("\n");
|
|
794
|
+
} catch {
|
|
795
|
+
return [];
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
function printCodeContext(filePath, line, contextLines = 2) {
|
|
799
|
+
const lines = getFileLines(filePath);
|
|
800
|
+
if (lines.length === 0) return;
|
|
801
|
+
const start = Math.max(0, line - 1 - contextLines);
|
|
802
|
+
const end = Math.min(lines.length - 1, line - 1 + contextLines);
|
|
803
|
+
console.log(chalk2.dim(" \u250C\u2500 code \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
804
|
+
for (let i = start; i <= end; i++) {
|
|
805
|
+
const lineNum = String(i + 1).padStart(4, " ");
|
|
806
|
+
const isViolation = i === line - 1;
|
|
807
|
+
if (isViolation) {
|
|
808
|
+
console.log(chalk2.red(` \u2502 ${lineNum} \u25B6 ${lines[i]}`));
|
|
809
|
+
} else {
|
|
810
|
+
console.log(chalk2.dim(` \u2502 ${lineNum} ${lines[i]}`));
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
console.log(chalk2.dim(" \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
814
|
+
}
|
|
791
815
|
var SOURCE_EXTENSIONS = /\.(ts|tsx|js|jsx|py|php|rb|go|java|cs|swift|kt|rs|vue|svelte)$/;
|
|
792
816
|
var reasonMap2 = new Map(
|
|
793
817
|
seeds.filter((s) => s.reason).map((s) => [s.content, s.reason])
|
|
@@ -920,6 +944,9 @@ ${diffToSend}` }
|
|
|
920
944
|
console.log(chalk2.yellow(" Rule: ") + v.rule);
|
|
921
945
|
const why = v.reason ?? reasonMap2.get(v.rule);
|
|
922
946
|
if (why) console.log(chalk2.dim(" Why: ") + chalk2.dim(why));
|
|
947
|
+
if (v.line && existsSync5(filePath)) {
|
|
948
|
+
printCodeContext(filePath, v.line, 1);
|
|
949
|
+
}
|
|
923
950
|
if (v.issue) console.log(chalk2.red(" Issue: ") + v.issue);
|
|
924
951
|
if (v.suggestion) console.log(chalk2.green(" Fix: ") + v.suggestion);
|
|
925
952
|
console.log();
|