commit-cop 1.0.1 → 1.1.1
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/README.md +69 -7
- package/dist/brand.d.ts +4 -0
- package/dist/brand.d.ts.map +1 -0
- package/dist/brand.js +4 -0
- package/dist/brand.js.map +1 -0
- package/dist/checks/binaryFileCheck.js +2 -2
- package/dist/checks/binaryFileCheck.js.map +1 -1
- package/dist/checks/consoleLogCheck.d.ts.map +1 -1
- package/dist/checks/consoleLogCheck.js +2 -2
- package/dist/checks/consoleLogCheck.js.map +1 -1
- package/dist/checks/debuggerCheck.d.ts.map +1 -1
- package/dist/checks/debuggerCheck.js +2 -2
- package/dist/checks/debuggerCheck.js.map +1 -1
- package/dist/checks/envFileCheck.d.ts.map +1 -1
- package/dist/checks/envFileCheck.js +2 -2
- package/dist/checks/envFileCheck.js.map +1 -1
- package/dist/checks/focusedTestCheck.js +2 -2
- package/dist/checks/focusedTestCheck.js.map +1 -1
- package/dist/checks/generatedFolderCheck.js +2 -2
- package/dist/checks/generatedFolderCheck.js.map +1 -1
- package/dist/checks/junkFileCheck.d.ts.map +1 -1
- package/dist/checks/junkFileCheck.js +2 -2
- package/dist/checks/junkFileCheck.js.map +1 -1
- package/dist/checks/largeFileCheck.js +2 -2
- package/dist/checks/largeFileCheck.js.map +1 -1
- package/dist/checks/localHostCheck.js +2 -2
- package/dist/checks/localHostCheck.js.map +1 -1
- package/dist/checks/lockfileDriftCheck.d.ts.map +1 -1
- package/dist/checks/lockfileDriftCheck.js +4 -4
- package/dist/checks/lockfileDriftCheck.js.map +1 -1
- package/dist/checks/mergeConflictCheck.d.ts.map +1 -1
- package/dist/checks/mergeConflictCheck.js +2 -2
- package/dist/checks/mergeConflictCheck.js.map +1 -1
- package/dist/checks/secretCheck.js +19 -19
- package/dist/checks/secretCheck.js.map +1 -1
- package/dist/checks/sensitiveFilenameCheck.d.ts.map +1 -1
- package/dist/checks/sensitiveFilenameCheck.js +2 -2
- package/dist/checks/sensitiveFilenameCheck.js.map +1 -1
- package/dist/fix/debugCode.d.ts +3 -0
- package/dist/fix/debugCode.d.ts.map +1 -0
- package/dist/fix/debugCode.js +55 -0
- package/dist/fix/debugCode.js.map +1 -0
- package/dist/fix/focusedTests.d.ts +2 -0
- package/dist/fix/focusedTests.d.ts.map +1 -0
- package/dist/fix/focusedTests.js +22 -0
- package/dist/fix/focusedTests.js.map +1 -0
- package/dist/fix/gitignore.d.ts +2 -0
- package/dist/fix/gitignore.d.ts.map +1 -0
- package/dist/fix/gitignore.js +82 -0
- package/dist/fix/gitignore.js.map +1 -0
- package/dist/fix/junkFiles.d.ts +2 -0
- package/dist/fix/junkFiles.d.ts.map +1 -0
- package/dist/fix/junkFiles.js +14 -0
- package/dist/fix/junkFiles.js.map +1 -0
- package/dist/fix/lockfile.d.ts +2 -0
- package/dist/fix/lockfile.d.ts.map +1 -0
- package/dist/fix/lockfile.js +18 -0
- package/dist/fix/lockfile.js.map +1 -0
- package/dist/fix/matchers.d.ts +9 -0
- package/dist/fix/matchers.d.ts.map +1 -0
- package/dist/fix/matchers.js +118 -0
- package/dist/fix/matchers.js.map +1 -0
- package/dist/fix/runFix.d.ts +3 -0
- package/dist/fix/runFix.d.ts.map +1 -0
- package/dist/fix/runFix.js +82 -0
- package/dist/fix/runFix.js.map +1 -0
- package/dist/fix/unstage.d.ts +2 -0
- package/dist/fix/unstage.d.ts.map +1 -0
- package/dist/fix/unstage.js +22 -0
- package/dist/fix/unstage.js.map +1 -0
- package/dist/fix/utils.d.ts +4 -0
- package/dist/fix/utils.d.ts.map +1 -0
- package/dist/fix/utils.js +39 -0
- package/dist/fix/utils.js.map +1 -0
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +2 -1
- package/dist/git.js.map +1 -1
- package/dist/hook.d.ts +3 -0
- package/dist/hook.d.ts.map +1 -0
- package/dist/hook.js +79 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.js +32 -21
- package/dist/index.js.map +1 -1
- package/dist/reporter.d.ts.map +1 -1
- package/dist/reporter.js +56 -26
- package/dist/reporter.js.map +1 -1
- package/dist/runScan.d.ts +2 -0
- package/dist/runScan.d.ts.map +1 -0
- package/dist/runScan.js +24 -0
- package/dist/runScan.js.map +1 -0
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +4 -1
- package/dist/scanner.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/brand.ts +3 -0
- package/src/checks/binaryFileCheck.ts +3 -3
- package/src/checks/consoleLogCheck.ts +3 -2
- package/src/checks/debuggerCheck.ts +3 -2
- package/src/checks/envFileCheck.ts +3 -2
- package/src/checks/focusedTestCheck.ts +2 -2
- package/src/checks/generatedFolderCheck.ts +2 -2
- package/src/checks/junkFileCheck.ts +3 -2
- package/src/checks/largeFileCheck.ts +2 -2
- package/src/checks/localHostCheck.ts +2 -2
- package/src/checks/lockfileDriftCheck.ts +6 -4
- package/src/checks/mergeConflictCheck.ts +3 -2
- package/src/checks/secretCheck.ts +19 -19
- package/src/checks/sensitiveFilenameCheck.ts +3 -2
- package/src/fix/debugCode.ts +74 -0
- package/src/fix/focusedTests.ts +26 -0
- package/src/fix/gitignore.ts +108 -0
- package/src/fix/junkFiles.ts +16 -0
- package/src/fix/lockfile.ts +23 -0
- package/src/fix/matchers.ts +141 -0
- package/src/fix/runFix.ts +96 -0
- package/src/fix/unstage.ts +25 -0
- package/src/fix/utils.ts +50 -0
- package/src/git.ts +2 -1
- package/src/hook.ts +98 -0
- package/src/index.ts +45 -27
- package/src/reporter.ts +70 -30
- package/src/runScan.ts +35 -0
- package/src/scanner.ts +4 -1
- package/src/types.ts +5 -0
- package/test.ts +5 -1
- package/testing.ts +3 -0
package/src/reporter.ts
CHANGED
|
@@ -1,48 +1,88 @@
|
|
|
1
|
+
import { PRODUCT_NAME } from "./brand.js";
|
|
1
2
|
import chalk from "chalk";
|
|
2
|
-
import type { Finding } from "./types.js";
|
|
3
|
+
import type { Finding, Severity } from "./types.js";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const WIDTH = 52;
|
|
6
|
+
|
|
7
|
+
function line(char = "─"): string {
|
|
8
|
+
return chalk.dim(char.repeat(WIDTH));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function printHeader(title: string): void {
|
|
12
|
+
console.log("");
|
|
13
|
+
console.log(line("═"));
|
|
14
|
+
console.log(chalk.bold(` ${title}`));
|
|
15
|
+
console.log(line("═"));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function printSection(title: string, color: (text: string) => string): void {
|
|
19
|
+
console.log("");
|
|
20
|
+
console.log(line());
|
|
21
|
+
console.log(color(chalk.bold(` ${title}`)));
|
|
22
|
+
console.log(line());
|
|
23
|
+
console.log("");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function printSummary(scannedCount: number, errors: number, warnings: number): void {
|
|
27
|
+
console.log("");
|
|
28
|
+
console.log(chalk.dim(` Scanned ${scannedCount} staged file(s)`));
|
|
29
|
+
console.log(
|
|
30
|
+
` ${chalk.red(`Errors: ${errors}`)}${chalk.dim(" │ ")}${chalk.yellow(`Warnings: ${warnings}`)}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function printFinding(finding: Finding, index: number): void {
|
|
35
|
+
const location = finding.line
|
|
36
|
+
? `${finding.file}:${finding.line}`
|
|
37
|
+
: finding.file;
|
|
38
|
+
|
|
39
|
+
const checkLabel = chalk.dim(`[${finding.checkName}]`);
|
|
7
40
|
|
|
8
|
-
|
|
9
|
-
|
|
41
|
+
console.log(chalk.bold(` ${index}.`) + ` ${checkLabel}`);
|
|
42
|
+
console.log(` ${chalk.cyan(location)}`);
|
|
43
|
+
console.log(` ${finding.message}`);
|
|
44
|
+
|
|
45
|
+
if (finding.suggestion) {
|
|
46
|
+
console.log(chalk.gray(` → ${finding.suggestion}`));
|
|
47
|
+
}
|
|
10
48
|
|
|
11
|
-
console.log(chalk.red(`Errors: ${errors.length}`));
|
|
12
|
-
console.log(chalk.yellow(`Warnings: ${warnings.length}`));
|
|
13
49
|
console.log("");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function printFindings(findings: Finding[], severity: Severity): void {
|
|
53
|
+
const filtered = findings.filter((finding) => finding.severity === severity);
|
|
54
|
+
|
|
55
|
+
filtered.forEach((finding, index) => {
|
|
56
|
+
printFinding(finding, index + 1);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function printReport(findings: Finding[], scannedCount: number) {
|
|
61
|
+
const errors = findings.filter((finding) => finding.severity === "error");
|
|
62
|
+
const warnings = findings.filter((finding) => finding.severity === "warning");
|
|
63
|
+
|
|
64
|
+
printHeader(`${PRODUCT_NAME} Report`);
|
|
65
|
+
printSummary(scannedCount, errors.length, warnings.length);
|
|
14
66
|
|
|
15
67
|
if (findings.length === 0) {
|
|
16
|
-
console.log(
|
|
68
|
+
console.log("");
|
|
69
|
+
console.log(chalk.green(" ✅ All clear — no issues found in staged files."));
|
|
70
|
+
console.log("");
|
|
71
|
+
console.log(line("═"));
|
|
72
|
+
console.log("");
|
|
17
73
|
return;
|
|
18
74
|
}
|
|
19
75
|
|
|
20
76
|
if (errors.length > 0) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
printFinding(finding);
|
|
24
|
-
}
|
|
77
|
+
printSection(`ERRORS (${errors.length})`, chalk.red);
|
|
78
|
+
printFindings(findings, "error");
|
|
25
79
|
}
|
|
26
80
|
|
|
27
81
|
if (warnings.length > 0) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
printFinding(finding);
|
|
31
|
-
}
|
|
82
|
+
printSection(`WARNINGS (${warnings.length})`, chalk.yellow);
|
|
83
|
+
printFindings(findings, "warning");
|
|
32
84
|
}
|
|
33
85
|
|
|
86
|
+
console.log(line("═"));
|
|
34
87
|
console.log("");
|
|
35
88
|
}
|
|
36
|
-
|
|
37
|
-
function printFinding(finding: Finding) {
|
|
38
|
-
const location = finding.line
|
|
39
|
-
? `${finding.file}:${finding.line}`
|
|
40
|
-
: finding.file;
|
|
41
|
-
|
|
42
|
-
console.log(`- ${chalk.bold(location)}`);
|
|
43
|
-
console.log(` ${finding.message}`);
|
|
44
|
-
|
|
45
|
-
if (finding.suggestion) {
|
|
46
|
-
console.log(chalk.gray(` Fix: ${finding.suggestion}`));
|
|
47
|
-
}
|
|
48
|
-
}
|
package/src/runScan.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PRODUCT_NAME } from "./brand.js";
|
|
2
|
+
import { getStagedFiles } from "./git.js";
|
|
3
|
+
import { runChecks } from "./scanner.js";
|
|
4
|
+
import { printReport } from "./reporter.js";
|
|
5
|
+
|
|
6
|
+
export async function runScan(
|
|
7
|
+
strict = false,
|
|
8
|
+
allowConsoleLog = false
|
|
9
|
+
): Promise<number> {
|
|
10
|
+
const stagedFiles = getStagedFiles();
|
|
11
|
+
|
|
12
|
+
if (stagedFiles.length === 0) {
|
|
13
|
+
console.log(`${PRODUCT_NAME}: No staged files found.`);
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const findings = await runChecks({
|
|
18
|
+
stagedFiles,
|
|
19
|
+
strict,
|
|
20
|
+
allowConsoleLog,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
printReport(findings, stagedFiles.length);
|
|
24
|
+
|
|
25
|
+
const hasErrors = findings.some((finding) => finding.severity === "error");
|
|
26
|
+
const hasWarnings = findings.some(
|
|
27
|
+
(finding) => finding.severity === "warning"
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (hasErrors || (strict && hasWarnings)) {
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
package/src/scanner.ts
CHANGED
|
@@ -31,8 +31,11 @@ const checks = [
|
|
|
31
31
|
|
|
32
32
|
export async function runChecks(context: CheckContext): Promise<Finding[]> {
|
|
33
33
|
const allFindings: Finding[] = [];
|
|
34
|
+
const activeChecks = context.allowConsoleLog
|
|
35
|
+
? checks.filter((check) => check !== consoleLogCheck)
|
|
36
|
+
: checks;
|
|
34
37
|
|
|
35
|
-
for (const check of
|
|
38
|
+
for (const check of activeChecks) {
|
|
36
39
|
const findings = await check.run(context);
|
|
37
40
|
allFindings.push(...findings);
|
|
38
41
|
}
|
package/src/types.ts
CHANGED
package/test.ts
CHANGED
package/testing.ts
ADDED