eslint-plugin-nextfriday 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +9 -6
- package/docs/rules/JSX_NO_TERNARY_NULL.md +42 -0
- package/lib/index.cjs +392 -326
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +14 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +392 -326
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# eslint-plugin-nextfriday
|
|
2
2
|
|
|
3
|
+
## 1.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#83](https://github.com/next-friday/eslint-plugin-nextfriday/pull/83) [`b7143d2`](https://github.com/next-friday/eslint-plugin-nextfriday/commit/b7143d2f779ca1ca34f6562d09c1a6168b74c338) Thanks [@joetakara](https://github.com/joetakara)! - Add jsx-no-ternary-null rule to enforce logical AND over ternary with null/undefined in JSX
|
|
8
|
+
|
|
3
9
|
## 1.18.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -126,6 +126,7 @@ export default [
|
|
|
126
126
|
"nextfriday/jsx-no-inline-object-prop": "error",
|
|
127
127
|
"nextfriday/jsx-no-newline-single-line-elements": "error",
|
|
128
128
|
"nextfriday/jsx-no-non-component-function": "error",
|
|
129
|
+
"nextfriday/jsx-no-ternary-null": "error",
|
|
129
130
|
"nextfriday/jsx-no-variable-in-callback": "error",
|
|
130
131
|
"nextfriday/jsx-require-suspense": "error",
|
|
131
132
|
"nextfriday/jsx-simple-props": "error",
|
|
@@ -217,6 +218,7 @@ export default [
|
|
|
217
218
|
| [jsx-no-inline-object-prop](docs/rules/JSX_NO_INLINE_OBJECT_PROP.md) | Disallow inline object literals in JSX props | ❌ |
|
|
218
219
|
| [jsx-no-newline-single-line-elements](docs/rules/JSX_NO_NEWLINE_SINGLE_LINE_ELEMENTS.md) | Disallow empty lines between single-line sibling JSX elements | ✅ |
|
|
219
220
|
| [jsx-no-non-component-function](docs/rules/JSX_NO_NON_COMPONENT_FUNCTION.md) | Disallow non-component functions at top level in .tsx/.jsx files | ❌ |
|
|
221
|
+
| [jsx-no-ternary-null](docs/rules/JSX_NO_TERNARY_NULL.md) | Enforce logical AND over ternary with null/undefined in JSX | ✅ |
|
|
220
222
|
| [jsx-no-variable-in-callback](docs/rules/JSX_NO_VARIABLE_IN_CALLBACK.md) | Disallow variable declarations inside callback functions in JSX | ❌ |
|
|
221
223
|
| [jsx-require-suspense](docs/rules/JSX_REQUIRE_SUSPENSE.md) | Require lazy-loaded components to be wrapped in Suspense | ❌ |
|
|
222
224
|
| [jsx-simple-props](docs/rules/JSX_SIMPLE_PROPS.md) | Enforce simple prop values (strings, variables, callbacks, ReactNode) | ❌ |
|
|
@@ -240,10 +242,10 @@ export default [
|
|
|
240
242
|
| -------------------- | -------- | ---------- | --------- | ------------- | ----------- |
|
|
241
243
|
| `base` | warn | 36 | 0 | 0 | 36 |
|
|
242
244
|
| `base/recommended` | error | 36 | 0 | 0 | 36 |
|
|
243
|
-
| `react` | warn | 36 |
|
|
244
|
-
| `react/recommended` | error | 36 |
|
|
245
|
-
| `nextjs` | warn | 36 |
|
|
246
|
-
| `nextjs/recommended` | error | 36 |
|
|
245
|
+
| `react` | warn | 36 | 15 | 0 | 51 |
|
|
246
|
+
| `react/recommended` | error | 36 | 15 | 0 | 51 |
|
|
247
|
+
| `nextjs` | warn | 36 | 15 | 1 | 52 |
|
|
248
|
+
| `nextjs/recommended` | error | 36 | 15 | 1 | 52 |
|
|
247
249
|
|
|
248
250
|
### Base Configuration Rules (36 rules)
|
|
249
251
|
|
|
@@ -286,7 +288,7 @@ Included in `base`, `base/recommended`, and all other presets:
|
|
|
286
288
|
- `nextfriday/sort-type-alphabetically`
|
|
287
289
|
- `nextfriday/sort-type-required-first`
|
|
288
290
|
|
|
289
|
-
### JSX Rules (
|
|
291
|
+
### JSX Rules (15 rules)
|
|
290
292
|
|
|
291
293
|
Additionally included in `react`, `react/recommended`, `nextjs`, `nextjs/recommended`:
|
|
292
294
|
|
|
@@ -296,6 +298,7 @@ Additionally included in `react`, `react/recommended`, `nextjs`, `nextjs/recomme
|
|
|
296
298
|
- `nextfriday/jsx-no-inline-object-prop`
|
|
297
299
|
- `nextfriday/jsx-no-newline-single-line-elements`
|
|
298
300
|
- `nextfriday/jsx-no-non-component-function`
|
|
301
|
+
- `nextfriday/jsx-no-ternary-null`
|
|
299
302
|
- `nextfriday/jsx-no-variable-in-callback`
|
|
300
303
|
- `nextfriday/jsx-pascal-case`
|
|
301
304
|
- `nextfriday/jsx-require-suspense`
|
|
@@ -329,7 +332,7 @@ Additionally included in `nextjs`, `nextjs/recommended` only:
|
|
|
329
332
|
|
|
330
333
|
## Agent Skill
|
|
331
334
|
|
|
332
|
-
This plugin ships with an [Agent Skill](https://github.com/anthropics/skills) that teaches AI coding assistants (Claude Code, Cursor, etc.) all
|
|
335
|
+
This plugin ships with an [Agent Skill](https://github.com/anthropics/skills) that teaches AI coding assistants (Claude Code, Cursor, etc.) all 52 rules so they generate compliant code from the start.
|
|
333
336
|
|
|
334
337
|
```bash
|
|
335
338
|
npx skills add next-friday/eslint-plugin-nextfriday --skill eslint-plugin-nextfriday
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# jsx-no-ternary-null
|
|
2
|
+
|
|
3
|
+
Enforce logical AND over ternary with null/undefined in JSX expressions.
|
|
4
|
+
|
|
5
|
+
> This rule is auto-fixable using `--fix`.
|
|
6
|
+
|
|
7
|
+
## Rule Details
|
|
8
|
+
|
|
9
|
+
This rule flags ternary expressions inside JSX where one branch is `null` or `undefined`. These patterns are better expressed using the logical AND (`&&`) operator, which is more concise and idiomatic in React.
|
|
10
|
+
|
|
11
|
+
### Why?
|
|
12
|
+
|
|
13
|
+
- **Readability**: `{condition && <Component />}` is cleaner than `{condition ? <Component /> : null}`
|
|
14
|
+
- **Consistency**: Encourages a single pattern for conditional rendering
|
|
15
|
+
- **Conciseness**: Removes unnecessary null/undefined branches
|
|
16
|
+
|
|
17
|
+
## Examples
|
|
18
|
+
|
|
19
|
+
### Incorrect
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
<div>{condition ? <span>Hello</span> : null}</div>
|
|
23
|
+
<div>{condition ? <Component /> : undefined}</div>
|
|
24
|
+
<div>{condition ? null : <span>Fallback</span>}</div>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Correct
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
<div>{condition && <span>Hello</span>}</div>
|
|
31
|
+
<div>{condition && <Component />}</div>
|
|
32
|
+
<div>{!condition && <span>Fallback</span>}</div>
|
|
33
|
+
<div>{condition ? <A /> : <B />}</div>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## When Not To Use It
|
|
37
|
+
|
|
38
|
+
If your team prefers explicit ternary expressions for conditional rendering, even when one branch is null or undefined.
|
|
39
|
+
|
|
40
|
+
## Related Rules
|
|
41
|
+
|
|
42
|
+
- [no-nested-ternary](JSX_NO_TERNARY_NULL.md)
|