mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
PR-URL: https://github.com/nodejs/node/pull/47906 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
/**
|
|
* @fileoverview Rule to check use of chained assignment expressions
|
|
* @author Stewart Rand
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
/** @type {import('../shared/types').Rule} */
|
|
module.exports = {
|
|
meta: {
|
|
type: "suggestion",
|
|
|
|
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",
|
|
default: false
|
|
}
|
|
},
|
|
additionalProperties: false
|
|
}],
|
|
|
|
messages: {
|
|
unexpectedChain: "Unexpected chained assignment."
|
|
}
|
|
},
|
|
|
|
create(context) {
|
|
|
|
//--------------------------------------------------------------------------
|
|
// Public
|
|
//--------------------------------------------------------------------------
|
|
const options = context.options[0] || {
|
|
ignoreNonDeclaration: false
|
|
};
|
|
const selectors = [
|
|
"VariableDeclarator > AssignmentExpression.init",
|
|
"PropertyDefinition > AssignmentExpression.value"
|
|
];
|
|
|
|
if (!options.ignoreNonDeclaration) {
|
|
selectors.push("AssignmentExpression > AssignmentExpression.right");
|
|
}
|
|
|
|
return {
|
|
[selectors](node) {
|
|
context.report({
|
|
node,
|
|
messageId: "unexpectedChain"
|
|
});
|
|
}
|
|
};
|
|
|
|
}
|
|
};
|