Skip to content
← All rules
ResourcesResource lifecycle

resources/require-cleanup-on-failure

Cleanup must run when intervening work fails, using managed lifetimes, finally blocks, scoped helpers, or ownership transfer.

cleanupexceptionsfinally
TypeScript
const socket = await connect(); await send(socket); socket.close();
Finding

Require cleanup that is safe on failure.

Setup

Install the package, register its plugin factory, then enable the rule.

Install the package

pnpm add -D @scruple/resources

Register the plugin

In scruple.config.ts, register the factory under the resources namespace used by the rule ID.

import { resources } from "@scruple/resources";

plugins: {
  "resources": resources(),
},

Enable the rule

"resources/require-cleanup-on-failure": "warn"
Package
@scruple/resources
Default threshold
0.9
Minimum confidence
0.7

Released under the MIT License.