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.
Files changed (128) hide show
  1. package/README.md +69 -7
  2. package/dist/brand.d.ts +4 -0
  3. package/dist/brand.d.ts.map +1 -0
  4. package/dist/brand.js +4 -0
  5. package/dist/brand.js.map +1 -0
  6. package/dist/checks/binaryFileCheck.js +2 -2
  7. package/dist/checks/binaryFileCheck.js.map +1 -1
  8. package/dist/checks/consoleLogCheck.d.ts.map +1 -1
  9. package/dist/checks/consoleLogCheck.js +2 -2
  10. package/dist/checks/consoleLogCheck.js.map +1 -1
  11. package/dist/checks/debuggerCheck.d.ts.map +1 -1
  12. package/dist/checks/debuggerCheck.js +2 -2
  13. package/dist/checks/debuggerCheck.js.map +1 -1
  14. package/dist/checks/envFileCheck.d.ts.map +1 -1
  15. package/dist/checks/envFileCheck.js +2 -2
  16. package/dist/checks/envFileCheck.js.map +1 -1
  17. package/dist/checks/focusedTestCheck.js +2 -2
  18. package/dist/checks/focusedTestCheck.js.map +1 -1
  19. package/dist/checks/generatedFolderCheck.js +2 -2
  20. package/dist/checks/generatedFolderCheck.js.map +1 -1
  21. package/dist/checks/junkFileCheck.d.ts.map +1 -1
  22. package/dist/checks/junkFileCheck.js +2 -2
  23. package/dist/checks/junkFileCheck.js.map +1 -1
  24. package/dist/checks/largeFileCheck.js +2 -2
  25. package/dist/checks/largeFileCheck.js.map +1 -1
  26. package/dist/checks/localHostCheck.js +2 -2
  27. package/dist/checks/localHostCheck.js.map +1 -1
  28. package/dist/checks/lockfileDriftCheck.d.ts.map +1 -1
  29. package/dist/checks/lockfileDriftCheck.js +4 -4
  30. package/dist/checks/lockfileDriftCheck.js.map +1 -1
  31. package/dist/checks/mergeConflictCheck.d.ts.map +1 -1
  32. package/dist/checks/mergeConflictCheck.js +2 -2
  33. package/dist/checks/mergeConflictCheck.js.map +1 -1
  34. package/dist/checks/secretCheck.js +19 -19
  35. package/dist/checks/secretCheck.js.map +1 -1
  36. package/dist/checks/sensitiveFilenameCheck.d.ts.map +1 -1
  37. package/dist/checks/sensitiveFilenameCheck.js +2 -2
  38. package/dist/checks/sensitiveFilenameCheck.js.map +1 -1
  39. package/dist/fix/debugCode.d.ts +3 -0
  40. package/dist/fix/debugCode.d.ts.map +1 -0
  41. package/dist/fix/debugCode.js +55 -0
  42. package/dist/fix/debugCode.js.map +1 -0
  43. package/dist/fix/focusedTests.d.ts +2 -0
  44. package/dist/fix/focusedTests.d.ts.map +1 -0
  45. package/dist/fix/focusedTests.js +22 -0
  46. package/dist/fix/focusedTests.js.map +1 -0
  47. package/dist/fix/gitignore.d.ts +2 -0
  48. package/dist/fix/gitignore.d.ts.map +1 -0
  49. package/dist/fix/gitignore.js +82 -0
  50. package/dist/fix/gitignore.js.map +1 -0
  51. package/dist/fix/junkFiles.d.ts +2 -0
  52. package/dist/fix/junkFiles.d.ts.map +1 -0
  53. package/dist/fix/junkFiles.js +14 -0
  54. package/dist/fix/junkFiles.js.map +1 -0
  55. package/dist/fix/lockfile.d.ts +2 -0
  56. package/dist/fix/lockfile.d.ts.map +1 -0
  57. package/dist/fix/lockfile.js +18 -0
  58. package/dist/fix/lockfile.js.map +1 -0
  59. package/dist/fix/matchers.d.ts +9 -0
  60. package/dist/fix/matchers.d.ts.map +1 -0
  61. package/dist/fix/matchers.js +118 -0
  62. package/dist/fix/matchers.js.map +1 -0
  63. package/dist/fix/runFix.d.ts +3 -0
  64. package/dist/fix/runFix.d.ts.map +1 -0
  65. package/dist/fix/runFix.js +82 -0
  66. package/dist/fix/runFix.js.map +1 -0
  67. package/dist/fix/unstage.d.ts +2 -0
  68. package/dist/fix/unstage.d.ts.map +1 -0
  69. package/dist/fix/unstage.js +22 -0
  70. package/dist/fix/unstage.js.map +1 -0
  71. package/dist/fix/utils.d.ts +4 -0
  72. package/dist/fix/utils.d.ts.map +1 -0
  73. package/dist/fix/utils.js +39 -0
  74. package/dist/fix/utils.js.map +1 -0
  75. package/dist/git.d.ts.map +1 -1
  76. package/dist/git.js +2 -1
  77. package/dist/git.js.map +1 -1
  78. package/dist/hook.d.ts +3 -0
  79. package/dist/hook.d.ts.map +1 -0
  80. package/dist/hook.js +79 -0
  81. package/dist/hook.js.map +1 -0
  82. package/dist/index.js +32 -21
  83. package/dist/index.js.map +1 -1
  84. package/dist/reporter.d.ts.map +1 -1
  85. package/dist/reporter.js +56 -26
  86. package/dist/reporter.js.map +1 -1
  87. package/dist/runScan.d.ts +2 -0
  88. package/dist/runScan.d.ts.map +1 -0
  89. package/dist/runScan.js +24 -0
  90. package/dist/runScan.js.map +1 -0
  91. package/dist/scanner.d.ts.map +1 -1
  92. package/dist/scanner.js +4 -1
  93. package/dist/scanner.js.map +1 -1
  94. package/dist/types.d.ts +4 -0
  95. package/dist/types.d.ts.map +1 -1
  96. package/package.json +4 -3
  97. package/src/brand.ts +3 -0
  98. package/src/checks/binaryFileCheck.ts +3 -3
  99. package/src/checks/consoleLogCheck.ts +3 -2
  100. package/src/checks/debuggerCheck.ts +3 -2
  101. package/src/checks/envFileCheck.ts +3 -2
  102. package/src/checks/focusedTestCheck.ts +2 -2
  103. package/src/checks/generatedFolderCheck.ts +2 -2
  104. package/src/checks/junkFileCheck.ts +3 -2
  105. package/src/checks/largeFileCheck.ts +2 -2
  106. package/src/checks/localHostCheck.ts +2 -2
  107. package/src/checks/lockfileDriftCheck.ts +6 -4
  108. package/src/checks/mergeConflictCheck.ts +3 -2
  109. package/src/checks/secretCheck.ts +19 -19
  110. package/src/checks/sensitiveFilenameCheck.ts +3 -2
  111. package/src/fix/debugCode.ts +74 -0
  112. package/src/fix/focusedTests.ts +26 -0
  113. package/src/fix/gitignore.ts +108 -0
  114. package/src/fix/junkFiles.ts +16 -0
  115. package/src/fix/lockfile.ts +23 -0
  116. package/src/fix/matchers.ts +141 -0
  117. package/src/fix/runFix.ts +96 -0
  118. package/src/fix/unstage.ts +25 -0
  119. package/src/fix/utils.ts +50 -0
  120. package/src/git.ts +2 -1
  121. package/src/hook.ts +98 -0
  122. package/src/index.ts +45 -27
  123. package/src/reporter.ts +70 -30
  124. package/src/runScan.ts +35 -0
  125. package/src/scanner.ts +4 -1
  126. package/src/types.ts +5 -0
  127. package/test.ts +5 -1
  128. 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
