slop-police 0.3.2 → 0.3.4
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 +23 -10
- package/lib/testing.js +6 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -34,15 +34,8 @@ slop-police reads `slop-police.json` from the current directory:
|
|
|
34
34
|
"testFiles": ["**/*.test.{ts,tsx}", "**/*.spec.{ts,tsx}"],
|
|
35
35
|
"rules": {
|
|
36
36
|
"unused-methods": ["error", { "includePrivate": true }],
|
|
37
|
-
"unused-object-keys": "error",
|
|
38
37
|
"no-identity-type-alias": "warn",
|
|
39
|
-
"no-
|
|
40
|
-
"no-redundant-value-alias": "error",
|
|
41
|
-
"no-single-string-cn": "off",
|
|
42
|
-
"no-pass-through-wrapper": "error",
|
|
43
|
-
"no-duplicate-function": "warn",
|
|
44
|
-
"no-placeholder-comment": "error",
|
|
45
|
-
"no-stringified-unknown-error": "warn"
|
|
38
|
+
"no-single-string-cn": "off"
|
|
46
39
|
}
|
|
47
40
|
}
|
|
48
41
|
```
|
|
@@ -50,7 +43,7 @@ slop-police reads `slop-police.json` from the current directory:
|
|
|
50
43
|
- `projects`: tsconfig files to analyze. Usages are counted across all of them, so a method used only by another package still counts as used.
|
|
51
44
|
- `ignore`: glob patterns (relative to the config) for files to skip entirely.
|
|
52
45
|
- `testFiles`: glob patterns for tests. Usages inside tests count, but declarations inside tests are not reported.
|
|
53
|
-
- `rules`: `"error"`, `"warn"` or `"off"`, or `[severity, options]`.
|
|
46
|
+
- `rules`: every built-in rule runs as an error with its default options. List a rule here to change that: `"error"`, `"warn"` or `"off"`, or `[severity, options]`. Plugin rules run only when they're listed.
|
|
54
47
|
- `plugins`: modules with [custom rules](#custom-rules), as paths relative to the config or package names.
|
|
55
48
|
|
|
56
49
|
Exit code is `1` when there are errors, `2` for an invalid config, `0` otherwise.
|
|
@@ -152,6 +145,26 @@ function parse(input: string) {
|
|
|
152
145
|
}
|
|
153
146
|
```
|
|
154
147
|
|
|
148
|
+
### no-duplicate-code
|
|
149
|
+
|
|
150
|
+
Copy-pasted code: at least 50 tokens in a row that repeat earlier code (in the same file or one before it by path) and span at least 11 lines. Tokens are compared by their text, types included, so a renamed variable or a different type ends a copy, but comments, formatting and imports are left out. Test files are neither reported nor compared. `// slop-police-ignore no-duplicate-code` above a statement, class member or object property takes it out of the comparison, so it is not reported as a copy or as the original. Options: `minLines` (default `11`, counting every line a copy spans) and `minTokens` (default `50`).
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
// update-card.ts and delete-card.ts both check the card the same way:
|
|
154
|
+
const userId = ctx.userId;
|
|
155
|
+
assert(userId);
|
|
156
|
+
|
|
157
|
+
const cards = await getCardsWithDeck(ctx.db, [input.id]);
|
|
158
|
+
if (cards.length === 0) {
|
|
159
|
+
throw notFound("Card not found");
|
|
160
|
+
}
|
|
161
|
+
const card = cards[0];
|
|
162
|
+
if (card.deckAuthorId !== userId) {
|
|
163
|
+
throw forbidden("You don't own this card");
|
|
164
|
+
}
|
|
165
|
+
// delete-card.ts:6:5 Lines 6-16 duplicate update-card.ts:6-16
|
|
166
|
+
```
|
|
167
|
+
|
|
155
168
|
### no-duplicate-function
|
|
156
169
|
|
|
157
170
|
A function whose body has the same shape as functions in at least two other files: a helper that was rewritten instead of reused. Shapes ignore the names of parameters and locals and the values of literals, but not the names of what the body calls or reads. Bodies with fewer than 2 statements or 16 syntax nodes, and functions in test files, don't count. Option: `minFiles` (default `3`, at least `2`), the number of files a shape has to appear in.
|
|
@@ -180,7 +193,7 @@ try {
|
|
|
180
193
|
|
|
181
194
|
## Custom rules
|
|
182
195
|
|
|
183
|
-
Write rules in TypeScript or JavaScript, list their modules in `plugins` and
|
|
196
|
+
Write rules in TypeScript or JavaScript, list their modules in `plugins` and turn them on in `rules`:
|
|
184
197
|
|
|
185
198
|
```json
|
|
186
199
|
{
|
package/lib/testing.js
CHANGED
|
@@ -17,9 +17,9 @@ const tsconfig = {
|
|
|
17
17
|
include: ["**/*.ts", "**/*.tsx"],
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
// lint runs rule
|
|
21
|
-
//
|
|
22
|
-
//
|
|
20
|
+
// lint runs rule on source (as index.ts) or on files (paths to contents, with
|
|
21
|
+
// a default strict tsconfig.json unless one is given) and returns its
|
|
22
|
+
// findings, leaving out those of the built-in rules.
|
|
23
23
|
export function lint(rule, source, options) {
|
|
24
24
|
const files = typeof source === "string" ? { "index.ts": source } : source;
|
|
25
25
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "slop-police-test-"));
|
|
@@ -31,7 +31,9 @@ export function lint(rule, source, options) {
|
|
|
31
31
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
32
32
|
fs.writeFileSync(file, content);
|
|
33
33
|
}
|
|
34
|
-
return lintWithRules(findBinary(), root, [rule])
|
|
34
|
+
return lintWithRules(findBinary(), root, [rule])
|
|
35
|
+
.results.filter((result) => result.rule === rule.name)
|
|
36
|
+
.map(({ file, line, column, message }) => ({ file, line, column, message }));
|
|
35
37
|
} finally {
|
|
36
38
|
fs.rmSync(root, { recursive: true, force: true });
|
|
37
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slop-police",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Type-aware TypeScript linter for the dead code and needless indirection AI agents leave behind",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"node": ">=22.18"
|
|
42
42
|
},
|
|
43
43
|
"optionalDependencies": {
|
|
44
|
-
"slop-police-darwin-arm64": "0.3.
|
|
45
|
-
"slop-police-darwin-x64": "0.3.
|
|
46
|
-
"slop-police-linux-arm64": "0.3.
|
|
47
|
-
"slop-police-linux-x64": "0.3.
|
|
44
|
+
"slop-police-darwin-arm64": "0.3.4",
|
|
45
|
+
"slop-police-darwin-x64": "0.3.4",
|
|
46
|
+
"slop-police-linux-arm64": "0.3.4",
|
|
47
|
+
"slop-police-linux-x64": "0.3.4"
|
|
48
48
|
}
|
|
49
49
|
}
|