Skip to content

Commit

Permalink
[Fix] Reset line.isUsingOperator correctly after ternary (jsx-eslin…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Waltl committed Dec 14, 2021
1 parent d56fdb8 commit 17467a7
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/jsx-indent-props.js
Expand Up @@ -153,7 +153,7 @@ module.exports = {

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

line.currentOperator = false;
if (useOperator) {
Expand Down
132 changes: 132 additions & 0 deletions tests/lib/rules/jsx-indent-props.js
Expand Up @@ -195,6 +195,48 @@ ruleTester.run('jsx-indent-props', rule, {
},
],
},
{
code: `
const F = () => {
const foo = true
? <div id="id">test</div>
: false;
return <div
id="id"
>
test
</div>
}
`,
options: [
{
indentMode: 2,
ignoreTernaryOperator: false,
},
],
},
{
code: `
const F = () => {
const foo = true
? <div id="id">test</div>
: false;
return <div
id="id"
>
test
</div>
}
`,
options: [
{
indentMode: 2,
ignoreTernaryOperator: true,
},
],
},
{
code: `
{this.props.ignoreTernaryOperatorTrue
Expand Down Expand Up @@ -607,5 +649,95 @@ ruleTester.run('jsx-indent-props', rule, {
},
],
},
{
code: `
const F = () => {
const foo = true
? <div id="id">test</div>
: false;
return <div
id="id"
>
test
</div>
}
`,
output: `
const F = () => {
const foo = true
? <div id="id">test</div>
: false;
return <div
id="id"
>
test
</div>
}
`,
options: [
{
indentMode: 2,
ignoreTernaryOperator: false,
},
],
errors: [
{
messageId: 'wrongIndent',
data: {
needed: 12,
type: 'space',
characters: 'characters',
gotten: 14,
},
},
],
},
{
code: `
const F = () => {
const foo = true
? <div id="id">test</div>
: false;
return <div
id="id"
>
test
</div>
}
`,
output: `
const F = () => {
const foo = true
? <div id="id">test</div>
: false;
return <div
id="id"
>
test
</div>
}
`,
options: [
{
indentMode: 2,
ignoreTernaryOperator: true,
},
],
errors: [
{
messageId: 'wrongIndent',
data: {
needed: 12,
type: 'space',
characters: 'characters',
gotten: 14,
},
},
],
},
]),
});

0 comments on commit 17467a7

Please sign in to comment.