From 0c17fe81454998192671e609c2f49e870e761e23 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 22 Oct 2024 11:51:35 -0700 Subject: [PATCH] fixup: Update docs/rules/jsx-no-leaked-render.md Co-authored-by: Artyom Konoplyov <46654802+artemxknpv@users.noreply.github.com> --- docs/rules/jsx-no-leaked-render.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/rules/jsx-no-leaked-render.md b/docs/rules/jsx-no-leaked-render.md index dc49e4b817..d034e65973 100644 --- a/docs/rules/jsx-no-leaked-render.md +++ b/docs/rules/jsx-no-leaked-render.md @@ -152,9 +152,32 @@ const Component = ({ elements }) => { The supported options are: ### `ignoreAttributes` +Boolean. When set to `true`, this option ignores all attributes except for `children` during validation, preventing false positives in scenarios where these attributes are used safely or validated internally. Default is `false`. -*TODO* +It can be set like: +```json5 +{ + // ... + "react/jsx-no-leaked-render": [, { "ignoreAttributes": true }] + // ... +} +``` + +Example of incorrect usage with default setting (`ignoreAttributes: false`) and the rule enabled (consider `value` might be undefined): + +```jsx +function MyComponent({ value }) { + return ( + + {value && } + + ); +} +``` + +This would trigger a warning in both `nonChildrenProp` and `children` props because `value` might be undefined. +By setting `ignoreAttributes` to `true`, the rule will not flag this scenario in `nonChildrenProp`, reducing false positives, **but will keep the warning of `children` being leaked**. ### `validStrategies` An array containing `"coerce"`, `"ternary"`, or both (default: `["ternary", "coerce"]`) - Decide which strategies are considered valid to prevent leaked renders (at least 1 is required). The "coerce" option will transform the conditional of the JSX expression to a boolean. The "ternary" option transforms the binary expression into a ternary expression returning `null` for falsy values. The first option from the array will be the strategy used when autofixing, so the order of the values matters.