Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
caesar1030 committed Dec 3, 2023
2 parents a7287a2 + 3c11201 commit de82efe
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

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

[#3611]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3611
[#3610]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3610
[#3605]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3605

## [7.33.0] - 2023.07.19
Expand Down
10 changes: 0 additions & 10 deletions lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ module.exports = {
return containsLineTerminators(text) && text.trim() === '';
}

function isSingleExpressionTemplateLiteral(child) {
return child.type === 'TemplateLiteral' && child.expressions.length === 1 && child.quasis.map((quasis) => quasis.value.raw).join('') === '';
}

function wrapNonHTMLEntities(text) {
const HTML_ENTITY = '<HTML_ENTITY>';
const withCurlyBraces = text.split(HTML_ENTITY_REGEX()).map((word) => (
Expand Down Expand Up @@ -181,9 +177,6 @@ module.exports = {
if (jsxUtil.isJSX(expression)) {
const sourceCode = context.getSourceCode();
textToReplace = sourceCode.getText(expression);
} else if (isSingleExpressionTemplateLiteral(expression)) {
const sourceCode = context.getSourceCode();
textToReplace = `{${sourceCode.getText(expression.expressions[0])}}`;
} else {
const expressionType = expression && expression.type;
const parentType = JSXExpressionNode.parent.type;
Expand Down Expand Up @@ -286,9 +279,6 @@ module.exports = {
&& !containsQuoteCharacters(expression.quasis[0].value.cooked)
) {
reportUnnecessaryCurly(JSXExpressionNode);
} else if (
isSingleExpressionTemplateLiteral(expression)) {
reportUnnecessaryCurly(JSXExpressionNode);
} else if (jsxUtil.isJSX(expression)) {
reportUnnecessaryCurly(JSXExpressionNode);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/rules/default-props-match-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ ruleTester.run('default-props-match-prop-types', rule, {
placeholder?: string,
disabled?: boolean,
};
TextField.defaultProps = {
label: '',
placeholder: '',
Expand Down Expand Up @@ -1761,12 +1761,12 @@ ruleTester.run('default-props-match-prop-types', rule, {
export type SharedProps = {|
disabled: boolean,
|};
type Props = {|
...SharedProps,
focused?: boolean,
|};
class Foo extends React.Component<Props> {
static defaultProps = {
disabled: false
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ ruleTester.run('destructuring-assignment', rule, {
],
output: `
function Foo({a}) {
${' '}
return <p>{a}</p>;
}
`,
Expand All @@ -878,7 +878,7 @@ ruleTester.run('destructuring-assignment', rule, {
],
output: `
function Foo({a}: FooProps) {
${' '}
return <p>{a}</p>;
}
`,
Expand Down
14 changes: 7 additions & 7 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,15 @@ ruleTester.run('display-name', rule, {
name: 'Bob',
},
];
const columns = [
{
Header: 'Name',
accessor: 'name',
Cell: ({ value }) => <div>{value}</div>,
},
];
return <ReactTable columns={columns} data={data} />;
}
`,
Expand All @@ -576,15 +576,15 @@ ruleTester.run('display-name', rule, {
name: 'Bob',
},
];
const columns = [
{
Header: 'Name',
accessor: 'name',
Cell: ({ value }) => <div>{value}</div>,
},
];
return <ReactTable columns={columns} data={data} />;
}
}
Expand Down Expand Up @@ -660,7 +660,7 @@ ruleTester.run('display-name', rule, {
function MyComponent(props) {
return <b>{props.name}</b>;
}
const MemoizedMyComponent = React.memo(
MyComponent,
(prevProps, nextProps) => prevProps.name === nextProps.name
Expand Down Expand Up @@ -1284,11 +1284,11 @@ ruleTester.run('display-name', rule, {
const data = processData({ value: 'data' });
return <div>{data}</div>;
});
export const Component2 = observer(() => {
const data = processData();
return <div>{data}</div>;
});
});
`,
features: ['optional chaining', 'types'],
settings: { componentWrapperFunctions: ['observer'] },
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/function-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ ruleTester.run('function-component-definition', rule, {
</div>
)
}
export default IndexPage;
`,
output: `
Expand All @@ -1157,7 +1157,7 @@ ruleTester.run('function-component-definition', rule, {
</div>
)
}
export default IndexPage;
`,
options: [{ namedComponents: ['function-declaration'] }],
Expand Down
45 changes: 17 additions & 28 deletions tests/lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,14 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
features: ['no-ts'],
options: ['never'],
},
// legit as this single template literal might be used for stringifying
{
code: '<App label={`${label}${suffix}`} />',
options: [{ props: 'never' }],
code: '<App label={`${label}`} />',
options: ['never'],
},
{
code: '<App>{`${label}${suffix}`}</App>',
options: [{ children: 'never' }],
code: '<App>{`${label}`}</App>',
options: ['never'],
}
)),

Expand Down Expand Up @@ -786,23 +787,23 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
},
{
code: `
<App prop="
a
<App prop="${' '}
a${' '}
b c
d
">
a
b c
d
b c${' '}
d${' '}
</App>
`,
errors: [
{ messageId: 'missingCurly' }, { messageId: 'missingCurly' },
],
options: ['always'],
output: `
<App prop="
a
<App prop="${' '}
a${' '}
b c
d
">
Expand All @@ -814,23 +815,23 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
},
{
code: `
<App prop='
a
<App prop='${' '}
a${' '}
b c
d
'>
a
b c
d
b c${' '}
d${' '}
</App>
`,
errors: [
{ messageId: 'missingCurly' }, { messageId: 'missingCurly' },
],
options: ['always'],
output: `
<App prop='
a
<App prop='${' '}
a${' '}
b c
d
'>
Expand Down Expand Up @@ -939,18 +940,6 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
errors: [{ messageId: 'unnecessaryCurly' }],
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
features: ['no-ts'],
},
{
code: '<App label={`${label}`} />',
output: '<App label={label} />',
errors: [{ messageId: 'unnecessaryCurly' }],
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
},
{
code: '<App>{`${label}`}</App>',
output: '<App>{label}</App>',
errors: [{ messageId: 'unnecessaryCurly' }],
options: [{ props: 'never', children: 'never', propElementValues: 'never' }],
}
)),
});
4 changes: 2 additions & 2 deletions tests/lib/rules/jsx-first-prop-new-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
{
code: `
<Foo a
b
b
/>
`,
options: ['never'],
Expand Down Expand Up @@ -109,7 +109,7 @@ ruleTester.run('jsx-first-prop-new-line', rule, {
},
{
code: `
<Foo
<Foo
foo={{
}}
bar
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ruleTester.run('jsx-indent', rule, {
{
code: `
<App>
</App>
</App>
`,
},
{
Expand Down Expand Up @@ -1183,21 +1183,21 @@ const Component = () => (
state = {
name: '',
}
componentDidMount() {
this.fetchName()
.then(name => {
this.setState({name})
});
}
fetchName = () => {
const url = 'https://api.github.com/users/job13er'
return fetch(url)
.then(resp => resp.json())
.then(json => json.name)
}
render() {
const {name} = this.state
return (
Expand Down
Loading

0 comments on commit de82efe

Please sign in to comment.