Skip to content

Commit

Permalink
Merge branch 'master' into ignore-non-proptypes-objects
Browse files Browse the repository at this point in the history
  • Loading branch information
TildaDares committed Jul 11, 2022
2 parents 1636884 + f7fe38f commit 1d5af2c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,12 +12,16 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`jsx-no-literals`]: properly error on children with noAttributeStrings: true ([#3317][] @TildaDares)
* [`jsx-key`]: catch key errors inside conditional statements ([#3320][] @TildaDares)
* [`display-name`]: Accept forwardRef and Memo nesting in newer React versions ([#3321][] @TildaDares)
* [`jsx-key`]: avoid a crash from optional chaining from [#3320][] ([#3327][] @ljharb)
* [`jsx-key`]: avoid a crash on a non-array node.body from [#3320][] ([#3328][] @ljharb)

### Changed
* [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223)
* [Tests] [`jsx-indent`], [`jsx-one-expression-per-line`]: add passing test cases ([#3314][] @ROSSROSALES)
* [Refactor] `boolean-prop-naming`, `jsx-indent`: avoid assigning to arguments ([#3316][] @caroline223)

[#3328]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3328
[#3327]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3327
[#3321]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3321
[#3320]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3320
[#3317]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3317
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-key.js
Expand Up @@ -95,7 +95,7 @@ module.exports = {
if (node.alternate) {
getReturnStatements(node.alternate, returnStatements);
}
} else {
} else if (Array.isArray(node.body)) {
node.body.forEach((item) => {
if (item.type === 'IfStatement') {
getReturnStatements(item, returnStatements);
Expand Down
7 changes: 4 additions & 3 deletions tests/helpers/parsers.js
Expand Up @@ -57,7 +57,8 @@ const parsers = {
}
const features = new Set([].concat(test.features || []));
delete test.features;
const es = test.parserOptions && test.parserOptions.ecmaVersion;

const es = features.has('class fields') ? 2022 : (features.has('optional chaining') ? 2020 : (test.parserOptions && test.parserOptions.ecmaVersion) || undefined); // eslint-disable-line no-nested-ternary

function addComment(testObject, parser) {
const extras = [].concat(
Expand Down Expand Up @@ -132,9 +133,9 @@ const parsers = {

return [].concat(
skipBase ? [] : addComment(
Object.assign({}, test, features.has('class fields') && {
Object.assign({}, test, typeof es !== 'undefined' && {
parserOptions: Object.assign({}, test.parserOptions, {
ecmaVersion: Math.max((test.parserOptions && test.parserOptions.ecmaVersion) || 0, 2022),
ecmaVersion: Math.max((test.parserOptions && test.parserOptions.ecmaVersion) || 0, es),
}),
}),
'default'
Expand Down
24 changes: 24 additions & 0 deletions tests/lib/rules/jsx-key.js
Expand Up @@ -124,6 +124,30 @@ ruleTester.run('jsx-key', rule, {
const onTextButtonClick = (e, item) => trackLink([, getAnalyticsUiElement(item), item.name], e);
`,
},
{
code: `
function Component({ allRatings }) {
return (
<RatingDetailsStyles>
{Object.entries(allRatings)?.map(([key, value], index) => {
const rate = value?.split(/(?=[%, /])/);
if (!rate) return null;
return (
<li key={\`\${entertainment.tmdbId}\${index}\`}>
<img src={\`/assets/rating/\${key}.png\`} />
<span className="rating-details--rate">{rate?.[0]}</span>
<span className="rating-details--rate-suffix">{rate?.[1]}</span>
</li>
);
})}
</RatingDetailsStyles>
);
}
`,
features: ['optional chaining'],
},
]),
invalid: parsers.all([
{
Expand Down
3 changes: 0 additions & 3 deletions tests/lib/rules/jsx-no-constructed-context-values.js
Expand Up @@ -63,9 +63,6 @@ ruleTester.run('react-no-constructed-context-values', rule, {
}
`,
features: ['optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down
6 changes: 0 additions & 6 deletions tests/lib/rules/no-array-index-key.js
Expand Up @@ -136,9 +136,6 @@ ruleTester.run('no-array-index-key', rule, {
{
code: 'foo?.map(child => <Foo key={child.i} />)',
features: ['optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
}
),

Expand Down Expand Up @@ -349,9 +346,6 @@ ruleTester.run('no-array-index-key', rule, {
code: 'foo?.map((child, i) => <Foo key={i} />)',
errors: [{ messageId: 'noArrayIndex' }],
features: ['optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down
12 changes: 0 additions & 12 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -807,9 +807,6 @@ ruleTester.run('no-unused-prop-types', rule, {
};
`,
features: ['optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down Expand Up @@ -839,9 +836,6 @@ ruleTester.run('no-unused-prop-types', rule, {
module.exports = HelloComponent();
`,
features: ['optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down Expand Up @@ -871,9 +865,6 @@ ruleTester.run('no-unused-prop-types', rule, {
module.exports = HelloComponent();
`,
features: ['optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down Expand Up @@ -926,9 +917,6 @@ ruleTester.run('no-unused-prop-types', rule, {
};
`,
features: ['optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down
3 changes: 0 additions & 3 deletions tests/lib/rules/no-unused-state.js
Expand Up @@ -353,9 +353,6 @@ eslintTester.run('no-unused-state', rule, {
}
`,
features: ['optional chaining'],
parserOptions: {
ecmaVersion: 2020,
},
},
{
code: `
Expand Down

0 comments on commit 1d5af2c

Please sign in to comment.