Skip to content

Commit e1cf8c5

Browse files
committed
[Fix] jsx-first-prop-new-line: ensure autofix preserves generics in component name
Fixes #3546
1 parent 838ac07 commit e1cf8c5

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1414
* [`no-array-index-key`]: consider flatMap ([#3530][] @k-yle)
1515
* [`jsx-curly-brace-presence`]: handle single and only expression template literals ([#3538][] @taozhou-glean)
1616
* [`no-unknown-property`]: allow `onLoad` on `source` (@ljharb)
17+
* [`jsx-first-prop-new-line`]: ensure autofix preserves generics in component name ([#3546][] @ljharb)
1718

1819
[#3548]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3548
20+
[#3546]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3546
1921
[#3538]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3538
2022
[#3533]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3533
2123
[#3530]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3530

lib/rules/jsx-first-prop-new-line.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = {
5454
report(context, messages.propOnNewLine, 'propOnNewLine', {
5555
node: decl,
5656
fix(fixer) {
57-
return fixer.replaceTextRange([node.name.range[1], decl.range[0]], '\n');
57+
return fixer.replaceTextRange([(node.typeParameters || node.name).range[1], decl.range[0]], '\n');
5858
},
5959
});
6060
}

tests/lib/rules/jsx-first-prop-new-line.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,27 @@ bar />
260260
options: ['multiprop'],
261261
errors: [{ messageId: 'propOnSameLine' }],
262262
},
263+
{
264+
code: `
265+
<DataTable<Items> fullscreen keyField="id" items={items}
266+
activeSortableColumn={sorting}
267+
onSortClick={handleSortedClick}
268+
rowActions={[
269+
]}
270+
/>
271+
`,
272+
features: ['ts'],
273+
output: `
274+
<DataTable<Items>
275+
fullscreen keyField="id" items={items}
276+
activeSortableColumn={sorting}
277+
onSortClick={handleSortedClick}
278+
rowActions={[
279+
]}
280+
/>
281+
`,
282+
options: ['multiline'],
283+
errors: [{ messageId: 'propOnNewLine' }],
284+
},
263285
]),
264286
});

tests/lib/rules/jsx-max-props-per-line.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,5 +535,63 @@ baz bor
535535
},
536536
],
537537
},
538+
{
539+
code: `
540+
<DataTable<Items> fullscreen keyField="id" items={items}
541+
activeSortableColumn={sorting}
542+
onSortClick={handleSortedClick}
543+
rowActions={[
544+
]}
545+
/>
546+
`,
547+
features: ['ts'],
548+
output: `
549+
<DataTable<Items> fullscreen
550+
keyField="id"
551+
items={items}
552+
activeSortableColumn={sorting}
553+
onSortClick={handleSortedClick}
554+
rowActions={[
555+
]}
556+
/>
557+
`,
558+
options: [{ maximum: { multi: 1, single: 1 } }],
559+
errors: [
560+
{
561+
messageId: 'newLine',
562+
data: { prop: 'keyField' },
563+
},
564+
],
565+
},
566+
{
567+
code: `
568+
<DataTable<Items>
569+
fullscreen keyField="id" items={items}
570+
activeSortableColumn={sorting}
571+
onSortClick={handleSortedClick}
572+
rowActions={[
573+
]}
574+
/>
575+
`,
576+
features: ['ts'],
577+
output: `
578+
<DataTable<Items>
579+
fullscreen
580+
keyField="id"
581+
items={items}
582+
activeSortableColumn={sorting}
583+
onSortClick={handleSortedClick}
584+
rowActions={[
585+
]}
586+
/>
587+
`,
588+
options: [{ maximum: { multi: 1, single: 1 } }],
589+
errors: [
590+
{
591+
messageId: 'newLine',
592+
data: { prop: 'keyField' },
593+
},
594+
],
595+
},
538596
]),
539597
});

0 commit comments

Comments
 (0)