Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call()

Proprietary

Replaces Object.prototype.hasOwnProperty.call(obj, key), Object.hasOwnProperty.call(obj, key), and ({}).hasOwnProperty.call(obj, key) (empty object literal receiver) with the equivalent ES2022 Object.hasOwn(obj, key), leaving the argument list untouched. No change is made when comments exist inside the callee, when the global Object is shadowed, or inside a with statement. The fixed code requires an ES2022+ runtime (Node.js 16.9+), which requireDeclaredRuntime checks against each project's engines.node. Replicates the autofix of the ESLint rule prefer-object-has-own under its default options.

io.moderne.javascript.cleanup.PreferObjectHasOwn

Optional

Only change JavaScript files whose nearest package.json declares an engines.node range that admits no Node.js release older than 16.9.0, the first with Object.hasOwn. Other files, and TypeScript files, whose tsconfig lib may lack Object.hasOwn, are left unchanged. Default is false.

mod run . --recipe=io.moderne.javascript.cleanup.PreferObjectHasOwn

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.