Skip to content

Commit 4d38484

Browse files
authored
re-implement jsx/no-leaked-conditional-rendering to use type infomation (#91)
1 parent bfb0277 commit 4d38484

File tree

22 files changed

+258
-118
lines changed

22 files changed

+258
-118
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/monorepo",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "ESLint plugin for React function components with TypeScript, built (mostly) from scratch.",
55
"keywords": [
66
"eslint",
@@ -68,8 +68,8 @@
6868
"@typescript-eslint/parser": ">=6.10.0",
6969
"@typescript-eslint/rule-tester": "6.10.0",
7070
"@vitest/ui": "0.34.6",
71-
"bun": "1.0.10",
72-
"bun-types": "1.0.10",
71+
"bun": "1.0.11",
72+
"bun-types": "1.0.11",
7373
"cspell": "7.3.9",
7474
"dprint": "0.42.5",
7575
"effect": "2.0.0-next.54",
@@ -95,7 +95,7 @@
9595
"tiny-invariant": "1.3.1",
9696
"ts-pattern": "5.0.5",
9797
"turbo": "1.10.16",
98-
"type-fest": "4.6.0",
98+
"type-fest": "4.7.0",
9999
"typedoc": "0.25.3",
100100
"typedoc-plugin-markdown": "3.17.1",
101101
"typedoc-plugin-mermaid": "1.10.0",

packages/ast/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/ast",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "AST Utility Module for Static Analysis of TypeScript",
55
"homepage": "https://github.com/eslint-react/eslint-react",
66
"bugs": {

packages/core/docs/README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- [RE\_HOOK\_NAME](README.md#re_hook_name)
4040
- [SuspenseComponent](README.md#suspensecomponent)
4141
- [SuspenseListComponent](README.md#suspenselistcomponent)
42+
- [defaultComponentCollectorHint](README.md#defaultcomponentcollectorhint)
4243

4344
### Functions
4445

@@ -109,8 +110,10 @@
109110
| `SkipClassProperty` | `bigint` |
110111
| `SkipCreateElement` | `bigint` |
111112
| `SkipMapCall` | `bigint` |
112-
| `SkipNull` | `bigint` |
113+
| `SkipNullLiteral` | `bigint` |
114+
| `SkipNumberLiteral` | `bigint` |
113115
| `SkipObjectMethod` | `bigint` |
116+
| `SkipStringLiteral` | `bigint` |
114117
| `StrictArray` | `bigint` |
115118
| `StrictConditional` | `bigint` |
116119
| `StrictLogical` | `bigint` |
@@ -127,7 +130,9 @@
127130
| :------------------ | :------- |
128131
| `None` | `0n` |
129132
| `SkipCreateElement` | `bigint` |
130-
| `SkipNull` | `bigint` |
133+
| `SkipNullLiteral` | `bigint` |
134+
| `SkipNumberLiteral` | `bigint` |
135+
| `SkipStringLiteral` | `bigint` |
131136
| `StrictArray` | `bigint` |
132137
| `StrictConditional` | `bigint` |
133138
| `StrictLogical` | `bigint` |
@@ -270,6 +275,12 @@
270275

271276
`Const` **SuspenseListComponent**: `19`
272277

278+
---
279+
280+
### defaultComponentCollectorHint
281+
282+
`Const` **defaultComponentCollectorHint**: `bigint`
283+
273284
## Functions
274285

275286
### componentCollector
@@ -278,11 +289,11 @@
278289

279290
#### Parameters
280291

281-
| Name | Type | Default value |
282-
| :-------- | :------------------------------------------------------------- | :---------------------------- |
283-
| `context` | `Readonly`\<`RuleContext`\<`string`, readonly `unknown`[]\>\> | `undefined` |
284-
| `hint` | `bigint` | `ComponentCollectorHint.None` |
285-
| `cache` | [`ComponentCollectorCache`](README.md#componentcollectorcache) | `undefined` |
292+
| Name | Type | Default value |
293+
| :-------- | :------------------------------------------------------------- | :------------------------------ |
294+
| `context` | `Readonly`\<`RuleContext`\<`string`, readonly `unknown`[]\>\> | `undefined` |
295+
| `hint` | `bigint` | `defaultComponentCollectorHint` |
296+
| `cache` | [`ComponentCollectorCache`](README.md#componentcollectorcache) | `undefined` |
286297

287298
#### Returns
288299

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/core",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "AST Utility Module for Static Analysis of React core API and Patterns.",
55
"homepage": "https://github.com/eslint-react/eslint-react",
66
"bugs": {

packages/core/src/component/component-collector.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ export const ComponentCollectorHint = {
5959
} as const;
6060
/* eslint-enable perfectionist/sort-objects */
6161

62+
export const defaultComponentCollectorHint = ComponentCollectorHint.SkipStringLiteral
63+
| ComponentCollectorHint.SkipNumberLiteral;
64+
6265
// TODO: support for detecting component types listed in core/component/component-types.ts
6366
export function componentCollector(
6467
context: RuleContext,
65-
hint: bigint = ComponentCollectorHint.None,
68+
hint: bigint = defaultComponentCollectorHint,
6669
cache: ComponentCollectorCache = new WeakMap(),
6770
) {
6871
const components: TSESTreeFunction[] = [];

packages/core/src/render-prop/is-render-prop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function unsafeIsRenderFunction(node: TSESTreeFunction, context: RuleCont
3737
return isJSXValue(
3838
body,
3939
context,
40-
JSXValueCheckHint.SkipNull | JSXValueCheckHint.StrictLogical | JSXValueCheckHint.StrictConditional,
40+
JSXValueCheckHint.SkipNullLiteral | JSXValueCheckHint.StrictLogical | JSXValueCheckHint.StrictConditional,
4141
);
4242
}
4343

packages/eslint-plugin-debug/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/eslint-plugin-debug",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "Debug specific rules for @eslint-react/eslint-plugin",
55
"homepage": "https://github.com/eslint-react/eslint-react",
66
"bugs": {

packages/eslint-plugin-hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/eslint-plugin-hooks",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "Hooks specific rules for @eslint-react/eslint-plugin",
55
"homepage": "https://github.com/eslint-react/eslint-react",
66
"bugs": {

packages/eslint-plugin-jsx/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/eslint-plugin-jsx",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "JSX specific rules for @eslint-react/eslint-plugin",
55
"homepage": "https://github.com/eslint-react/eslint-react",
66
"bugs": {
@@ -56,6 +56,7 @@
5656
"effect": "2.0.0-next.54",
5757
"rambda": "8.5.0",
5858
"string-ts": "1.3.2",
59+
"ts-api-utils": "1.0.3",
5960
"ts-pattern": "5.0.5"
6061
},
6162
"peerDependencies": {

packages/eslint-plugin-jsx/src/rules/no-leaked-conditional-rendering.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ruleTester.run(RULE_NAME, rule, {
7373
`,
7474
dedent`
7575
const App = ({ items, count }) => {
76-
return <div>{direction ? (direction === "down" ? "▼" : "▲") : ""}</div>
76+
return <div>{direction ? (direction === "down" ? "▼" : "▲") : "o"}</div>
7777
}
7878
`,
7979
dedent`

0 commit comments

Comments
 (0)