Skip to content

Commit de82efe

Browse files
committed
2 parents a7287a2 + 3c11201 commit de82efe

16 files changed

+67
-84
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
77

88
### Fixed
99
* [`require-default-props`]: fix config schema ([#3605][] @controversial)
10+
* [`jsx-curly-brace-presence`]: Revert [#3538][] due to issues with intended string type casting usage ([#3611][] @taozhou-glean)
11+
* [`sort-prop-types`]: ensure sort-prop-types respects noSortAlphabetically ([#3610][] @caesar1030)
1012

13+
[#3611]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3611
14+
[#3610]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3610
1115
[#3605]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3605
1216

1317
## [7.33.0] - 2023.07.19

lib/rules/jsx-curly-brace-presence.js

-10
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ module.exports = {
131131
return containsLineTerminators(text) && text.trim() === '';
132132
}
133133

134-
function isSingleExpressionTemplateLiteral(child) {
135-
return child.type === 'TemplateLiteral' && child.expressions.length === 1 && child.quasis.map((quasis) => quasis.value.raw).join('') === '';
136-
}
137-
138134
function wrapNonHTMLEntities(text) {
139135
const HTML_ENTITY = '<HTML_ENTITY>';
140136
const withCurlyBraces = text.split(HTML_ENTITY_REGEX()).map((word) => (
@@ -181,9 +177,6 @@ module.exports = {
181177
if (jsxUtil.isJSX(expression)) {
182178
const sourceCode = context.getSourceCode();
183179
textToReplace = sourceCode.getText(expression);
184-
} else if (isSingleExpressionTemplateLiteral(expression)) {
185-
const sourceCode = context.getSourceCode();
186-
textToReplace = `{${sourceCode.getText(expression.expressions[0])}}`;
187180
} else {
188181
const expressionType = expression && expression.type;
189182
const parentType = JSXExpressionNode.parent.type;
@@ -286,9 +279,6 @@ module.exports = {
286279
&& !containsQuoteCharacters(expression.quasis[0].value.cooked)
287280
) {
288281
reportUnnecessaryCurly(JSXExpressionNode);
289-
} else if (
290-
isSingleExpressionTemplateLiteral(expression)) {
291-
reportUnnecessaryCurly(JSXExpressionNode);
292282
} else if (jsxUtil.isJSX(expression)) {
293283
reportUnnecessaryCurly(JSXExpressionNode);
294284
}

tests/lib/rules/default-props-match-prop-types.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ ruleTester.run('default-props-match-prop-types', rule, {
789789
placeholder?: string,
790790
disabled?: boolean,
791791
};
792-
792+
793793
TextField.defaultProps = {
794794
label: '',
795795
placeholder: '',
@@ -1761,12 +1761,12 @@ ruleTester.run('default-props-match-prop-types', rule, {
17611761
export type SharedProps = {|
17621762
disabled: boolean,
17631763
|};
1764-
1764+
17651765
type Props = {|
17661766
...SharedProps,
17671767
focused?: boolean,
17681768
|};
1769-
1769+
17701770
class Foo extends React.Component<Props> {
17711771
static defaultProps = {
17721772
disabled: false

tests/lib/rules/destructuring-assignment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ ruleTester.run('destructuring-assignment', rule, {
857857
],
858858
output: `
859859
function Foo({a}) {
860-
860+
${' '}
861861
return <p>{a}</p>;
862862
}
863863
`,
@@ -878,7 +878,7 @@ ruleTester.run('destructuring-assignment', rule, {
878878
],
879879
output: `
880880
function Foo({a}: FooProps) {
881-
881+
${' '}
882882
return <p>{a}</p>;
883883
}
884884
`,

tests/lib/rules/display-name.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -543,15 +543,15 @@ ruleTester.run('display-name', rule, {
543543
name: 'Bob',
544544
},
545545
];
546-
546+
547547
const columns = [
548548
{
549549
Header: 'Name',
550550
accessor: 'name',
551551
Cell: ({ value }) => <div>{value}</div>,
552552
},
553553
];
554-
554+
555555
return <ReactTable columns={columns} data={data} />;
556556
}
557557
`,
@@ -576,15 +576,15 @@ ruleTester.run('display-name', rule, {
576576
name: 'Bob',
577577
},
578578
];
579-
579+
580580
const columns = [
581581
{
582582
Header: 'Name',
583583
accessor: 'name',
584584
Cell: ({ value }) => <div>{value}</div>,
585585
},
586586
];
587-
587+
588588
return <ReactTable columns={columns} data={data} />;
589589
}
590590
}
@@ -660,7 +660,7 @@ ruleTester.run('display-name', rule, {
660660
function MyComponent(props) {
661661
return <b>{props.name}</b>;
662662
}
663-
663+
664664
const MemoizedMyComponent = React.memo(
665665
MyComponent,
666666
(prevProps, nextProps) => prevProps.name === nextProps.name
@@ -1284,11 +1284,11 @@ ruleTester.run('display-name', rule, {
12841284
const data = processData({ value: 'data' });
12851285
return <div>{data}</div>;
12861286
});
1287-
1287+
12881288
export const Component2 = observer(() => {
12891289
const data = processData();
12901290
return <div>{data}</div>;
1291-
});
1291+
});
12921292
`,
12931293
features: ['optional chaining', 'types'],
12941294
settings: { componentWrapperFunctions: ['observer'] },

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ ruleTester.run('function-component-definition', rule, {
11441144
</div>
11451145
)
11461146
}
1147-
1147+
11481148
export default IndexPage;
11491149
`,
11501150
output: `
@@ -1157,7 +1157,7 @@ ruleTester.run('function-component-definition', rule, {
11571157
</div>
11581158
)
11591159
}
1160-
1160+
11611161
export default IndexPage;
11621162
`,
11631163
options: [{ namedComponents: ['function-declaration'] }],

tests/lib/rules/jsx-curly-brace-presence.js

+17-28
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,14 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
469469
features: ['no-ts'],
470470
options: ['never'],
471471
},
472+
// legit as this single template literal might be used for stringifying
472473
{
473-
code: '<App label={`${label}${suffix}`} />',
474-
options: [{ props: 'never' }],
474+
code: '<App label={`${label}`} />',
475+
options: ['never'],
475476
},
476477
{
477-
code: '<App>{`${label}${suffix}`}</App>',
478-
options: [{ children: 'never' }],
478+
code: '<App>{`${label}`}</App>',
479+
options: ['never'],
479480
}
480481
)),
481482

@@ -786,23 +787,23 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
786787
},
787788
{
788789
code: `
789-
<App prop="
790-
a
790+
<App prop="${' '}
791+
a${' '}
791792
b c
792793
d
793794
">
794795
a
795-
b c
796-
d
796+
b c${' '}
797+
d${' '}
797798
</App>
798799
`,
799800
errors: [
800801
{ messageId: 'missingCurly' }, { messageId: 'missingCurly' },
801802
],
802803
options: ['always'],
803804
output: `
804-
<App prop="
805-
a
805+
<App prop="${' '}
806+
a${' '}
806807
b c
807808
d
808809
">
@@ -814,23 +815,23 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
814815
},
815816
{
816817
code: `
817-
<App prop='
818-
a
818+
<App prop='${' '}
819+
a${' '}
819820
b c
820821
d
821822
'>
822823
a
823-
b c
824-
d
824+
b c${' '}
825+
d${' '}
825826
</App>
826827
`,
827828
errors: [
828829
{ messageId: 'missingCurly' }, { messageId: 'missingCurly' },
829830
],
830831
options: ['always'],
831832
output: `
832-
<App prop='
833-
a
833+
<App prop='${' '}
834+
a${' '}
834835
b c
835836
d
836837
'>
@@ -939,18 +940,6 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
939940
errors: [{ messageId: 'unnecessaryCurly' }],
940941
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
941942
features: ['no-ts'],
942-
},
943-
{
944-
code: '<App label={`${label}`} />',
945-
output: '<App label={label} />',
946-
errors: [{ messageId: 'unnecessaryCurly' }],
947-
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
948-
},
949-
{
950-
code: '<App>{`${label}`}</App>',
951-
output: '<App>{label}</App>',
952-
errors: [{ messageId: 'unnecessaryCurly' }],
953-
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
954943
}
955944
)),
956945
});

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
4949
{
5050
code: `
5151
<Foo a
52-
b
52+
b
5353
/>
5454
`,
5555
options: ['never'],
@@ -109,7 +109,7 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
109109
},
110110
{
111111
code: `
112-
<Foo
112+
<Foo
113113
foo={{
114114
}}
115115
bar

tests/lib/rules/jsx-indent.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ruleTester.run('jsx-indent', rule, {
4545
{
4646
code: `
4747
<App>
48-
</App>
48+
</App>
4949
`,
5050
},
5151
{
@@ -1183,21 +1183,21 @@ const Component = () => (
11831183
state = {
11841184
name: '',
11851185
}
1186-
1186+
11871187
componentDidMount() {
11881188
this.fetchName()
11891189
.then(name => {
11901190
this.setState({name})
11911191
});
11921192
}
1193-
1193+
11941194
fetchName = () => {
11951195
const url = 'https://api.github.com/users/job13er'
11961196
return fetch(url)
11971197
.then(resp => resp.json())
11981198
.then(json => json.name)
11991199
}
1200-
1200+
12011201
render() {
12021202
const {name} = this.state
12031203
return (

0 commit comments

Comments
 (0)