Skip to content

Commit 6255ca6

Browse files
committed
[Fix] function-component-definition: do not break on dollar signs
Fixes #3207
1 parent f7d50c2 commit 6255ca6

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2323
* [`prop-types`/`propTypes`]: follow a returned identifier to see if it is JSX ([#1046][] @ljharb)
2424
* [`no-unused-state`]: TS: support `getDerivedStateFromProps` as an arrow function ([#2061][] @ljharb)
2525
* [`no-array-index-key`]: catch `.toString` and `String()` usage ([#2813][] @RedTn)
26+
* [`function-component-definition`]: do not break on dollar signs ([#3207][] @ljharb)
2627

2728
### Changed
2829
* [readme] change [`jsx-runtime`] link from branch to sha ([#3160][] @tatsushitoji)
@@ -36,6 +37,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
3637
* [Docs] [`jsx-no-target-blank`]: fix syntax highlighting ([#3199][] @shamrin)
3738
* [Docs] [`jsx-key`]: improve example ([#3202][] @chnakamura)
3839

40+
[#3207]: https://github.com/yannickcr/eslint-plugin-react/issues/3207
3941
[#3202]: https://github.com/yannickcr/eslint-plugin-react/pull/3202
4042
[#3199]: https://github.com/yannickcr/eslint-plugin-react/pull/3199
4143
[#3198]: https://github.com/yannickcr/eslint-plugin-react/pull/3198

lib/rules/function-component-definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const reportC = require('../util/report');
1616

1717
function buildFunction(template, parts) {
1818
return Object.keys(parts)
19-
.reduce((acc, key) => acc.replace(`{${key}}`, parts[key] || ''), template);
19+
.reduce((acc, key) => acc.replace(`{${key}}`, () => (parts[key] || '')), template);
2020
}
2121

2222
const NAMED_FUNCTION_TEMPLATES = {

tests/lib/rules/function-component-definition.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,5 +969,35 @@ ruleTester.run('function-component-definition', rule, {
969969
options: [{ namedComponents: ['function-expression', 'function-declaration'] }],
970970
errors: [{ messageId: 'function-expression' }],
971971
},
972+
{
973+
code: `
974+
const genX = (symbol) => \`the symbol is \${symbol}\`;
975+
976+
const IndexPage = () => {
977+
return (
978+
<div>
979+
Hello World.{genX('$')}
980+
</div>
981+
)
982+
}
983+
984+
export default IndexPage;
985+
`,
986+
output: `
987+
const genX = (symbol) => \`the symbol is \${symbol}\`;
988+
989+
function IndexPage() {
990+
return (
991+
<div>
992+
Hello World.{genX('$')}
993+
</div>
994+
)
995+
}
996+
997+
export default IndexPage;
998+
`,
999+
options: [{ namedComponents: ['function-declaration'] }],
1000+
errors: [{ messageId: 'function-declaration' }],
1001+
},
9721002
]),
9731003
});

0 commit comments

Comments
 (0)