Skip to content

Commit 04472dd

Browse files
committed
update docs
1 parent 59aee22 commit 04472dd

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

docs/rules/jsx-no-leaked-zero.md

+32-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const Component = ({ numberA, numberB }) => {
5858

5959
```jsx
6060
// If the condition is a boolean value, this rule will report the logical expression
61-
// since it can't guess the type of the condition.
61+
// since it can't infer the type of the condition.
6262
const Component = ({ someBool }) => {
6363
return <div>{someBool && <Results>{numberA+numberB}</Results>}</div>
6464
}
@@ -120,36 +120,60 @@ const Component = ({ elements }) => {
120120

121121
The supported options are:
122122

123-
### `fixStrategy`
124-
`"cast"` or `"ternary"` (default: `"ternary"`) - Decide the strategy to autofix the rule. The "cast" option will cast to boolean the condition of the JSX expression. The "ternary" option transforms the binary expression into a ternary expression returning `null` for falsy values.
123+
### `validFixStrategies`
124+
An array containing `"cast"`, `"ternary"` or both (default: `["ternary", "cast"]`) - Decide which strategies are valid to consider that a potential leaked zero is prevented (at least 1 is required). This also affects the autofix approach used by the rule. The "cast" option will cast to boolean the condition of the JSX expression. The "ternary" option transforms the binary expression into a ternary expression returning `null` for falsy values. If both options are set, the first one will be used for autofixing the reported occurrences.
125125

126126
It can be set like:
127127
```js
128128
// ...
129-
"react/jsx-no-leaked-zero": [<enabled>, { "fixStrategy": <"cast" | "ternary"> }]
129+
"react/jsx-no-leaked-zero": [<enabled>, { "validFixStrategies": ["ternary", "cast"] }]
130130
// ...
131131
```
132132

133-
Assuming the following incorrect code:
133+
Assuming the following options: `{ "validFixStrategies": ["ternary"] }`
134+
135+
Examples of **incorrect** code for this rule, with the above configuration:
134136
```jsx
135137
const Component = ({ count, title }) => {
136138
return <div>{count && title}</div>
137139
}
138140
```
139141

140-
These are the fixes depending on the strategy selected:
141142
```jsx
142-
// fixStrategy: "cast"
143143
const Component = ({ count, title }) => {
144144
return <div>{!!count && title}</div>
145145
}
146+
```
147+
148+
Examples of **correct** code for this rule, with the above configuration:
149+
```jsx
150+
const Component = ({ count, title }) => {
151+
return <div>{count ? title : null}</div>
152+
}
153+
```
154+
155+
Assuming the following options: `{ "validFixStrategies": ["cast"] }`
156+
157+
Examples of **incorrect** code for this rule, with the above configuration:
158+
```jsx
159+
const Component = ({ count, title }) => {
160+
return <div>{count && title}</div>
161+
}
162+
```
146163

147-
// fixStrategy: "ternary"
164+
```jsx
148165
const Component = ({ count, title }) => {
149166
return <div>{count ? title : null}</div>
150167
}
151168
```
152169

170+
Examples of **correct** code for this rule, with the above configuration:
171+
```jsx
172+
const Component = ({ count, title }) => {
173+
return <div>{!!count && title}</div>
174+
}
175+
```
176+
153177
## When Not To Use It
154178

155179
If you are working in a typed-codebase which encourages you to always use boolean conditions, this rule can be disabled.

0 commit comments

Comments
 (0)