Skip to content

Commit 74c5644

Browse files
Merge pull request #99 from CodeDeficient/claude/project-thread-5iipm8
Rewrite README and description from scratch
2 parents ea94def + 775930e commit 74c5644

3 files changed

Lines changed: 81 additions & 112 deletions

File tree

‎README.md‎

Lines changed: 78 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,123 +2,117 @@
22

33
[![npm version](https://img.shields.io/npm/v/karpeslop.svg)](https://www.npmjs.com/package/karpeslop)
44
[![npm downloads](https://img.shields.io/npm/dt/karpeslop.svg)](https://www.npmjs.com/package/karpeslop)
5-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
66

7-
KarpeSlop finds the mistakes that slip into TypeScript and JavaScript when generated code isn't carefully reviewed: imports of things that don't exist, packages that don't exist, placeholder bodies, code elided with `// ... rest of code`, swallowed errors, unchecked `fetch` responses, and type-system escape hatches (`any`, casts, `!`, `@ts-ignore`).
8-
9-
It can't tell who wrote a line, and it doesn't try. Every rule is a check on the code itself, and every finding says what was found and why it matters. A fix is only suggested when it is certain.
7+
A linter for the mistakes AI coding tools tend to leave in TypeScript and JavaScript.
108

119
```bash
1210
npx karpeslop@latest
1311
```
1412

15-
## How it works
16-
17-
- **Syntax rules run on the TypeScript AST**, not on lines of text. Strings, comments, JSX text and code split across lines are all seen the way the compiler sees them.
18-
- **Import checks use real module resolution.** KarpeSlop builds a TypeScript program with your `tsconfig.json`/`jsconfig.json` and checks each named import against the module's actual exports. Bare package imports are checked against every `package.json` up the tree and `node_modules`; names that are neither declared nor installed are looked up on the npm registry.
19-
- **Run it after `npm install`** for the full import check. Without installed types it falls back to a list of well-known mix-ups (e.g. `useRouter` from `react`).
20-
21-
## Rules
22-
23-
| Rule | Severity | What it finds |
24-
| --- | --- | --- |
25-
| `hallucinated_import` | critical | A named import the module doesn't export (`import { useRouter } from 'react'`), including multi-line and aliased imports, a default import from an ES module with no default export, a subpath an installed package does not have (`lodash-es/debounceAsync`), and a relative or tsconfig-alias import of a file that does not exist (`../lib/validation`, `@/lib/formatting`). Paths into build output or generated code (`dist/`, `generated/`, dot-folders, SvelteKit `$types`) are not checked |
26-
| `nonexistent_package` | critical | An imported package that isn't on the npm registry |
27-
| `undeclared_dependency` | high | An imported package that isn't in any `package.json` and isn't installed. Not reported in `examples/`, whose readers install what each example needs |
28-
| `placeholder_implementation` | high | A body that returns a constant (or nothing) under a TODO or placeholder comment; a short body under a comment that says the real code is elsewhere ("Simulate API call", "In a real app you would..."); a body that only logs and returns success; or `throw new Error("Not implemented")` |
29-
| `elided_code_comment` | high | `// ... rest of the code`, `// ...existing code...`, `{/* ... other fields */}`, `// Add more cases as needed` and similar, in line, block and JSX comments |
30-
| `placeholder_value` | high | `"YOUR_API_KEY"`, `"<your-token>"`, `"Bearer <API_KEY>"`, `"sk-xxxxxx"`, `"sk_test_your_key_here"`, `"postgres://postgres:password@..."`, `"https://your-project.supabase.co"`, `"xxxx"` stored as a key or token, an `example.com` URL stored in config, and a hard-coded fallback for a secret (`process.env.JWT_SECRET \|\| "secret"`) |
31-
| `empty_catch` | high | `catch {}` or `.catch(() => {})` with no comment explaining why, no `_`-named binding and no `void` in front. Not reported when the `try` returns and code after it is the fallback (`try { return parse(x) } catch {}` then a default), or when the `try` only assigns variables declared before it that are read after it (`let found = fallback; try { found = probe() } catch {}`) |
32-
| `swallowed_error` | medium | A `catch` block that only logs (`console.error('Failed', err)`) and lets execution continue as if nothing failed, or logs and then returns `[]`, `{}` or `''`, which the caller cannot tell apart from an empty success |
33-
| `unsafe_type_assertion` | high | `as any` |
34-
| `unsafe_double_type_assertion` | high | `as unknown as T` and other chained casts |
35-
| `unsafe_object_assertion` / `unsafe_array_assertion` | high | Casts to `Record<...>`, `{ ... }`, `T[]`. A cast of `[]`, `{}` or `Object.keys(...)` (and `Object.getOwnPropertyNames`) only narrows a known shape and is reported as `type_assertion` |
36-
| `type_assertion` | medium | Any other cast (`as T`, `<T>x`). `as const` and `as unknown` are not casts |
37-
| `any_type_usage` | medium | Declared `any`, once per line. Not reported in generic constraints, conditional `extends`, fully erased generics like `Query<any, any, any>`, or the "any function" type `(...args: any[]) => any`, which `unknown` cannot express |
38-
| `ts_suppression` | medium | `@ts-ignore`, `@ts-nocheck` |
39-
| `blanket_eslint_disable` | medium | `eslint-disable` without a rule name |
40-
| `unchecked_fetch_response` | medium | `res.json()` with no `res.ok`/`res.status` check (`fetch` only rejects on network errors) |
41-
| `non_null_assertion` | low | `value!` |
42-
| `hedging_comment` | low | "should work", "hopefully", "not sure if" |
43-
| `restating_comment` | low | `// Set loading to true` above `setLoading(true)` |
44-
| `filler_comment` | low | `@param id - the id`, `@returns the result`, "This function is used to..." |
45-
| `todo_comment` | low | TODO / FIXME / HACK that does not link a tracking issue (a URL, `#123` or `PROJ-123`) |
46-
| `production_console_log` | low | `console.log/debug/info` outside tests and CLI scripts |
47-
| `fresh_package_version` | medium | A dependency version published within `minPackageAgeDays` (default 7). New releases are where typosquats and compromised versions usually land |
48-
49-
The cast rules (`unsafe_*_assertion`, `type_assertion`), `any_type_usage` and `non_null_assertion` only run on TypeScript files. They are skipped for `.js`, `.jsx`, `.mjs` and `.cjs`, which have no `as` casts, type annotations or `!`. JSDoc types such as `/** @type {any} */` are not checked.
50-
51-
Rules marked for application code skip test, benchmark and example code (`__tests__/`, `*.test.*`, `*.spec.*`, `test/`, `tests/`, fixtures, `bench/`, `benchmarks/`, `examples/`, `runtime-tests/`, `perf-measures/`). Imports in `__fixtures__/` and `__testfixtures__/` are not checked, because those folders hold sample input rather than code that runs.
13+
> KarpeSlop is a work in progress. Rules change between releases, and some findings will be wrong. If you hit one, please [open an issue](https://github.com/CodeDeficient/KarpeSlop/issues).
14+
15+
## Why
16+
17+
AI tools write code fast, and some of it looks finished when it isn't. Common examples:
18+
19+
- importing a function the library never had
20+
- importing a package that isn't on npm
21+
- a function body that is just a TODO and `return true`
22+
- `// ... rest of the code` where real code should be
23+
- `catch {}` that hides an error
24+
- reading `res.json()` without checking `res.ok`
25+
- `as any` and other casts that switch off type checking
26+
27+
ESLint and `tsc` catch some of this. KarpeSlop looks for the rest, so you can find it before it ships.
5228

5329
## Usage
5430

31+
Run it from your project root, after `npm install` so it can check imports against the packages you actually have.
32+
5533
```bash
56-
npx karpeslop@latest # scan the current directory
57-
npx karpeslop@latest src/ lib/api.ts # scan specific paths
58-
npx karpeslop@latest --quiet # only app/, components/, lib/, hooks/, services/, src/ (at any depth); skip tests
59-
npx karpeslop@latest --strict # exit 2 on critical findings
60-
npx karpeslop@latest --fail-on=medium # also fail on medium findings (casts, any, unchecked fetch)
61-
npx karpeslop@latest -- -dash-file.ts # paths that start with "-"
62-
npx karpeslop@latest --help # list every rule
34+
npx karpeslop@latest # scan the current directory
35+
npx karpeslop@latest src/ lib/api.ts # scan specific files or folders
36+
npx karpeslop@latest --help # list every option and rule
6337
```
6438

65-
A JSON report is written to `./ai-slop-report.json`. `--report=<path>` writes it elsewhere, and `--no-report` skips it.
39+
| Option | What it does |
40+
| --- | --- |
41+
| `--quiet`, `-q` | Only scan `app/`, `components/`, `lib/`, `hooks/`, `services/` and `src/`, and skip tests |
42+
| `--strict`, `-s` | Exit with code 2 when there are critical findings |
43+
| `--fail-on=<severity>` | Lowest severity that fails the run: `critical`, `high` (default), `medium` or `low` |
44+
| `--report=<path>` | Write the JSON report somewhere other than `./ai-slop-report.json` |
45+
| `--no-report` | Don't write the JSON report |
46+
| `--version`, `-v` | Print the version |
47+
| `--` | Treat everything after it as a path, even if it starts with `-` |
48+
49+
Set `KARPESLOP_OFFLINE=1` to skip the npm registry lookups.
6650

6751
### Exit codes
6852

69-
- `0`: nothing at high severity or above. Package-age warnings never fail a run.
70-
- `1`: findings at high severity or above. `--fail-on=medium` (or `low`, `critical`) moves the threshold. Medium findings such as a single cast or an `any` are worth a look in review, but most healthy codebases have some, so they do not fail a run by default.
71-
- `2`: critical findings, with `--strict`.
53+
| Code | Meaning |
54+
| --- | --- |
55+
| `0` | No findings at the `--fail-on` severity or above |
56+
| `1` | Findings at the `--fail-on` severity or above |
57+
| `2` | Critical findings, with `--strict` |
58+
59+
### Monorepos
60+
61+
Run it once from the repo root. Every `package.json` in the tree counts when checking imports, and `--quiet` picks up folders like `packages/ui/src/` at any depth.
7262

73-
Set `KARPESLOP_OFFLINE=1` to skip every npm registry request (package age and package existence checks).
63+
### CI
64+
65+
Add a step to your workflow:
66+
67+
```yaml
68+
- name: KarpeSlop
69+
run: npx karpeslop@latest --quiet --strict
70+
```
71+
72+
[`examples/github-workflow.yml`](examples/github-workflow.yml) is a full GitHub Actions workflow that also uploads the report and comments on the pull request. [`examples/pre-commit`](examples/pre-commit) is a git hook that blocks commits with critical findings.
73+
74+
## What it checks
75+
76+
| Severity | Rules |
77+
| --- | --- |
78+
| critical | Imports of names a module doesn't export, files that don't exist, and packages that aren't on npm |
79+
| high | Packages missing from `package.json`, placeholder bodies, elided-code comments, placeholder values like `"YOUR_API_KEY"`, empty `catch` blocks, `as any` and other unsafe casts |
80+
| medium | Errors that are logged and dropped, other casts, `any`, `@ts-ignore`, blanket `eslint-disable`, unchecked `fetch` responses, dependency versions published in the last few days |
81+
| low | `!` assertions, hedging and filler comments, TODOs without an issue link, `console.log` in app code |
82+
83+
`npx karpeslop@latest --help` lists every rule by name. Test, fixture and example folders are skipped by rules meant for app code.
7484

7585
## Configuration
7686

77-
Create `.karpesloprc.json` in your project root:
87+
Add a `.karpesloprc.json` to your project root:
7888

7989
```json
8090
{
8191
"severityOverrides": {
8292
"type_assertion": "low",
8393
"production_console_log": "off"
8494
},
95+
"ignorePaths": ["**/legacy/**"],
96+
"minPackageAgeDays": 7,
97+
"blockOnCritical": true,
8598
"customPatterns": [
8699
{
87100
"id": "banned_import",
88101
"pattern": "from\\s+['\"]lodash['\"]",
89-
"message": "Use lodash-es for tree-shaking",
90-
"severity": "medium",
91-
"fix": "Replace 'lodash' with 'lodash-es'"
102+
"message": "Use lodash-es",
103+
"severity": "medium"
92104
}
93-
],
94-
"minPackageAgeDays": 7,
95-
"ignorePaths": ["**/legacy/**"],
96-
"blockOnCritical": true
105+
]
97106
}
98107
```
99108

100-
An unknown option on the command line stops the run with exit 1, and a `severityOverrides` key that is not a rule id prints a warning, so a typo never silently changes what is checked.
101-
102-
There are no inline suppression comments. A comment that silences the linter is easy for anyone, or any tool, to add next to the problem it hides. Changing a rule's severity, or turning it off, goes through `severityOverrides`, where it shows up in review.
103-
104-
`customPatterns` are plain regexes matched line by line. Each needs an `id` of its own: a built-in rule id or one used by another pattern is rejected.
105-
106-
## Limitations
107-
108-
- Syntax rules don't use type information. `type_assertion` reports every cast, including ones a careful author made on purpose; tune it with `severityOverrides`.
109-
- The named-import check only covers modules with TypeScript declarations. Exports inferred from plain JavaScript are skipped rather than guessed.
110-
- An import that matches a `paths` alias, a Deno import map entry (`deno.json` `imports`), a folder under `baseUrl` or `src`, or a name quoted in a bundler config is treated as an internal alias. It is never sent to the npm registry, so a missing package with the same name as one of these goes unreported.
111-
- Comment rules are heuristics. They are low severity for that reason and never fail a run.
112-
- KarpeSlop complements ESLint and `tsc`; it doesn't replace them. Run all three.
109+
- `severityOverrides` changes a rule's severity, or turns it off with `"off"`.
110+
- `ignorePaths` skips files that match these globs.
111+
- `minPackageAgeDays` sets how new a dependency version has to be before it gets flagged.
112+
- `blockOnCritical` acts like `--strict` on every run.
113+
- `customPatterns` adds your own regex rules, matched one line at a time.
113114

114-
## CI/CD
115-
116-
```yaml
117-
- name: KarpeSlop
118-
run: npx karpeslop@latest --quiet --strict
119-
```
120-
121-
[`examples/github-workflow.yml`](examples/github-workflow.yml) is a complete workflow that also uploads the JSON report and comments on the pull request when the check fails. [`examples/pre-commit`](examples/pre-commit) is a git hook that blocks a commit on critical findings.
115+
There are no inline comments to silence a finding. Changes go in this file so they show up in code review.
122116

123117
## Contributing
124118

@@ -128,29 +122,8 @@ npm run typecheck
128122
npm test
129123
```
130124

131-
### Local git hooks
132-
133-
Run `./scripts/setup-git-hooks.sh` once after cloning. It installs a pre-push hook that refuses pushes to `main` or `master`; open a pull request from a feature branch instead. `--no-verify` skips the hook, so branch protection on the server is what actually keeps `main` safe.
134-
135-
The script never overwrites a hook it did not install, and stops if an unrelated `pre-push` hook exists. To keep yours, rename it to `pre-push.local` in the same hooks folder and run the script again: the KarpeSlop hook checks the refs first, then runs `pre-push.local` with the same arguments and input. Don't call the KarpeSlop hook from your own hook instead: a hook that reads stdin first leaves it no refs to check, and the push goes through.
136-
137-
To update an installed copy, first check that it is an unmodified KarpeSlop hook: a regular file that contains `Managed by KarpeSlop setup-git-hooks.sh.` and matches a committed version of `.githooks/pre-push`. This prints the matching commit:
138-
139-
```bash
140-
hook="$(git rev-parse --git-path hooks)/pre-push"
141-
if [ -f "$hook" ] && [ ! -L "$hook" ] && grep -qF 'Managed by KarpeSlop setup-git-hooks.sh.' "$hook"; then
142-
for c in $(git rev-list HEAD -- .githooks/pre-push); do
143-
git show "$c:.githooks/pre-push" | cmp -s - "$hook" && echo "matches $c"
144-
done
145-
fi
146-
```
147-
148-
If it matches, move it to the trash and run the script again. Hooks installed before the marker existed can't be told apart from your own; leave them unless you are sure they are KarpeSlop's.
125+
Run `./scripts/setup-git-hooks.sh` once after cloning to add a pre-push hook that stops pushes straight to `main`.
149126

150127
## License
151128

152-
MIT
153-
154-
## Support
155-
156-
If KarpeSlop is useful to you, you can sponsor its development on [GitHub Sponsors](https://github.com/sponsors/CodeDeficient).
129+
[MIT](LICENSE)

‎codemeta.json‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"@context": "https://raw.githubusercontent.com/codemeta/codemeta/2.0/codemeta.jsonld",
33
"@type": "SoftwareSourceCode",
44
"name": "KarpeSlop",
5-
"description": "Finds the mistakes that slip into unreviewed AI-assisted TypeScript and JavaScript: imports and packages that do not exist, placeholder code, swallowed errors, unchecked fetch responses, any and type casts. AST-based static analysis.",
5+
"description": "A linter for the mistakes AI coding tools leave in TypeScript and JavaScript: imports that don't exist, missing packages, placeholder code, swallowed errors and unsafe casts.",
66
"version": "2.0.0",
77
"license": "https://spdx.org/licenses/MIT.html",
88
"codeRepository": "https://github.com/CodeDeficient/karpeslop",
@@ -51,9 +51,5 @@
5151
"readme": "https://github.com/CodeDeficient/karpeslop#readme",
5252
"contIntegration": "https://github.com/CodeDeficient/karpeslop/actions",
5353
"developmentStatus": "active",
54-
"isAccessibleForFree": true,
55-
"funder": {
56-
"@type": "Person",
57-
"url": "https://github.com/sponsors/CodeDeficient"
58-
}
54+
"isAccessibleForFree": true
5955
}

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "karpeslop",
33
"version": "2.0.0",
4-
"description": "Finds the mistakes that slip into unreviewed AI-assisted TypeScript and JavaScript: imports and packages that do not exist, placeholder code, swallowed errors, unchecked fetch responses, any and type casts.",
4+
"description": "A linter for the mistakes AI coding tools leave in TypeScript and JavaScript: imports that don't exist, missing packages, placeholder code, swallowed errors and unsafe casts.",
55
"type": "module",
66
"packageManager": "npm@10.9.7",
77
"bin": {

0 commit comments

Comments
 (0)