Skip to content

Commit 1d0bc97

Browse files
caroline223ljharb
authored andcommitted
[Refactor] jsx-indent-props: improved readability of the checkNodesIndent function
1 parent 8887a19 commit 1d0bc97

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
88
### Added
99
* [`jsx-newline`]: add `allowMultiline` option when prevent option is true ([#3311][] @TildaDares)
1010

11+
### Fixed
12+
* [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223)
13+
14+
[#3315]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3315
1115
[#3311]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3311
1216

1317
## [7.30.1] - 2022.06.23

lib/rules/jsx-indent-props.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,23 @@ module.exports = {
172172
* @param {Number} indent needed indent
173173
*/
174174
function checkNodesIndent(nodes, indent) {
175+
let nestedIndent = indent;
175176
nodes.forEach((node) => {
176177
const nodeIndent = getNodeIndent(node);
177-
if (line.isUsingOperator && !line.currentOperator && indentSize !== 'first' && !ignoreTernaryOperator) {
178-
indent += indentSize;
178+
if (
179+
line.isUsingOperator
180+
&& !line.currentOperator
181+
&& indentSize !== 'first'
182+
&& !ignoreTernaryOperator
183+
) {
184+
nestedIndent += indentSize;
179185
line.isUsingOperator = false;
180186
}
181187
if (
182188
node.type !== 'ArrayExpression' && node.type !== 'ObjectExpression'
183-
&& nodeIndent !== indent && astUtil.isNodeFirstInLine(context, node)
189+
&& nodeIndent !== nestedIndent && astUtil.isNodeFirstInLine(context, node)
184190
) {
185-
report(node, indent, nodeIndent);
191+
report(node, nestedIndent, nodeIndent);
186192
}
187193
});
188194
}

0 commit comments

Comments
 (0)