@cencori/scan 0.4.4 → 0.4.5
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 +106 -67
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +107 -68
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -906,24 +906,6 @@ Generate a secure fix.`
|
|
|
906
906
|
}
|
|
907
907
|
return results;
|
|
908
908
|
}
|
|
909
|
-
async function applyFixes(fixes, fileContents) {
|
|
910
|
-
for (const fix of fixes) {
|
|
911
|
-
if (fix.fixedCode === fix.originalCode) {
|
|
912
|
-
continue;
|
|
913
|
-
}
|
|
914
|
-
const content = fileContents.get(fix.issue.file);
|
|
915
|
-
if (!content) {
|
|
916
|
-
continue;
|
|
917
|
-
}
|
|
918
|
-
const newContent = content.replace(fix.originalCode, fix.fixedCode);
|
|
919
|
-
if (newContent !== content) {
|
|
920
|
-
const filePath = path2.resolve(fix.issue.file);
|
|
921
|
-
fs2.writeFileSync(filePath, newContent, "utf-8");
|
|
922
|
-
fix.applied = true;
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
return fixes;
|
|
926
|
-
}
|
|
927
909
|
|
|
928
910
|
// src/telemetry.ts
|
|
929
911
|
var TELEMETRY_URL = "https://api.cencori.com/v1/telemetry/scan";
|
|
@@ -1176,7 +1158,7 @@ No commits found in the specified period.
|
|
|
1176
1158
|
// src/cli.ts
|
|
1177
1159
|
var fs3 = __toESM(require("fs"));
|
|
1178
1160
|
var path3 = __toESM(require("path"));
|
|
1179
|
-
var VERSION = "0.4.
|
|
1161
|
+
var VERSION = "0.4.5";
|
|
1180
1162
|
var scoreStyles = {
|
|
1181
1163
|
A: { color: import_chalk.default.green },
|
|
1182
1164
|
B: { color: import_chalk.default.blue },
|
|
@@ -1411,57 +1393,108 @@ async function handleAutoFix(result, targetPath) {
|
|
|
1411
1393
|
fileContents
|
|
1412
1394
|
);
|
|
1413
1395
|
fixSpinner.succeed(`Generated ${fixes.length} fixes`);
|
|
1414
|
-
const applySpinner = (0, import_ora.default)({
|
|
1415
|
-
text: "Applying fixes...",
|
|
1416
|
-
color: "cyan"
|
|
1417
|
-
}).start();
|
|
1418
|
-
const appliedFixes = await applyFixes(fixes, fileContents);
|
|
1419
|
-
const appliedCount = appliedFixes.filter((f) => f.applied).length;
|
|
1420
|
-
applySpinner.succeed(`Applied ${appliedCount}/${fixes.length} fixes`);
|
|
1421
1396
|
console.log();
|
|
1422
|
-
const
|
|
1423
|
-
const
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1397
|
+
const acceptedFixes = [];
|
|
1398
|
+
const skippedFixes = [];
|
|
1399
|
+
let applyAll = false;
|
|
1400
|
+
let skipRest = false;
|
|
1401
|
+
for (let i = 0; i < fixes.length; i++) {
|
|
1402
|
+
const fix = fixes[i];
|
|
1403
|
+
if (skipRest) {
|
|
1404
|
+
skippedFixes.push(fix);
|
|
1405
|
+
continue;
|
|
1429
1406
|
}
|
|
1407
|
+
if (applyAll) {
|
|
1408
|
+
acceptedFixes.push(fix);
|
|
1409
|
+
continue;
|
|
1410
|
+
}
|
|
1411
|
+
console.log(import_chalk.default.cyan(` \u2500\u2500\u2500 Fix ${i + 1}/${fixes.length}: ${fix.issue.file}:${fix.issue.line} \u2500\u2500\u2500`));
|
|
1412
|
+
console.log(import_chalk.default.gray(` Issue: ${fix.issue.name} (${fix.issue.severity})`));
|
|
1430
1413
|
console.log();
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
console.log(
|
|
1414
|
+
const origLines = fix.originalCode.split("\n");
|
|
1415
|
+
console.log(import_chalk.default.red(" - Original:"));
|
|
1416
|
+
origLines.slice(0, 8).forEach((line) => console.log(import_chalk.default.red(` ${line}`)));
|
|
1417
|
+
if (origLines.length > 8) {
|
|
1418
|
+
console.log(import_chalk.default.gray(` ... (${origLines.length - 8} more lines)`));
|
|
1419
|
+
}
|
|
1420
|
+
console.log();
|
|
1421
|
+
const fixLines = fix.fixedCode.split("\n");
|
|
1422
|
+
console.log(import_chalk.default.green(" + Suggested fix:"));
|
|
1423
|
+
fixLines.slice(0, 8).forEach((line) => console.log(import_chalk.default.green(` ${line}`)));
|
|
1424
|
+
if (fixLines.length > 8) {
|
|
1425
|
+
console.log(import_chalk.default.gray(` ... (${fixLines.length - 8} more lines)`));
|
|
1426
|
+
}
|
|
1434
1427
|
console.log();
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1428
|
+
console.log(import_chalk.default.gray(` Explanation: ${fix.explanation}`));
|
|
1429
|
+
console.log();
|
|
1430
|
+
const action = await (0, import_prompts.select)({
|
|
1431
|
+
message: "Apply this fix?",
|
|
1432
|
+
choices: [
|
|
1433
|
+
{ name: "Yes - apply this fix", value: "y" },
|
|
1434
|
+
{ name: "No - skip this fix", value: "n" },
|
|
1435
|
+
{ name: "All - apply all remaining fixes", value: "a" },
|
|
1436
|
+
{ name: "Skip rest - save remaining to file", value: "s" },
|
|
1437
|
+
{ name: "Quit - stop reviewing", value: "q" }
|
|
1438
|
+
]
|
|
1439
|
+
});
|
|
1440
|
+
if (action === "y") {
|
|
1441
|
+
acceptedFixes.push(fix);
|
|
1442
|
+
console.log(import_chalk.default.green(" \u2714 Fix accepted"));
|
|
1443
|
+
} else if (action === "n") {
|
|
1444
|
+
skippedFixes.push(fix);
|
|
1445
|
+
console.log(import_chalk.default.yellow(" \u2298 Fix skipped"));
|
|
1446
|
+
} else if (action === "a") {
|
|
1447
|
+
applyAll = true;
|
|
1448
|
+
acceptedFixes.push(fix);
|
|
1449
|
+
for (let j = i + 1; j < fixes.length; j++) {
|
|
1450
|
+
acceptedFixes.push(fixes[j]);
|
|
1445
1451
|
}
|
|
1446
|
-
console.log();
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
+
console.log(import_chalk.default.green(` \u2714 Applying all ${fixes.length - i} remaining fixes`));
|
|
1453
|
+
break;
|
|
1454
|
+
} else if (action === "s") {
|
|
1455
|
+
skipRest = true;
|
|
1456
|
+
skippedFixes.push(fix);
|
|
1457
|
+
for (let j = i + 1; j < fixes.length; j++) {
|
|
1458
|
+
skippedFixes.push(fixes[j]);
|
|
1452
1459
|
}
|
|
1453
|
-
console.log(import_chalk.default.
|
|
1454
|
-
|
|
1460
|
+
console.log(import_chalk.default.yellow(` \u2298 Skipping ${fixes.length - i} remaining fixes`));
|
|
1461
|
+
break;
|
|
1462
|
+
} else if (action === "q") {
|
|
1463
|
+
skippedFixes.push(fix);
|
|
1464
|
+
for (let j = i + 1; j < fixes.length; j++) {
|
|
1465
|
+
skippedFixes.push(fixes[j]);
|
|
1466
|
+
}
|
|
1467
|
+
console.log(import_chalk.default.gray(" Stopped reviewing"));
|
|
1468
|
+
break;
|
|
1455
1469
|
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1470
|
+
console.log();
|
|
1471
|
+
}
|
|
1472
|
+
if (acceptedFixes.length > 0) {
|
|
1473
|
+
console.log();
|
|
1474
|
+
const applySpinner = (0, import_ora.default)({
|
|
1475
|
+
text: `Applying ${acceptedFixes.length} fixes...`,
|
|
1476
|
+
color: "cyan"
|
|
1477
|
+
}).start();
|
|
1478
|
+
let appliedCount = 0;
|
|
1479
|
+
for (const fix of acceptedFixes) {
|
|
1480
|
+
const content = fileContents.get(fix.issue.file);
|
|
1481
|
+
if (!content) continue;
|
|
1482
|
+
const newContent = content.replace(fix.originalCode, fix.fixedCode);
|
|
1483
|
+
if (newContent !== content) {
|
|
1484
|
+
const filePath = path3.resolve(targetPath, fix.issue.file);
|
|
1485
|
+
fs3.writeFileSync(filePath, newContent, "utf-8");
|
|
1486
|
+
fileContents.set(fix.issue.file, newContent);
|
|
1487
|
+
appliedCount++;
|
|
1488
|
+
}
|
|
1459
1489
|
}
|
|
1490
|
+
applySpinner.succeed(`Applied ${appliedCount}/${acceptedFixes.length} fixes to your codebase`);
|
|
1491
|
+
}
|
|
1492
|
+
if (skippedFixes.length > 0) {
|
|
1460
1493
|
const fixesFile = ".cencori-fixes.json";
|
|
1461
1494
|
const fixesData = {
|
|
1462
1495
|
generated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1463
|
-
total_fixes:
|
|
1464
|
-
fixes:
|
|
1496
|
+
total_fixes: skippedFixes.length,
|
|
1497
|
+
fixes: skippedFixes.map((f) => ({
|
|
1465
1498
|
file: f.issue.file,
|
|
1466
1499
|
line: f.issue.line,
|
|
1467
1500
|
issue_type: f.issue.type,
|
|
@@ -1473,16 +1506,22 @@ async function handleAutoFix(result, targetPath) {
|
|
|
1473
1506
|
}))
|
|
1474
1507
|
};
|
|
1475
1508
|
fs3.writeFileSync(fixesFile, JSON.stringify(fixesData, null, 2));
|
|
1476
|
-
console.log(import_chalk.default.gray(" \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
1477
|
-
console.log();
|
|
1478
|
-
console.log(` ${import_chalk.default.bold("Next steps:")}`);
|
|
1479
|
-
console.log(import_chalk.default.cyan(` 1. Review fixes in ${import_chalk.default.bold(fixesFile)}`));
|
|
1480
|
-
console.log(import_chalk.default.cyan(` 2. Apply fixes manually to your codebase`));
|
|
1481
|
-
console.log(import_chalk.default.cyan(` 3. Run ${import_chalk.default.bold("npx @cencori/scan")} again to verify`));
|
|
1482
1509
|
console.log();
|
|
1510
|
+
console.log(import_chalk.default.yellow(` ${skippedFixes.length} skipped fixes saved to ${import_chalk.default.bold(fixesFile)}`));
|
|
1483
1511
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1512
|
+
console.log();
|
|
1513
|
+
console.log(import_chalk.default.gray(" \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
1514
|
+
console.log();
|
|
1515
|
+
console.log(` ${import_chalk.default.bold("Summary:")}`);
|
|
1516
|
+
if (acceptedFixes.length > 0) {
|
|
1517
|
+
console.log(import_chalk.default.green(` \u2714 ${acceptedFixes.length} fixes applied`));
|
|
1518
|
+
}
|
|
1519
|
+
if (skippedFixes.length > 0) {
|
|
1520
|
+
console.log(import_chalk.default.yellow(` \u2298 ${skippedFixes.length} fixes skipped (saved to .cencori-fixes.json)`));
|
|
1521
|
+
}
|
|
1522
|
+
if (acceptedFixes.length > 0) {
|
|
1523
|
+
console.log();
|
|
1524
|
+
console.log(import_chalk.default.cyan(` Run ${import_chalk.default.bold("npx @cencori/scan")} again to verify your fixes!`));
|
|
1486
1525
|
}
|
|
1487
1526
|
console.log();
|
|
1488
1527
|
} catch (error) {
|