Repository: eslint/eslint
File: lib/rules/grouped-accessor-pairs.js (JavaScript)

Code before:
								],
							},
							enforceForTSTypes: {
								type: "boolean",
							},
						},
						additionalProperties: false,
					},
				],
			},
		],

		messages: {
			notGrouped:
				"Accessor pair {{ formerName }} and {{ latterName }} should be grouped.",
			invalidOrder:
				"Expected {{ latterName }} to be before {{ formerName }}.",
		},
	},

	create(context) {
		const order =
			typeof context.options[0] === "string"
				? context.options[0]
				: (context.options[0].order ?? DEFAULT_ORDER);
		const enforceForTSTypes = context.options[0].enforceForTSTypes ?? false;
		const sourceCode = context.sourceCode;

		/**
		 * Reports the given accessor pair.
		 * @param {string} messageId messageId to report.
		 * @param {ASTNode} formerNode getter/setter node that is defined before `latterNode`.
		 * @param {ASTNode} latterNode getter/setter node that is defined after `formerNode`.
		 * @returns {void}
		 * @private
		 */
		function report(messageId, formerNode, latterNode) {
			context.report({
				node: latterNode,
				messageId,
				loc: astUtils.getFunctionHeadLoc(
					latterNode.type !== "TSMethodSignature"
						? latterNode.value
						: latterNode,
					sourceCode,
				),
				data: {
					formerName: astUtils.getFunctionNameWithKind(
						formerNode.type !== "TSMethodSignature"
							? formerNode.value
							: formerNode,

Review comment (refactor):
[Refactor] `order` checks that the first option is a string before accessing a property. But then the second one doesn't. Just for consistency:

```suggestion
   const [order, enforceForTSTypes] =
     typeof context.options[0] === "string"
       ? [context.options[0], false]
       : [context.options[0].order, context.options[0].enforceForTSTypes ?? false];
```

Code after:

		messages: {
			notGrouped:
				"Accessor pair {{ formerName }} and {{ latterName }} should be grouped.",
			invalidOrder:
				"Expected {{ latterName }} to be before {{ formerName }}.",
		},
	},

	create(context) {
		const order = context.options[0] ?? DEFAULT_ORDER;
		const enforceForTSTypes =
			context.options[1]?.enforceForTSTypes ?? false;
		const sourceCode = context.sourceCode;

		/**
		 * Reports the given accessor pair.
		 * @param {string} messageId messageId to report.
		 * @param {ASTNode} formerNode getter/setter node that is defined before `latterNode`.
		 * @param {ASTNode} latterNode getter/setter node that is defined after `formerNode`.
		 * @returns {void}
		 * @private
		 */
		function report(messageId, formerNode, latterNode) {
			context.report({
				node: latterNode,
				messageId,
				loc: astUtils.getFunctionHeadLoc(
					latterNode.type !== "TSMethodSignature"
						? latterNode.value
						: latterNode,
					sourceCode,
				),
				data: {
					formerName: astUtils.getFunctionNameWithKind(
						formerNode.type !== "TSMethodSignature"
							? formerNode.value
							: formerNode,
					),
					latterName: astUtils.getFunctionNameWithKind(
						latterNode.type !== "TSMethodSignature"
							? latterNode.value
							: latterNode,
					),
				},
			});
		}

		/**
		 * Checks accessor pairs in the given list of nodes.
		 * @param {ASTNode[]} nodes The list to check.