{"id":19875,"library":"eslint-plugin-prefer-object-spread","title":"eslint-plugin-prefer-object-spread","description":"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.","status":"maintenance","version":"1.2.1","language":"javascript","source_language":"en","source_url":"git://github.com/bryanrsmith/eslint-plugin-prefer-object-spread","tags":["javascript","eslint","eslintplugin","eslint-plugin"],"install":[{"cmd":"npm install eslint-plugin-prefer-object-spread","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-prefer-object-spread","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-prefer-object-spread","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for loading and running the plugin","package":"eslint","optional":false}],"imports":[{"note":"In ESLint, plugins are typically referenced by name in config, not imported directly. When importing for testing, named exports may not exist; prefer require.","wrong":"const plugin = require('eslint-plugin-prefer-object-spread');","symbol":"prefer-object-spread (plugin)","correct":"import { rules } from 'eslint-plugin-prefer-object-spread';"},{"note":"Rule must be prefixed with the plugin name in ESLint config.","wrong":"\"prefer-object-spread\": \"error\"","symbol":"prefer-object-spread rule","correct":"\"prefer-object-spread/prefer-object-spread\": \"error\""},{"note":"ESLint rule names in config must be prefixed by the plugin name.","wrong":"{\n  \"plugins\": [\"prefer-object-spread\"],\n  \"rules\": {\n    \"prefer-object-spread\": \"error\"\n  }\n}","symbol":"Plugin registration in ESLint config","correct":"{\n  \"plugins\": [\"prefer-object-spread\"],\n  \"rules\": {\n    \"prefer-object-spread/prefer-object-spread\": \"error\"\n  }\n}"}],"quickstart":{"code":"// First install ESLint and the plugin:\n// npm install --save-dev eslint eslint-plugin-prefer-object-spread\n\n// In your .eslintrc.js:\nmodule.exports = {\n  plugins: ['prefer-object-spread'],\n  rules: {\n    'prefer-object-spread/prefer-object-spread': 'error'\n  }\n};\n\n// Example code that would trigger the rule:\nvar a = Object.assign({}, foo); // Error: Use a spread property instead of Object.assign().\n\n// Corrected version:\nvar a = { ...foo };","lang":"javascript","description":"Shows how to install ESLint and the plugin, configure the rule, and see it flag Object.assign usage on an object literal."},"warnings":[{"fix":"No fix needed; this is by design. Use the rule only for cloning patterns.","message":"The rule only flags Object.assign() when the target is an object literal. If you mutate an existing object, the rule will not flag it.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider if you have non-enumerable properties or accessor properties. Otherwise, spread is safe.","message":"Object spread only copies own enumerable properties. Object.assign() also copies own enumerable properties, but the rule assumes both are equivalent.","severity":"gotcha","affected_versions":">=1.0.0"},{"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\"`.","message":"This plugin is no longer actively maintained. ESLint's built-in 'prefer-object-spread' rule may be preferred if available.","severity":"deprecated","affected_versions":">=1.2.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev eslint eslint-plugin-prefer-object-spread`","cause":"ESLint plugin not installed","error":"Error: Failed to load plugin 'prefer-object-spread' declared in '.eslintrc': Cannot find module 'eslint-plugin-prefer-object-spread'"},{"fix":"Use 'prefer-object-spread/prefer-object-spread' instead of just 'prefer-object-spread'","cause":"Rule name missing plugin prefix in config","error":"Parsing error: The keyword 'prefer-object-spread' is not defined"},{"fix":"Use numbers (0,1,2) or strings ('off','warn','error')","cause":"Invalid severity value in ESLint config","error":"Configuration for rule 'prefer-object-spread/prefer-object-spread' is invalid: Severity should be one of the following: 0 = off, 1 = warn, 2 = error"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}