Registry / testing / eslint-plugin-prefer-object-spread

eslint-plugin-prefer-object-spread

JSON →
library1.2.1jsnpmunverified

ESLint rule that flags Object.assign() calls when the target is an object literal, recommending object spread properties instead. Version 1.2.1 is the latest stable release; the package has not been updated since 2016. It applies only when Object.assign() is used for cloning (first argument is an object literal) to avoid false positives when mutating an existing object. Requires ESLint >=0.8.0 and Node >=4.0.0. This plugin is lightweight and has a single rule. It is not actively maintained and may be superseded by built-in ESLint rules or new JavaScript features.

npm install eslint-plugin-prefer-object-spread
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-PREF
E
eslint-plugin-prefer-object-spread
testingjavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prefer-object-spread (plugin)
import { rules } from 'eslint-plugin-prefer-object-spread';
const plugin = require('eslint-plugin-prefer-object-spread');
In ESLint, plugins are typically referenced by name in config, not imported directly. When importing for testing, named exports may not exist; prefer require.
prefer-object-spread rule
"prefer-object-spread/prefer-object-spread": "error"
"prefer-object-spread": "error"
Rule must be prefixed with the plugin name in ESLint config.
Plugin registration in ESLint config
{ "plugins": ["prefer-object-spread"], "rules": { "prefer-object-spread/prefer-object-spread": "error" } }
{ "plugins": ["prefer-object-spread"], "rules": { "prefer-object-spread": "error" } }
ESLint rule names in config must be prefixed by the plugin name.

Shows how to install ESLint and the plugin, configure the rule, and see it flag Object.assign usage on an object literal.

// First install ESLint and the plugin: // npm install --save-dev eslint eslint-plugin-prefer-object-spread // In your .eslintrc.js: module.exports = { plugins: ['prefer-object-spread'], rules: { 'prefer-object-spread/prefer-object-spread': 'error' } }; // Example code that would trigger the rule: var a = Object.assign({}, foo); // Error: Use a spread property instead of Object.assign(). // Corrected version: var a = { ...foo };
Debug
Known issues
gotchaThe rule only flags Object.assign() when the target is an object literal. If you mutate an existing object, the rule will not flag it.
fix
No fix needed; this is by design. Use the rule only for cloning patterns.
affects: >=1.0.0
gotchaObject spread only copies own enumerable properties. Object.assign() also copies own enumerable properties, but the rule assumes both are equivalent.
fix
Consider if you have non-enumerable properties or accessor properties. Otherwise, spread is safe.
affects: >=1.0.0
deprecatedThis plugin is no longer actively maintained. ESLint's built-in 'prefer-object-spread' rule may be preferred if available.
fix
Migrate to ESLint's built-in 'prefer-object-spread' rule (since ESLint v5.8.0) by removing the plugin and using `"prefer-object-spread/prefer-object-spread": "error" -> "prefer-object-spread": "error"`.
affects: >=1.2.1
Errors
Common errors & fixes
Error: Failed to load plugin 'prefer-object-spread' declared in '.eslintrc': Cannot find module 'eslint-plugin-prefer-object-spread'
ESLint plugin not installed
fix
Run `npm install --save-dev eslint eslint-plugin-prefer-object-spread`
Parsing error: The keyword 'prefer-object-spread' is not defined
Rule name missing plugin prefix in config
fix
Use 'prefer-object-spread/prefer-object-spread' instead of just 'prefer-object-spread'
Configuration for rule 'prefer-object-spread/prefer-object-spread' is invalid: Severity should be one of the following: 0 = off, 1 = warn, 2 = error
Invalid severity value in ESLint config
fix
Use numbers (0,1,2) or strings ('off','warn','error')
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
eslintrequiredPeer dependency required for loading and running the plugin
Agent activity
2 hits · last 30 days
node
2
Resources
eslint-plugin-prefer-object-spread — npm install eslint-plugin-prefer-object-spread · libregistry