tsl-react 0.0.1-next.0 → 0.0.2-next.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/dist/index.d.ts +54 -56
- package/dist/index.js +3 -60
- package/package.json +8 -7
- package/README.md +0 -69
package/dist/index.d.ts
CHANGED
|
@@ -1,58 +1,56 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Rule } from 'tsl';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
noLeakedConditionalRendering: (options?: "off" | undefined) => tsl.Rule<unknown>;
|
|
56
|
-
}>;
|
|
3
|
+
/**
|
|
4
|
+
* Prevents problematic leaked values from being rendered.
|
|
5
|
+
*
|
|
6
|
+
* Using the && operator to render some element conditionally in JSX can cause unexpected values being rendered, or even crashing the rendering.
|
|
7
|
+
*
|
|
8
|
+
* **Examples**
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import React from "react";
|
|
12
|
+
*
|
|
13
|
+
* interface MyComponentProps {
|
|
14
|
+
* count: number;
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* function MyComponent({ count }: MyComponentProps) {
|
|
18
|
+
* return <div>{count && <span>There are {count} results</span>}</div>;
|
|
19
|
+
* // ^^^^^
|
|
20
|
+
* // - Potential leaked value 'count' that might cause unintentionally rendered values or rendering crashes.
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* import React from "react";
|
|
26
|
+
*
|
|
27
|
+
* interface MyComponentProps {
|
|
28
|
+
* items: string[];
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* function MyComponent({ items }: MyComponentProps) {
|
|
32
|
+
* return <div>{items.length && <List items={items} />}</div>;
|
|
33
|
+
* // ^^^^^^^^^^^^
|
|
34
|
+
* // - Potential leaked value 'items.length' that might cause unintentionally rendered values or rendering crashes.
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* ```tsx
|
|
39
|
+
* import React from "react";
|
|
40
|
+
*
|
|
41
|
+
* interface MyComponentProps {
|
|
42
|
+
* items: string[];
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* function MyComponent({ items }: MyComponentProps) {
|
|
46
|
+
* return <div>{items[0] && <List items={items} />}</div>;
|
|
47
|
+
* // ^^^^^^^^
|
|
48
|
+
* // - Potential leaked value 'items[0]' that might cause unintentionally rendered values or rendering crashes.
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @since 0.0.0
|
|
53
|
+
*/
|
|
54
|
+
declare const noLeakedConditionalRendering: (options?: "off" | undefined) => Rule<unknown>;
|
|
57
55
|
|
|
58
|
-
export {
|
|
56
|
+
export { noLeakedConditionalRendering };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineRule, createRulesSet } from 'tsl';
|
|
2
1
|
import { compare } from 'compare-versions';
|
|
2
|
+
import { defineRule } from 'tsl';
|
|
3
3
|
import { SyntaxKind } from 'typescript';
|
|
4
4
|
import { isLogicalNegationExpression } from '@react-analyzer/ast';
|
|
5
5
|
import { unit } from '@react-analyzer/eff';
|
|
@@ -7,7 +7,7 @@ import { Report } from '@react-analyzer/kit';
|
|
|
7
7
|
import { getAnalyzerOptions } from '@react-analyzer/shared';
|
|
8
8
|
import * as RA from '@react-analyzer/core';
|
|
9
9
|
|
|
10
|
-
// src/
|
|
10
|
+
// src/rules/no-leaked-conditional-rendering.ts
|
|
11
11
|
var messages = {
|
|
12
12
|
noLeakedConditionalRendering: (p) => `Potential leaked value ${p.value} that might cause unintentionally rendered values or rendering crashes.`
|
|
13
13
|
};
|
|
@@ -63,61 +63,4 @@ var noLeakedConditionalRendering = defineRule(() => {
|
|
|
63
63
|
};
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
var rules = createRulesSet({
|
|
68
|
-
/**
|
|
69
|
-
* Prevents problematic leaked values from being rendered.
|
|
70
|
-
*
|
|
71
|
-
* Using the && operator to render some element conditionally in JSX can cause unexpected values being rendered, or even crashing the rendering.
|
|
72
|
-
*
|
|
73
|
-
* **Examples**
|
|
74
|
-
*
|
|
75
|
-
* ```tsx
|
|
76
|
-
* import React from "react";
|
|
77
|
-
*
|
|
78
|
-
* interface MyComponentProps {
|
|
79
|
-
* count: number;
|
|
80
|
-
* }
|
|
81
|
-
*
|
|
82
|
-
* function MyComponent({ count }: MyComponentProps) {
|
|
83
|
-
* return <div>{count && <span>There are {count} results</span>}</div>;
|
|
84
|
-
* // ^^^^^
|
|
85
|
-
* // - Potential leaked value 'count' that might cause unintentionally rendered values or rendering crashes.
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* ```tsx
|
|
90
|
-
* import React from "react";
|
|
91
|
-
*
|
|
92
|
-
* interface MyComponentProps {
|
|
93
|
-
* items: string[];
|
|
94
|
-
* }
|
|
95
|
-
*
|
|
96
|
-
* function MyComponent({ items }: MyComponentProps) {
|
|
97
|
-
* return <div>{items.length && <List items={items} />}</div>;
|
|
98
|
-
* // ^^^^^^^^^^^^
|
|
99
|
-
* // - Potential leaked value 'items.length' that might cause unintentionally rendered values or rendering crashes.
|
|
100
|
-
* }
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* ```tsx
|
|
104
|
-
* import React from "react";
|
|
105
|
-
*
|
|
106
|
-
* interface MyComponentProps {
|
|
107
|
-
* items: string[];
|
|
108
|
-
* }
|
|
109
|
-
*
|
|
110
|
-
* function MyComponent({ items }: MyComponentProps) {
|
|
111
|
-
* return <div>{items[0] && <List items={items} />}</div>;
|
|
112
|
-
* // ^^^^^^^^
|
|
113
|
-
* // - Potential leaked value 'items[0]' that might cause unintentionally rendered values or rendering crashes.
|
|
114
|
-
* }
|
|
115
|
-
* ```
|
|
116
|
-
*
|
|
117
|
-
* @since 0.0.0
|
|
118
|
-
*/
|
|
119
|
-
noLeakedConditionalRendering
|
|
120
|
-
// TODO: Port more rules from https://beta.eslint-react.xyz/docs/rules/overview
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
export { rules };
|
|
66
|
+
export { noLeakedConditionalRendering };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsl-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-next.0",
|
|
4
4
|
"description": "A unified plugin that combines all individual plugins from the react-analyzer monorepo into one.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -28,18 +28,18 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"compare-versions": "^6.1.1",
|
|
31
|
-
"@react-analyzer/
|
|
32
|
-
"@react-analyzer/
|
|
33
|
-
"@react-analyzer/
|
|
34
|
-
"@react-analyzer/
|
|
35
|
-
"@react-analyzer/kit": "0.0.
|
|
31
|
+
"@react-analyzer/core": "0.0.2-next.0",
|
|
32
|
+
"@react-analyzer/eff": "0.0.2-next.0",
|
|
33
|
+
"@react-analyzer/ast": "0.0.2-next.0",
|
|
34
|
+
"@react-analyzer/shared": "0.0.2-next.0",
|
|
35
|
+
"@react-analyzer/kit": "0.0.2-next.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"tsup": "^8.5.0",
|
|
39
39
|
"@local/configs": "0.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"tsl": "^1.0.
|
|
42
|
+
"tsl": "^1.0.20",
|
|
43
43
|
"typescript": "^4.9.5 || ^5.4.5"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsup --dts-resolve",
|
|
54
|
+
"build:docs": "typedoc",
|
|
54
55
|
"lint:publish": "pnpm publint",
|
|
55
56
|
"lint:ts": "tsl"
|
|
56
57
|
}
|
package/README.md
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# tsl-react
|
|
2
|
-
|
|
3
|
-
[](https://npmjs.com/package/tsl-react)
|
|
4
|
-
|
|
5
|
-
(WIP) Bring the same linting functionality that [`eslint-react.xyz`](https://eslint-react.xyz) has to the TypeScript LSP.
|
|
6
|
-
|
|
7
|
-
This package provides the rulesets from [`beta.eslint-react.xyz/docs/rules/overview`](https://beta.eslint-react.xyz/docs/rules/overview) as custom rules for the [ArnaudBarre/tsl](https://github.com/ArnaudBarre/tsl) linting tool.
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
pnpm add -D tsl tsl-react
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Then follow the [installation guide](https://github.com/ArnaudBarre/tsl?tab=readme-ov-file#installation) for tsl.
|
|
16
|
-
|
|
17
|
-
## Enabling rules
|
|
18
|
-
|
|
19
|
-
```diff
|
|
20
|
-
// tsl.config.ts
|
|
21
|
-
import { core, defineConfig } from "tsl";
|
|
22
|
-
+ import { rules as react } from "tsl-react";
|
|
23
|
-
|
|
24
|
-
export default defineConfig({
|
|
25
|
-
rules: [
|
|
26
|
-
...core.all(),
|
|
27
|
-
+ react.noLeakedConditionalRendering(),
|
|
28
|
-
],
|
|
29
|
-
});
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Specifying project-aware React configuration
|
|
33
|
-
|
|
34
|
-
In your `tsconfig.json` or `jsconfig.json` add the following:
|
|
35
|
-
|
|
36
|
-
```diff
|
|
37
|
-
{
|
|
38
|
-
"compilerOptions": {
|
|
39
|
-
+ "jsx": "react-jsx",
|
|
40
|
-
"plugins": [{ "name": "tsl/plugin" }],
|
|
41
|
-
},
|
|
42
|
-
+ "react": {
|
|
43
|
-
+ "version": "19.1.0" // or "detect" to automatically detect the version
|
|
44
|
-
+ // other options can be added here
|
|
45
|
-
+ }
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Status
|
|
50
|
-
|
|
51
|
-
This package is currently a work in progress. The rules are being developed and tested, and we welcome contributions from the community.
|
|
52
|
-
|
|
53
|
-
### Implemented Rules
|
|
54
|
-
|
|
55
|
-
- [x] `noLeakedConditionalRendering`: Prevents problematic leaked values from being rendered.
|
|
56
|
-
- [ ] ...
|
|
57
|
-
|
|
58
|
-
## License
|
|
59
|
-
|
|
60
|
-
This project is licensed under the [MIT License](./LICENSE).
|
|
61
|
-
|
|
62
|
-
## Acknowledgements
|
|
63
|
-
|
|
64
|
-
We extend our gratitude to:
|
|
65
|
-
|
|
66
|
-
- **[ArnaudBarre/tsl](https://github.com/ArnaudBarre/tsl)** for the core and AST type rewrite, which significantly streamlined custom rules development within TypeScript Language Service Plugin.
|
|
67
|
-
- **[johnsoncodehk/tsslint](https://github.com/johnsoncodehk/tsslint)** for their early explorations of exposing the TypeScript Language Server diagnostic interface.
|
|
68
|
-
- **[typescript-eslint/typescript-eslint](https://github.com/typescript-eslint/typescript-eslint)** for providing the foundation where these custom rules were initially developed and tested.
|
|
69
|
-
- **[Effect-TS/language-service](https://github.com/Effect-TS/language-service)** for inspiring the creation of [`typescriptreact-language-service`](https://github.com/react-analyzer/tsl/commit/01ab1d8d954d555bff65246c61af8c1028be78f1#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5) (now [`tsl-react`](https://github.com/react-analyzer/tsl)).
|