commit-cop 1.1.1 → 1.1.2
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 +72 -15
- package/dist/hook.d.ts.map +1 -1
- package/dist/hook.js +8 -0
- package/dist/hook.js.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/reporter.d.ts +1 -1
- package/dist/reporter.d.ts.map +1 -1
- package/dist/reporter.js +49 -21
- package/dist/reporter.js.map +1 -1
- package/dist/runScan.d.ts.map +1 -1
- package/dist/runScan.js +1 -7
- package/dist/runScan.js.map +1 -1
- package/package.json +7 -2
- package/src/brand.ts +0 -3
- package/src/checks/binaryFileCheck.ts +0 -64
- package/src/checks/consoleLogCheck.ts +0 -40
- package/src/checks/debuggerCheck.ts +0 -33
- package/src/checks/envFileCheck.ts +0 -26
- package/src/checks/focusedTestCheck.ts +0 -41
- package/src/checks/generatedFolderCheck.ts +0 -45
- package/src/checks/junkFileCheck.ts +0 -40
- package/src/checks/largeFileCheck.ts +0 -31
- package/src/checks/localHostCheck.ts +0 -40
- package/src/checks/lockfileDriftCheck.ts +0 -40
- package/src/checks/mergeConflictCheck.ts +0 -41
- package/src/checks/secretCheck.ts +0 -60
- package/src/checks/sensitiveFilenameCheck.ts +0 -51
- package/src/checks/utils.ts +0 -62
- package/src/fix/debugCode.ts +0 -74
- package/src/fix/focusedTests.ts +0 -26
- package/src/fix/gitignore.ts +0 -108
- package/src/fix/junkFiles.ts +0 -16
- package/src/fix/lockfile.ts +0 -23
- package/src/fix/matchers.ts +0 -141
- package/src/fix/runFix.ts +0 -96
- package/src/fix/unstage.ts +0 -25
- package/src/fix/utils.ts +0 -50
- package/src/git.ts +0 -17
- package/src/hook.ts +0 -98
- package/src/index.ts +0 -59
- package/src/reporter.ts +0 -88
- package/src/runScan.ts +0 -35
- package/src/scanner.ts +0 -44
- package/src/types.ts +0 -25
- package/test.ts +0 -6
- package/testing.ts +0 -3
- package/tsconfig.json +0 -44
package/README.md
CHANGED
|
@@ -8,10 +8,14 @@ Built for students, hackathons, and dev teams who want practical guardrails—no
|
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
|
+
In your project:
|
|
12
|
+
|
|
11
13
|
```bash
|
|
12
14
|
npm install commit-cop
|
|
13
15
|
```
|
|
14
16
|
|
|
17
|
+
This downloads the package into `node_modules`. It does **not** enable the Git hook by itself.
|
|
18
|
+
|
|
15
19
|
### Run automatically on every commit (recommended)
|
|
16
20
|
|
|
17
21
|
From your Git repo:
|
|
@@ -20,9 +24,9 @@ From your Git repo:
|
|
|
20
24
|
npx commit-cop install
|
|
21
25
|
```
|
|
22
26
|
|
|
23
|
-
This
|
|
27
|
+
This writes a **pre-commit** hook. After that, Commit Cop runs **before** each `git commit` completes and scans staged files. If it exits with an error, the commit is blocked.
|
|
24
28
|
|
|
25
|
-
Treat warnings as
|
|
29
|
+
Treat warnings as blocking issues in the hook:
|
|
26
30
|
|
|
27
31
|
```bash
|
|
28
32
|
npx commit-cop install --strict
|
|
@@ -34,6 +38,12 @@ Remove the hook:
|
|
|
34
38
|
npx commit-cop uninstall
|
|
35
39
|
```
|
|
36
40
|
|
|
41
|
+
Skip the hook once:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
git commit --no-verify
|
|
45
|
+
```
|
|
46
|
+
|
|
37
47
|
### Run manually
|
|
38
48
|
|
|
39
49
|
Scan staged changes once:
|
|
@@ -42,21 +52,33 @@ Scan staged changes once:
|
|
|
42
52
|
npx commit-cop
|
|
43
53
|
```
|
|
44
54
|
|
|
45
|
-
Treat warnings as
|
|
55
|
+
Treat warnings as blocking:
|
|
46
56
|
|
|
47
57
|
```bash
|
|
48
58
|
npx commit-cop --strict
|
|
49
59
|
```
|
|
50
60
|
|
|
51
|
-
|
|
61
|
+
## Strict mode and commit behavior
|
|
52
62
|
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
Every scan prints:
|
|
64
|
+
|
|
65
|
+
```txt
|
|
66
|
+
Strict Mode: ON | OFF
|
|
67
|
+
Errors: N
|
|
68
|
+
Warnings: N
|
|
55
69
|
```
|
|
56
70
|
|
|
71
|
+
| Situation | Strict OFF | Strict ON |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| Errors found | Commit blocked | Commit blocked |
|
|
74
|
+
| Warnings only | Commit allowed | Commit blocked |
|
|
75
|
+
| Clean scan | Commit allowed | Commit allowed |
|
|
76
|
+
|
|
77
|
+
Errors always block. Warnings only block when `--strict` is used (via the CLI or `install --strict`).
|
|
78
|
+
|
|
57
79
|
## Auto-fix (work in progress)
|
|
58
80
|
|
|
59
|
-
`wip-fix`
|
|
81
|
+
`wip-fix` applies common repo fixes. More fixes may be added over time.
|
|
60
82
|
|
|
61
83
|
```bash
|
|
62
84
|
npx commit-cop wip-fix
|
|
@@ -99,32 +121,58 @@ Review all changes before committing. `wip-fix` may run `npm install` and unstag
|
|
|
99
121
|
| Large files | Warning | Staged files over 5 MB |
|
|
100
122
|
| Binary files | Warning | `.zip`, `.exe`, `.mp4`, and other non-text files |
|
|
101
123
|
|
|
102
|
-
Errors block the commit. Warnings are reported but do not block unless you use `--strict`.
|
|
103
|
-
|
|
104
124
|
## Local development
|
|
105
125
|
|
|
126
|
+
Clone this repo and install dependencies:
|
|
127
|
+
|
|
106
128
|
```bash
|
|
107
129
|
npm install
|
|
108
|
-
npm run commit-cop
|
|
109
|
-
npm run commit-cop -- wip-fix
|
|
110
130
|
```
|
|
111
131
|
|
|
132
|
+
Run from source (no build required):
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npm run dev
|
|
136
|
+
npm run dev -- --strict
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Install the pre-commit hook for this repo:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npx tsx src/index.ts install
|
|
143
|
+
npx tsx src/index.ts install --strict
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
When developing Commit Cop itself, the hook runs `npm run dev` so you always test local source—not a nested npm copy. Do **not** add `commit-cop` as a dependency of this repo.
|
|
147
|
+
|
|
112
148
|
Build and run the compiled CLI:
|
|
113
149
|
|
|
114
150
|
```bash
|
|
115
151
|
npm run build
|
|
116
152
|
npm start
|
|
153
|
+
npm start -- --strict
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Demo fixtures for manual testing:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm run demo:setup
|
|
160
|
+
git add testing.ts demo/
|
|
161
|
+
npm run dev
|
|
117
162
|
```
|
|
118
163
|
|
|
119
164
|
## Project structure
|
|
120
165
|
|
|
121
166
|
```
|
|
122
167
|
src/
|
|
123
|
-
index.ts CLI entry point (scan
|
|
168
|
+
index.ts CLI entry point (scan, install, wip-fix)
|
|
169
|
+
hook.ts Writes the Git pre-commit hook
|
|
124
170
|
git.ts Reads staged files from Git
|
|
125
171
|
scanner.ts Runs all checks
|
|
126
|
-
reporter.ts Prints the report
|
|
172
|
+
reporter.ts Prints the report and exit outcome
|
|
173
|
+
runScan.ts Orchestrates a scan
|
|
127
174
|
types.ts Shared types
|
|
175
|
+
brand.ts Product name and CLI name
|
|
128
176
|
checks/ One file per check
|
|
129
177
|
fix/ Auto-fix helpers used by wip-fix
|
|
130
178
|
```
|
|
@@ -136,5 +184,14 @@ Each check implements the same interface: receive staged files, return findings
|
|
|
136
184
|
1. Install the hook with `npx commit-cop install` (or run manually)
|
|
137
185
|
2. Read staged file paths with `git diff --cached --name-only`
|
|
138
186
|
3. Run every check in `src/checks/`
|
|
139
|
-
4. Print
|
|
140
|
-
5. Exit with code `1`
|
|
187
|
+
4. Print findings, strict mode status, and error/warning counts
|
|
188
|
+
5. Exit with code `1` to block the commit (errors, or warnings in strict mode)
|
|
189
|
+
|
|
190
|
+
## Publish to npm
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
npm run build
|
|
194
|
+
npm publish
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
`prepublishOnly` runs `build` automatically. The `files` field ensures `dist/` is included in the published package even though it is gitignored locally.
|
package/dist/hook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AA8CA,wBAAgB,WAAW,CAAC,MAAM,UAAQ,GAAG,IAAI,CA6BhD;AAED,wBAAgB,aAAa,IAAI,IAAI,CA4BpC"}
|
package/dist/hook.js
CHANGED
|
@@ -23,6 +23,11 @@ ${HOOK_MARKER}
|
|
|
23
23
|
|
|
24
24
|
cd "$(git rev-parse --show-toplevel)" || exit 1
|
|
25
25
|
|
|
26
|
+
# Local development: run from source when working on Commit Cop itself
|
|
27
|
+
if [ -f package.json ] && [ -f src/index.ts ] && command -v npm >/dev/null 2>&1; then
|
|
28
|
+
exec npm run dev --${strictFlag}
|
|
29
|
+
fi
|
|
30
|
+
|
|
26
31
|
if [ -x "./node_modules/.bin/${CLI_NAME}" ]; then
|
|
27
32
|
exec ./node_modules/.bin/${CLI_NAME}${strictFlag}
|
|
28
33
|
fi
|
|
@@ -54,6 +59,9 @@ export function installHook(strict = false) {
|
|
|
54
59
|
console.log(` ${hookPath}`);
|
|
55
60
|
console.log("");
|
|
56
61
|
console.log("Commit Cop will now run automatically on git commit.");
|
|
62
|
+
if (strict) {
|
|
63
|
+
console.log("Strict mode is enabled for this hook.");
|
|
64
|
+
}
|
|
57
65
|
}
|
|
58
66
|
export function uninstallHook() {
|
|
59
67
|
const hooksDir = getGitHooksDir();
|
package/dist/hook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CA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AC"}
|
package/dist/reporter.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Finding } from "./types.js";
|
|
2
|
-
export declare function printReport(findings: Finding[], scannedCount: number):
|
|
2
|
+
export declare function printReport(findings: Finding[], scannedCount: number, strict: boolean): number;
|
|
3
3
|
//# sourceMappingURL=reporter.d.ts.map
|
package/dist/reporter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AA4G1C,wBAAgB,WAAW,CACzB,QAAQ,EAAE,OAAO,EAAE,EACnB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,OAAO,GACd,MAAM,CA2BR"}
|
package/dist/reporter.js
CHANGED
|
@@ -17,11 +17,6 @@ function printSection(title, color) {
|
|
|
17
17
|
console.log(line());
|
|
18
18
|
console.log("");
|
|
19
19
|
}
|
|
20
|
-
function printSummary(scannedCount, errors, warnings) {
|
|
21
|
-
console.log("");
|
|
22
|
-
console.log(chalk.dim(` Scanned ${scannedCount} staged file(s)`));
|
|
23
|
-
console.log(` ${chalk.red(`Errors: ${errors}`)}${chalk.dim(" │ ")}${chalk.yellow(`Warnings: ${warnings}`)}`);
|
|
24
|
-
}
|
|
25
20
|
function printFinding(finding, index) {
|
|
26
21
|
const location = finding.line
|
|
27
22
|
? `${finding.file}:${finding.line}`
|
|
@@ -41,28 +36,61 @@ function printFindings(findings, severity) {
|
|
|
41
36
|
printFinding(finding, index + 1);
|
|
42
37
|
});
|
|
43
38
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
function printSummary(strict, errorCount, warningCount) {
|
|
40
|
+
console.log("");
|
|
41
|
+
console.log(`Strict Mode: ${strict ? "ON" : "OFF"}`);
|
|
42
|
+
console.log(` ${chalk.red(`Errors: ${errorCount}`)}${chalk.dim(" │ ")}${chalk.yellow(`Warnings: ${warningCount}`)}`);
|
|
43
|
+
console.log("");
|
|
44
|
+
}
|
|
45
|
+
function colorErrors(text) {
|
|
46
|
+
return text.replace(/\berrors\b/gi, (match) => chalk.red(match));
|
|
47
|
+
}
|
|
48
|
+
function colorWarnings(text) {
|
|
49
|
+
return text.replace(/\bwarnings\b/gi, (match) => chalk.yellow(match));
|
|
50
|
+
}
|
|
51
|
+
function colorOutcomeMessage(text) {
|
|
52
|
+
return colorErrors(colorWarnings(text));
|
|
53
|
+
}
|
|
54
|
+
function resolveOutcome(strict, errorCount, warningCount) {
|
|
55
|
+
if (errorCount > 0) {
|
|
56
|
+
console.error(colorOutcomeMessage(`${PRODUCT_NAME} found errors.`));
|
|
57
|
+
console.error(colorOutcomeMessage("Please fix the errors before committing successfully."));
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
if (strict && warningCount > 0) {
|
|
61
|
+
console.error(colorOutcomeMessage(`${PRODUCT_NAME} found warnings.`));
|
|
62
|
+
console.error(colorOutcomeMessage("Please fix the warnings before committing successfully."));
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
if (!strict && warningCount > 0) {
|
|
66
|
+
console.warn(colorOutcomeMessage(`${PRODUCT_NAME} found warnings, but no errors.`));
|
|
67
|
+
console.warn(`Your commit was ${chalk.green("successful")}.`);
|
|
68
|
+
console.warn(colorOutcomeMessage(`If you still like to clean up these ${chalk.yellow("warnings")}, review these before commiting again.`));
|
|
69
|
+
return 0;
|
|
56
70
|
}
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
console.log(`${PRODUCT_NAME} passed.`);
|
|
72
|
+
console.log(colorOutcomeMessage("No errors or warnings found."));
|
|
73
|
+
console.log(`Your commit was ${chalk.green("successful")}.`);
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
export function printReport(findings, scannedCount, strict) {
|
|
77
|
+
const errorCount = findings.filter((finding) => finding.severity === "error").length;
|
|
78
|
+
const warningCount = findings.filter((finding) => finding.severity === "warning").length;
|
|
79
|
+
printHeader(`${PRODUCT_NAME} Report`);
|
|
80
|
+
console.log("");
|
|
81
|
+
console.log(chalk.dim(` Scanned ${scannedCount} staged file(s)`));
|
|
82
|
+
printSummary(strict, errorCount, warningCount);
|
|
83
|
+
if (errorCount > 0) {
|
|
84
|
+
printSection(`ERRORS (${errorCount})`, chalk.red);
|
|
59
85
|
printFindings(findings, "error");
|
|
60
86
|
}
|
|
61
|
-
if (
|
|
62
|
-
printSection(`WARNINGS (${
|
|
87
|
+
if (warningCount > 0) {
|
|
88
|
+
printSection(`WARNINGS (${warningCount})`, chalk.yellow);
|
|
63
89
|
printFindings(findings, "warning");
|
|
64
90
|
}
|
|
91
|
+
const exitCode = resolveOutcome(strict, errorCount, warningCount);
|
|
65
92
|
console.log(line("═"));
|
|
66
93
|
console.log("");
|
|
94
|
+
return exitCode;
|
|
67
95
|
}
|
|
68
96
|
//# sourceMappingURL=reporter.js.map
|
package/dist/reporter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reporter.js","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,KAAK,GAAG,EAAE,CAAC;AAEjB,SAAS,IAAI,CAAC,IAAI,GAAG,GAAG;IACtB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,WAAW,CAAC,KAA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ot":"","sources":["../src/runScan.ts"],"names":[],"mappings":"AAKA,wBAAsB,OAAO,CAC3B,MAAM,UAAQ,EACd,eAAe,UAAQ,GACtB,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"runScan.d.ts","sourceRoot":"","sources":["../src/runScan.ts"],"names":[],"mappings":"AAKA,wBAAsB,OAAO,CAC3B,MAAM,UAAQ,EACd,eAAe,UAAQ,GACtB,OAAO,CAAC,MAAM,CAAC,CAejB"}
|
package/dist/runScan.js
CHANGED
|
@@ -13,12 +13,6 @@ export async function runScan(strict = false, allowConsoleLog = false) {
|
|
|
13
13
|
strict,
|
|
14
14
|
allowConsoleLog,
|
|
15
15
|
});
|
|
16
|
-
printReport(findings, stagedFiles.length);
|
|
17
|
-
const hasErrors = findings.some((finding) => finding.severity === "error");
|
|
18
|
-
const hasWarnings = findings.some((finding) => finding.severity === "warning");
|
|
19
|
-
if (hasErrors || (strict && hasWarnings)) {
|
|
20
|
-
return 1;
|
|
21
|
-
}
|
|
22
|
-
return 0;
|
|
16
|
+
return printReport(findings, stagedFiles.length, strict);
|
|
23
17
|
}
|
|
24
18
|
//# sourceMappingURL=runScan.js.map
|
package/dist/runScan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runScan.js","sourceRoot":"","sources":["../src/runScan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,MAAM,GAAG,KAAK,EACd,eAAe,GAAG,KAAK;IAEvB,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,0BAA0B,CAAC,CAAC;QACvD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC;QAC/B,WAAW;QACX,MAAM;QACN,eAAe;KAChB,CAAC,CAAC;IAEH,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"runScan.js","sourceRoot":"","sources":["../src/runScan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,MAAM,GAAG,KAAK,EACd,eAAe,GAAG,KAAK;IAEvB,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,0BAA0B,CAAC,CAAC;QACvD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC;QAC/B,WAAW;QACX,MAAM;QACN,eAAe;KAChB,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commit-cop",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Commit Cop — a pre-commit safety checker that scans staged files for risky commits.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"bin": {
|
|
7
10
|
"commit-cop": "./dist/index.js"
|
|
8
11
|
},
|
|
9
12
|
"scripts": {
|
|
10
13
|
"dev": "tsx src/index.ts",
|
|
11
14
|
"build": "tsc",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
12
16
|
"start": "node dist/index.js",
|
|
13
17
|
"commit-cop": "tsx src/index.ts",
|
|
14
18
|
"demo:setup": "node scripts/setup-demo.mjs"
|
|
@@ -37,6 +41,7 @@
|
|
|
37
41
|
},
|
|
38
42
|
"dependencies": {
|
|
39
43
|
"chalk": "^5.6.2",
|
|
40
|
-
"commander": "^14.0.3"
|
|
44
|
+
"commander": "^14.0.3",
|
|
45
|
+
"commit-cop": "^1.0.1"
|
|
41
46
|
}
|
|
42
47
|
}
|
package/src/brand.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import type { Check, Finding } from "../types.js";
|
|
3
|
-
import { getBaseName } from "./utils.js";
|
|
4
|
-
|
|
5
|
-
const binaryExtensions = new Set([
|
|
6
|
-
".zip",
|
|
7
|
-
".exe",
|
|
8
|
-
".dll",
|
|
9
|
-
".mp4",
|
|
10
|
-
".mov",
|
|
11
|
-
".sqlite",
|
|
12
|
-
".db",
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
function hasNullBytes(file: string): boolean {
|
|
16
|
-
const buffer = fs.readFileSync(file);
|
|
17
|
-
const sampleSize = Math.min(buffer.length, 8192);
|
|
18
|
-
|
|
19
|
-
for (let index = 0; index < sampleSize; index += 1) {
|
|
20
|
-
if (buffer[index] === 0) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const binaryFileCheck: Check = {
|
|
29
|
-
name: "binary-file-check",
|
|
30
|
-
|
|
31
|
-
async run(context) {
|
|
32
|
-
const findings: Finding[] = [];
|
|
33
|
-
|
|
34
|
-
for (const file of context.stagedFiles) {
|
|
35
|
-
if (!fs.existsSync(file)) continue;
|
|
36
|
-
|
|
37
|
-
const baseName = getBaseName(file);
|
|
38
|
-
const extension = baseName.includes(".")
|
|
39
|
-
? baseName.slice(baseName.lastIndexOf(".")).toLowerCase()
|
|
40
|
-
: "";
|
|
41
|
-
|
|
42
|
-
let isBinary = binaryExtensions.has(extension);
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
isBinary ||= hasNullBytes(file);
|
|
46
|
-
} catch {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (isBinary) {
|
|
51
|
-
findings.push({
|
|
52
|
-
severity: "warning",
|
|
53
|
-
checkName: this.name,
|
|
54
|
-
file,
|
|
55
|
-
message:
|
|
56
|
-
"Binary file detected — archives, executables, and media don't belong in source control.",
|
|
57
|
-
suggestion: "Remove it from the commit or store it with Git LFS.",
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return findings;
|
|
63
|
-
},
|
|
64
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import type { Check, Finding } from "../types.js";
|
|
3
|
-
|
|
4
|
-
const codeExtensions = [".js", ".jsx", ".ts", ".tsx"];
|
|
5
|
-
|
|
6
|
-
function isCodeFile(file: string): boolean {
|
|
7
|
-
return codeExtensions.some((ext) => file.endsWith(ext));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const consoleLogCheck: Check = {
|
|
11
|
-
name: "console-log-check",
|
|
12
|
-
|
|
13
|
-
async run(context) {
|
|
14
|
-
const findings: Finding[] = [];
|
|
15
|
-
|
|
16
|
-
for (const file of context.stagedFiles) {
|
|
17
|
-
if (!isCodeFile(file)) continue;
|
|
18
|
-
if (!fs.existsSync(file)) continue;
|
|
19
|
-
|
|
20
|
-
const content = fs.readFileSync(file, "utf-8");
|
|
21
|
-
const lines = content.split("\n");
|
|
22
|
-
|
|
23
|
-
lines.forEach((line, index) => {
|
|
24
|
-
if (line.includes("console.log")) {
|
|
25
|
-
findings.push({
|
|
26
|
-
severity: "warning",
|
|
27
|
-
checkName: this.name,
|
|
28
|
-
file,
|
|
29
|
-
line: index + 1,
|
|
30
|
-
message:
|
|
31
|
-
"Debug log left in code — easy to miss and clutters production output.",
|
|
32
|
-
suggestion: "Delete the console.log before committing.",
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return findings;
|
|
39
|
-
},
|
|
40
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Check, Finding } from "../types.js";
|
|
2
|
-
import { isCodeFile, readFileLines } from "./utils.js";
|
|
3
|
-
|
|
4
|
-
export const debuggerCheck: Check = {
|
|
5
|
-
name: "debugger-check",
|
|
6
|
-
|
|
7
|
-
async run(context) {
|
|
8
|
-
const findings: Finding[] = [];
|
|
9
|
-
|
|
10
|
-
for (const file of context.stagedFiles) {
|
|
11
|
-
if (!isCodeFile(file)) continue;
|
|
12
|
-
|
|
13
|
-
const lines = readFileLines(file);
|
|
14
|
-
if (!lines) continue;
|
|
15
|
-
|
|
16
|
-
lines.forEach((line, index) => {
|
|
17
|
-
if (/\bdebugger\b/.test(line)) {
|
|
18
|
-
findings.push({
|
|
19
|
-
severity: "warning",
|
|
20
|
-
checkName: this.name,
|
|
21
|
-
file,
|
|
22
|
-
line: index + 1,
|
|
23
|
-
message:
|
|
24
|
-
"debugger statement left in code — pauses execution and breaks CI/headless runs.",
|
|
25
|
-
suggestion: "Delete the debugger statement before committing.",
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return findings;
|
|
32
|
-
},
|
|
33
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Check, Finding } from "../types.js";
|
|
2
|
-
|
|
3
|
-
export const envFileCheck: Check = {
|
|
4
|
-
name: "env-file-check",
|
|
5
|
-
|
|
6
|
-
async run(context) {
|
|
7
|
-
const findings: Finding[] = [];
|
|
8
|
-
|
|
9
|
-
for (const file of context.stagedFiles) {
|
|
10
|
-
const fileName = file.split("/").pop() ?? "";
|
|
11
|
-
|
|
12
|
-
if (fileName === ".env" || fileName.startsWith(".env.")) {
|
|
13
|
-
findings.push({
|
|
14
|
-
severity: "error",
|
|
15
|
-
checkName: this.name,
|
|
16
|
-
file,
|
|
17
|
-
message:
|
|
18
|
-
".env file detected — these often hold API keys, passwords, and tokens.",
|
|
19
|
-
suggestion: `Unstage it: git restore --staged ${file}`,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return findings;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import type { Check, Finding } from "../types.js";
|
|
3
|
-
|
|
4
|
-
const testPatterns = [
|
|
5
|
-
"test.only",
|
|
6
|
-
"it.only",
|
|
7
|
-
"describe.only",
|
|
8
|
-
];
|
|
9
|
-
|
|
10
|
-
export const focusedTestCheck: Check = {
|
|
11
|
-
name: "focused-test-check",
|
|
12
|
-
|
|
13
|
-
async run(context) {
|
|
14
|
-
const findings: Finding[] = [];
|
|
15
|
-
|
|
16
|
-
for (const file of context.stagedFiles) {
|
|
17
|
-
if (!file.includes("test") && !file.includes("spec")) continue;
|
|
18
|
-
if (!fs.existsSync(file)) continue;
|
|
19
|
-
|
|
20
|
-
const content = fs.readFileSync(file, "utf-8");
|
|
21
|
-
const lines = content.split("\n");
|
|
22
|
-
|
|
23
|
-
lines.forEach((line, index) => {
|
|
24
|
-
for (const pattern of testPatterns) {
|
|
25
|
-
if (line.includes(pattern)) {
|
|
26
|
-
findings.push({
|
|
27
|
-
severity: "error",
|
|
28
|
-
checkName: this.name,
|
|
29
|
-
file,
|
|
30
|
-
line: index + 1,
|
|
31
|
-
message: `${pattern} detected — only that test will run, hiding failures in the rest of the suite.`,
|
|
32
|
-
suggestion: `Change ${pattern} back to ${pattern.replace(".only", "")}.`,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return findings;
|
|
40
|
-
},
|
|
41
|
-
};
|