2024-08-09 12:04:48 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview Rule to check use of chained assignment expressions
|
|
|
|
* @author Stewart Rand
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Rule Definition
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2024-08-21 06:34:30 +00:00
|
|
|
/** @type {import('../shared/types').Rule} */
|
2024-08-09 12:04:48 +00:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
type: "suggestion",
|
|
|
|
|
|
|
|
docs: {
|
2024-08-21 06:34:30 +00:00
|
|
|
description: "Disallow use of chained assignment expressions",
|
2024-08-09 12:04:48 +00:00
|
|
|
recommended: false,
|
2024-08-21 06:34:30 +00:00
|
|
|
url: "https://eslint.org/docs/latest/rules/no-multi-assign"
|
2024-08-09 12:04:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
2024-08-21 06:34:30 +00:00
|
|
|
const selectors = [
|
|
|
|
"VariableDeclarator > AssignmentExpression.init",
|
|
|
|
"PropertyDefinition > AssignmentExpression.value"
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!options.ignoreNonDeclaration) {
|
|
|
|
selectors.push("AssignmentExpression > AssignmentExpression.right");
|
|
|
|
}
|
2024-08-09 12:04:48 +00:00
|
|
|
|
|
|
|
return {
|
2024-08-21 06:34:30 +00:00
|
|
|
[selectors](node) {
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
messageId: "unexpectedChain"
|
|
|
|
});
|
2024-08-09 12:04:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|