]> git.proxmox.com Git - pve-eslint.git/blame - eslint/lib/rules/no-multi-assign.js
import 8.4.0 source
[pve-eslint.git] / eslint / lib / rules / no-multi-assign.js
CommitLineData
eb39fafa
DC
1/**
2 * @fileoverview Rule to check use of chained assignment expressions
3 * @author Stewart Rand
4 */
5
6"use strict";
7
8
9//------------------------------------------------------------------------------
10// Rule Definition
11//------------------------------------------------------------------------------
12
34eeec05 13/** @type {import('../shared/types').Rule} */
eb39fafa
DC
14module.exports = {
15 meta: {
16 type: "suggestion",
17
18 docs: {
19 description: "disallow use of chained assignment expressions",
eb39fafa
DC
20 recommended: false,
21 url: "https://eslint.org/docs/rules/no-multi-assign"
22 },
23
5422a9cc
TL
24 schema: [{
25 type: "object",
26 properties: {
27 ignoreNonDeclaration: {
28 type: "boolean",
29 default: false
30 }
31 },
32 additionalProperties: false
33 }],
eb39fafa
DC
34
35 messages: {
36 unexpectedChain: "Unexpected chained assignment."
37 }
38 },
39
40 create(context) {
41
42 //--------------------------------------------------------------------------
43 // Public
44 //--------------------------------------------------------------------------
5422a9cc
TL
45 const options = context.options[0] || {
46 ignoreNonDeclaration: false
47 };
609c276f
TL
48 const selectors = [
49 "VariableDeclarator > AssignmentExpression.init",
50 "PropertyDefinition > AssignmentExpression.value"
51 ];
52
53 if (!options.ignoreNonDeclaration) {
54 selectors.push("AssignmentExpression > AssignmentExpression.right");
55 }
eb39fafa
DC
56
57 return {
609c276f
TL
58 [selectors](node) {
59 context.report({
60 node,
61 messageId: "unexpectedChain"
62 });
eb39fafa
DC
63 }
64 };
65
66 }
67};