- export function printReport(findings: Finding[], scannedCount: number) {
5
- console.log(chalk.bold("\nCommitClean Report\n"));
6
- console.log(`Scanned ${scannedCount} staged file(s).\n`);
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
- const errors = findings.filter((f) => f.severity === "error");
9
- const warnings = findings.filter((f) => f.severity === "warning");
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(chalk.green("✅ No issues found. Commit looks clean.\n"));
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
- console.log(chalk.red.bold("❌ Errors"));
22
- for (const finding of errors) {
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
- console.log(chalk.yellow.bold("\n⚠️ Warnings"));
29
- for (const finding of warnings) {
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 checks) {
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
@@ -12,6 +12,11 @@ export type Finding = {
12
12
  export type CheckContext = {
13
13
  stagedFiles: string[];
14
14
  strict: boolean;
15
+ allowConsoleLog?: boolean;
16
+ };
17
+
18
+ export type WipFixOptions = {
19
+ fixConsoleLog?: boolean;
15
20
  };
16
21
 
17
22
  export type Check = {
package/test.ts CHANGED
@@ -1,2 +1,6 @@
1
+ // Add test cases here, make sure to to
2
+ // git add when you make a change to see CLI in
3
+ // action
1
4
  console.log("Hello, world!");
2
- console.log("Debug log");
5
+ console.log("Debug log");
6
+ console.log("Debug log 2");
package/testing.ts ADDED
@@ -0,0 +1,3 @@
1
+ console.log("testingFinal");
2
+ console.log("testingFinal");
3
+ console.log("testingFinal");