| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /**
- * @fileoverview Rule to check use of chained assignment expressions
- * @author Stewart Rand
- */
- "use strict";
- //------------------------------------------------------------------------------
- // Rule Definition
- //------------------------------------------------------------------------------
- /** @type {import('../types').Rule.RuleModule} */
- module.exports = {
- meta: {
- type: "suggestion",
- defaultOptions: [
- {
- ignoreNonDeclaration: false,
- },
- ],
- docs: {
- description: "Disallow use of chained assignment expressions",
- recommended: false,
- url: "https://eslint.org/docs/latest/rules/no-multi-assign",
- },
- schema: [
- {
- type: "object",
- properties: {
- ignoreNonDeclaration: {
- type: "boolean",
- },
- },
- additionalProperties: false,
- },
- ],
- messages: {
- unexpectedChain: "Unexpected chained assignment.",
- },
- },
- create(context) {
- const [{ ignoreNonDeclaration }] = context.options;
- const selectors = [
- "VariableDeclarator > AssignmentExpression.init",
- "PropertyDefinition > AssignmentExpression.value",
- ];
- if (!ignoreNonDeclaration) {
- selectors.push("AssignmentExpression > AssignmentExpression.right");
- }
- return {
- [selectors](node) {
- context.report({
- node,
- messageId: "unexpectedChain",
- });
- },
- };
- },
- };
|