javascript-no-extra-bind-cleanup
Remove redundant inline .bind(...) calls from arrow functions and function expressions when the bind wrapper has no semantic effect.
What It Rewrites
The codemod targets inline function-like expressions:
(() => doWork()).bind(obj)(function () { return 1; }).bind(ctx)- Inline safe cases nested in arguments, returns, conditionals, and JSX/TSX expressions
It removes .bind(...) only when the callee is syntactically an inline arrow function or function expression and there is no partial application.
Safety Rules
The codemod skips cases that can change behavior or observable metadata:
- Function expressions that reference dynamic
this - Function expressions that reference
arguments - Any
.bind(...)call with more than one argument - Bound results used with
new - Bound results immediately accessed via
.name,.length, or.prototype - Bound results immediately accessed via computed metadata reads such as
["name"] - Optional chaining bind calls such as
fn?.bind(obj) - Dynamic property access such as
fn["bind"](obj) - Non-inline callees such as
const g = f.bind(obj) - Function expressions with a TypeScript
thisparameter
File Types
The workflow runs over:
**/*.{js,jsx,mjs,cjs}**/*.{ts,tsx,mts,cts}
Examples
Before:
js
After:
js
Before:
tsx
After:
tsx
Development
bash
The test suite includes JavaScript and TSX fixtures covering safe removals, preserved reflective cases, and TypeScript-specific guardrails.
License
MIT