@bitobeats/linger 0.0.0-stage → 0.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 (3) hide show
  1. package/README.md +48 -2
  2. package/bin/linger.js +26 -0
  3. package/package.json +34 -4
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # linger
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Finds likely memory leaks in TypeScript and React code. Instead of matching names
4
+ like `subscribe` without `unsubscribe`, linger reasons about lifetimes: a leak is
5
+ something long-lived (`window`, a module-scope store, the timer table) holding a
6
+ callback from something short-lived (a component, an element, a class instance)
7
+ with no release in the short-lived owner's teardown.
8
+
9
+ ```sh
10
+ npx @bitobeats/linger check # uses ./tsconfig.json
11
+ npx @bitobeats/linger check packages/app --format json
12
+ ```
13
+
14
+ ## Rules
15
+
16
+ | Rule | Finds |
17
+ | --- | --- |
18
+ | `discarded-disposer` | A call that registers something and returns its release (a `() => void` disposer, a subscription with `unsubscribe()`/`dispose()`/`disconnect()`, a `Disposable`) whose result is thrown away or never read. |
19
+ | `unreleased-registration` | A listener, `setInterval`, observer or kept subscription on a longer-lived holder that the owner's teardown never releases. Owners are React effects, class components, custom elements, Angular components and classes with `dispose()`/`destroy()`. |
20
+
21
+ An `AbortSignal` counts as a release: pass `{ signal: controller.signal }` and
22
+ call `controller.abort()` in the teardown. For APIs without signal support,
23
+ `signal.addEventListener("abort", () => unsubscribe())` is recognized too.
24
+
25
+ Every finding has a confidence. Only `likely` findings fail the run; `possible`
26
+ ones are reported for review.
27
+
28
+ ## Suppressing a finding
29
+
30
+ ```ts
31
+ // linger-ignore discarded-disposer: the store lives as long as the page
32
+ store.subscribe(render);
33
+ ```
34
+
35
+ The comment covers the next line, or its own line when it follows code. The rule
36
+ and the reason are both required; a malformed comment is reported as
37
+ `invalid-suppression`.
38
+
39
+ ## Options
40
+
41
+ | Flag | |
42
+ | --- | --- |
43
+ | `-p, --project <file>` | tsconfig to load (default `<dir>/tsconfig.json`) |
44
+ | `--format text\|json\|sarif` | `sarif` is for GitHub Code Scanning |
45
+ | `--include-tests` | also analyze `*.test.*`, `*.spec.*`, `__tests__/`, `__mocks__/` |
46
+
47
+ Exit codes: `0` no `likely` findings, `1` at least one, `2` error.
48
+
49
+ The JSON and SARIF formats are unstable before 1.0 (`schemaVersion: "0"`).
package/bin/linger.js ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // Runs the native binary from the platform package npm installed for this machine.
4
+ const { spawnSync } = require("node:child_process");
5
+
6
+ const pkg = `@bitobeats/linger-${process.platform}-${process.arch}`;
7
+ const exe = process.platform === "win32" ? "linger.exe" : "linger";
8
+
9
+ let bin;
10
+ try {
11
+ bin = require.resolve(`${pkg}/bin/${exe}`);
12
+ } catch {
13
+ console.error(
14
+ `linger: no binary for ${process.platform}-${process.arch}.\n` +
15
+ `Expected the optional dependency ${pkg}. Reinstall without --no-optional / --omit=optional,\n` +
16
+ `or check that your platform is supported (darwin, linux, win32 on x64 and arm64).`,
17
+ );
18
+ process.exit(2);
19
+ }
20
+
21
+ const r = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
22
+ if (r.error) {
23
+ console.error(`linger: ${r.error.message}`);
24
+ process.exit(2);
25
+ }
26
+ process.exit(r.status ?? 1);
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@bitobeats/linger",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Finds likely memory leaks in TypeScript and React code by reasoning about lifetimes.",
5
+ "keywords": [
6
+ "memory-leak",
7
+ "typescript",
8
+ "react",
9
+ "lint",
10
+ "static-analysis"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/bitobeats/linger.git"
15
+ },
16
+ "bin": {
17
+ "linger": "bin/linger.js"
18
+ },
19
+ "files": [
20
+ "bin"
21
+ ],
22
+ "engines": {
23
+ "node": ">=18"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "optionalDependencies": {
29
+ "@bitobeats/linger-darwin-arm64": "0.1.1",
30
+ "@bitobeats/linger-darwin-x64": "0.1.1",
31
+ "@bitobeats/linger-linux-arm64": "0.1.1",
32
+ "@bitobeats/linger-linux-x64": "0.1.1",
33
+ "@bitobeats/linger-win32-arm64": "0.1.1",
34
+ "@bitobeats/linger-win32-x64": "0.1.1"
35
+ }
36
+ }