Skip to content

Commit 9d74b89

Browse files
committed
Put jsx-indent attribute check behind an option
1 parent f302f05 commit 9d74b89

File tree

2 files changed

+116
-3
lines changed

2 files changed

+116
-3
lines changed

lib/rules/jsx-indent.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ module.exports = {
5050
}, {
5151
type: 'integer'
5252
}]
53+
}, {
54+
type: 'object',
55+
properties: {
56+
checkAttributes: {
57+
type: 'boolean'
58+
}
59+
},
60+
additionalProperties: false
5361
}]
5462
},
5563

@@ -73,6 +81,7 @@ module.exports = {
7381
}
7482

7583
const indentChar = indentType === 'space' ? ' ' : '\t';
84+
const checkAttributes = context.options[1] && context.options[1].checkAttributes || false;
7685

7786
/**
7887
* Responsible for fixing the indentation issue fix
@@ -243,7 +252,7 @@ module.exports = {
243252
}
244253

245254
function handleAttribute(node) {
246-
if (node.value.type !== 'JSXExpressionContainer') {
255+
if (!checkAttributes || node.value.type !== 'JSXExpressionContainer') {
247256
return;
248257
}
249258
const nameIndent = getNodeIndent(node.name);

tests/lib/rules/jsx-indent.js

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,110 @@ ruleTester.run('jsx-indent', rule, {
716716
`,
717717
parser: 'babel-eslint',
718718
options: [2]
719+
}, {
720+
code: `
721+
const Component = () => (
722+
<View
723+
ListFooterComponent={(
724+
<View
725+
rowSpan={3}
726+
placeholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
727+
/>
728+
)}
729+
/>
730+
);
731+
`,
732+
output: `
733+
const Component = () => (
734+
<View
735+
ListFooterComponent={(
736+
<View
737+
rowSpan={3}
738+
placeholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
739+
/>
740+
)}
741+
/>
742+
);
743+
`,
744+
options: [2]
745+
}, {
746+
code: `
747+
const Component = () => (
748+
\t<View
749+
\t\tListFooterComponent={(
750+
\t\t\t<View
751+
\t\t\t\trowSpan={3}
752+
\t\t\t\tplaceholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
753+
\t\t\t/>
754+
)}
755+
\t/>
756+
);
757+
`,
758+
output: `
759+
const Component = () => (
760+
\t<View
761+
\t\tListFooterComponent={(
762+
\t\t\t<View
763+
\t\t\t\trowSpan={3}
764+
\t\t\t\tplaceholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
765+
\t\t\t/>
766+
\t\t)}
767+
\t/>
768+
);
769+
`,
770+
options: ['tab']
771+
}, {
772+
code: `
773+
const Component = () => (
774+
<View
775+
ListFooterComponent={(
776+
<View
777+
rowSpan={3}
778+
placeholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
779+
/>
780+
)}
781+
/>
782+
);
783+
`,
784+
output: `
785+
const Component = () => (
786+
<View
787+
ListFooterComponent={(
788+
<View
789+
rowSpan={3}
790+
placeholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
791+
/>
792+
)}
793+
/>
794+
);
795+
`,
796+
options: [2, {checkAttributes: false}]
797+
}, {
798+
code: `
799+
const Component = () => (
800+
\t<View
801+
\t\tListFooterComponent={(
802+
\t\t\t<View
803+
\t\t\t\trowSpan={3}
804+
\t\t\t\tplaceholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
805+
\t\t\t/>
806+
)}
807+
\t/>
808+
);
809+
`,
810+
output: `
811+
const Component = () => (
812+
\t<View
813+
\t\tListFooterComponent={(
814+
\t\t\t<View
815+
\t\t\t\trowSpan={3}
816+
\t\t\t\tplaceholder="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
817+
\t\t\t/>
818+
\t\t)}
819+
\t/>
820+
);
821+
`,
822+
options: ['tab', {checkAttributes: false}]
719823
}],
720824

721825
invalid: [{
@@ -1503,7 +1607,7 @@ ruleTester.run('jsx-indent', rule, {
15031607
/>
15041608
);
15051609
`,
1506-
options: [2],
1610+
options: [2, {checkAttributes: true}],
15071611
errors: [
15081612
{message: 'Expected indentation of 8 space characters but found 4.'}
15091613
]
@@ -1532,7 +1636,7 @@ const Component = () => (
15321636
\t/>
15331637
);
15341638
`,
1535-
options: ['tab'],
1639+
options: ['tab', {checkAttributes: true}],
15361640
errors: [
15371641
{message: 'Expected indentation of 2 tab characters but found 0.'}
15381642
]

0 commit comments

Comments
 (0)