HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-172-31-4-197 6.8.0-1036-aws #38~22.04.1-Ubuntu SMP Fri Aug 22 15:44:33 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/api-storage/node_modules/eslint/lib/rules/rest-spread-spacing.js
/**
 * @fileoverview Enforce spacing between rest and spread operators and their expressions.
 * @author Kai Cataldo
 * @deprecated in ESLint v8.53.0
 */

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

/** @type {import('../types').Rule.RuleModule} */
module.exports = {
	meta: {
		deprecated: {
			message: "Formatting rules are being moved out of ESLint core.",
			url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
			deprecatedSince: "8.53.0",
			availableUntil: "10.0.0",
			replacedBy: [
				{
					message:
						"ESLint Stylistic now maintains deprecated stylistic core rules.",
					url: "https://eslint.style/guide/migration",
					plugin: {
						name: "@stylistic/eslint-plugin-js",
						url: "https://eslint.style/packages/js",
					},
					rule: {
						name: "rest-spread-spacing",
						url: "https://eslint.style/rules/js/rest-spread-spacing",
					},
				},
			],
		},
		type: "layout",

		docs: {
			description:
				"Enforce spacing between rest and spread operators and their expressions",
			recommended: false,
			url: "https://eslint.org/docs/latest/rules/rest-spread-spacing",
		},

		fixable: "whitespace",

		schema: [
			{
				enum: ["always", "never"],
			},
		],

		messages: {
			unexpectedWhitespace:
				"Unexpected whitespace after {{type}} operator.",
			expectedWhitespace: "Expected whitespace after {{type}} operator.",
		},
	},

	create(context) {
		const sourceCode = context.sourceCode,
			alwaysSpace = context.options[0] === "always";

		//--------------------------------------------------------------------------
		// Helpers
		//--------------------------------------------------------------------------

		/**
		 * Checks whitespace between rest/spread operators and their expressions
		 * @param {ASTNode} node The node to check
		 * @returns {void}
		 */
		function checkWhiteSpace(node) {
			const operator = sourceCode.getFirstToken(node),
				nextToken = sourceCode.getTokenAfter(operator),
				hasWhitespace = sourceCode.isSpaceBetweenTokens(
					operator,
					nextToken,
				);
			let type;

			switch (node.type) {
				case "SpreadElement":
					type = "spread";
					if (node.parent.type === "ObjectExpression") {
						type += " property";
					}
					break;
				case "RestElement":
					type = "rest";
					if (node.parent.type === "ObjectPattern") {
						type += " property";
					}
					break;
				case "ExperimentalSpreadProperty":
					type = "spread property";
					break;
				case "ExperimentalRestProperty":
					type = "rest property";
					break;
				default:
					return;
			}

			if (alwaysSpace && !hasWhitespace) {
				context.report({
					node,
					loc: operator.loc,
					messageId: "expectedWhitespace",
					data: {
						type,
					},
					fix(fixer) {
						return fixer.replaceTextRange(
							[operator.range[1], nextToken.range[0]],
							" ",
						);
					},
				});
			} else if (!alwaysSpace && hasWhitespace) {
				context.report({
					node,
					loc: {
						start: operator.loc.end,
						end: nextToken.loc.start,
					},
					messageId: "unexpectedWhitespace",
					data: {
						type,
					},
					fix(fixer) {
						return fixer.removeRange([
							operator.range[1],
							nextToken.range[0],
						]);
					},
				});
			}
		}

		//--------------------------------------------------------------------------
		// Public
		//--------------------------------------------------------------------------

		return {
			SpreadElement: checkWhiteSpace,
			RestElement: checkWhiteSpace,
			ExperimentalSpreadProperty: checkWhiteSpace,
			ExperimentalRestProperty: checkWhiteSpace,
		};
	},
};