slop-police 0.3.3 → 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 +4 -12
- package/lib/testing.js +6 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -34,16 +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-code": "error",
|
|
44
|
-
"no-duplicate-function": "warn",
|
|
45
|
-
"no-placeholder-comment": "error",
|
|
46
|
-
"no-stringified-unknown-error": "warn"
|
|
38
|
+
"no-single-string-cn": "off"
|
|
47
39
|
}
|
|
48
40
|
}
|
|
49
41
|
```
|
|
@@ -51,7 +43,7 @@ slop-police reads `slop-police.json` from the current directory:
|
|
|
51
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.
|
|
52
44
|
- `ignore`: glob patterns (relative to the config) for files to skip entirely.
|
|
53
45
|
- `testFiles`: glob patterns for tests. Usages inside tests count, but declarations inside tests are not reported.
|
|
54
|
-
- `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.
|
|
55
47
|
- `plugins`: modules with [custom rules](#custom-rules), as paths relative to the config or package names.
|
|
56
48
|
|
|
57
49
|
Exit code is `1` when there are errors, `2` for an invalid config, `0` otherwise.
|
|
@@ -155,7 +147,7 @@ function parse(input: string) {
|
|
|
155
147
|
|
|
156
148
|
### no-duplicate-code
|
|
157
149
|
|
|
158
|
-
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
|
|
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`).
|
|
159
151
|
|
|
160
152
|
```ts
|
|
161
153
|
// update-card.ts and delete-card.ts both check the card the same way:
|
|
@@ -201,7 +193,7 @@ try {
|
|
|
201
193
|
|
|
202
194
|
## Custom rules
|
|
203
195
|
|
|
204
|
-
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`:
|
|
205
197
|
|
|
206
198
|
```json
|
|
207
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
|
}
|