Skip to content

Commit

Permalink
[Fix] jsx-indent-props: Apply indentation when using brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
Moong0122 authored and ljharb committed Oct 13, 2020
1 parent 632639b commit 237547e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## Unreleased

### Fixed
* [`jsx-indent-props`]: Apply indentation when using brackets ([#2826][] @Moong0122)

[#2826]: https://github.com/yannickcr/eslint-plugin-react/issues/2826

## [7.21.4] - 2020.10.09

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/jsx-indent-props.js
Expand Up @@ -124,10 +124,14 @@ module.exports = {

const indent = regExp.exec(src);
const useOperator = /^([ ]|[\t])*[:]/.test(src) || /^([ ]|[\t])*[?]/.test(src);
const useBracket = /^([ ]|[\t])*[<]/.test(src);

line.currentOperator = false;
if (useOperator) {
line.isUsingOperator = true;
line.currentOperator = true;
} else if (useBracket) {
line.isUsingOperator = false;
}

return indent ? indent[0].length : 0;
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/jsx-indent-props.js
Expand Up @@ -38,6 +38,23 @@ ruleTester.run('jsx-indent-props', rule, {
'/>'
].join('\n'),
options: [2]
}, {
code: [
'const Test = () => ([',
' (x',
' ? <div key="1" />',
' : <div key="2" />),',
' <div',
' key="3"',
' align="left"',
' />,',
' <div',
' key="4"',
' align="left"',
' />,',
']);'
].join('\n'),
options: [2]
}, {
code: [
'<App',
Expand Down

0 comments on commit 237547e

Please sign in to comment.