Skip to content

Commit

Permalink
[Refactor] jsx-indent-props: improved readability of the checkNodes…
Browse files Browse the repository at this point in the history
…Indent function
  • Loading branch information
caroline223 authored and ljharb committed Jun 29, 2022
1 parent 8887a19 commit 3095e60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
### Added
* [`jsx-newline`]: add `allowMultiline` option when prevent option is true ([#3311][] @TildaDares)

### Fixed
* [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223)

[#3315]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3315
[#3311]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3311

## [7.30.1] - 2022.06.23
Expand Down
14 changes: 10 additions & 4 deletions lib/rules/jsx-indent-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,22 @@ module.exports = {
*/
function checkNodesIndent(nodes, indent) {
nodes.forEach((node) => {
let nestedIndent = indent;
const nodeIndent = getNodeIndent(node);
if (line.isUsingOperator && !line.currentOperator && indentSize !== 'first' && !ignoreTernaryOperator) {
indent += indentSize;
if (
line.isUsingOperator
&& !line.currentOperator
&& indentSize !== 'first'
&& !ignoreTernaryOperator
) {
nestedIndent += indentSize;
line.isUsingOperator = false;
}
if (
node.type !== 'ArrayExpression' && node.type !== 'ObjectExpression'
&& nodeIndent !== indent && astUtil.isNodeFirstInLine(context, node)
&& nodeIndent !== nestedIndent && astUtil.isNodeFirstInLine(context, node)
) {
report(node, indent, nodeIndent);
report(node, nestedIndent, nodeIndent);
}
});
}
Expand Down

0 comments on commit 3095e60

Please sign in to comment.