tsl-react 0.0.1-next.1 → 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 CHANGED
@@ -1,58 +1,56 @@
1
- import * as tsl from 'tsl';
1
+ import { Rule } from 'tsl';
2
2
 
3
- declare const rules: tsl.RulesSet<{
4
- /**
5
- * Prevents problematic leaked values from being rendered.
6
- *
7
- * Using the && operator to render some element conditionally in JSX can cause unexpected values being rendered, or even crashing the rendering.
8
- *
9
- * **Examples**
10
- *
11
- * ```tsx
12
- * import React from "react";
13
- *
14
- * interface MyComponentProps {
15
- * count: number;
16
- * }
17
- *
18
- * function MyComponent({ count }: MyComponentProps) {
19
- * return <div>{count && <span>There are {count} results</span>}</div>;
20
- * // ^^^^^
21
- * // - Potential leaked value 'count' that might cause unintentionally rendered values or rendering crashes.
22
- * }
23
- * ```
24
- *
25
- * ```tsx
26
- * import React from "react";
27
- *
28
- * interface MyComponentProps {
29
- * items: string[];
30
- * }
31
- *
32
- * function MyComponent({ items }: MyComponentProps) {
33
- * return <div>{items.length && <List items={items} />}</div>;
34
- * // ^^^^^^^^^^^^
35
- * // - Potential leaked value 'items.length' that might cause unintentionally rendered values or rendering crashes.
36
- * }
37
- * ```
38
- *
39
- * ```tsx
40
- * import React from "react";
41
- *
42
- * interface MyComponentProps {
43
- * items: string[];
44
- * }
45
- *
46
- * function MyComponent({ items }: MyComponentProps) {
47
- * return <div>{items[0] && <List items={items} />}</div>;
48
- * // ^^^^^^^^
49
- * // - Potential leaked value 'items[0]' that might cause unintentionally rendered values or rendering crashes.
50
- * }
51
- * ```
52
- *
53
- * @since 0.0.0
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 { rules };
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/index.ts
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
- // src/index.ts
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.1-next.1",
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,11 +28,11 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "compare-versions": "^6.1.1",
31
- "@react-analyzer/ast": "0.0.1-next.1",
32
- "@react-analyzer/shared": "0.0.1-next.1",
33
- "@react-analyzer/core": "0.0.1-next.1",
34
- "@react-analyzer/kit": "0.0.1-next.1",
35
- "@react-analyzer/eff": "0.0.1-next.1"
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",
@@ -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,67 +0,0 @@
1
- # tsl-react
2
-
3
- [![Version](https://img.shields.io/npm/v/tsl-react?style=flat&colorA=000000&colorB=000000)](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
- ### Implemented Rules
52
-
53
- - [x] `noLeakedConditionalRendering`: Prevents problematic leaked values from being rendered.
54
- - [ ] ...
55
-
56
- ## License
57
-
58
- This project is licensed under the [MIT License](./LICENSE).
59
-
60
- ## Acknowledgements
61
-
62
- We extend our gratitude to:
63
-
64
- - **[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.
65
- - **[johnsoncodehk/tsslint](https://github.com/johnsoncodehk/tsslint)** for their early explorations of exposing the TypeScript Language Server diagnostic interface.
66
- - **[typescript-eslint/typescript-eslint](https://github.com/typescript-eslint/typescript-eslint)** for providing the foundation where these custom rules were initially developed and tested.
67
- - **[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)).