@tsrx/eslint-plugin 0.7.4 → 0.7.6
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/README.md +128 -19
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +490 -87
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +10 -1
package/README.md
CHANGED
|
@@ -94,33 +94,121 @@ after `tsrx.configs.react`.
|
|
|
94
94
|
- `tsrx/no-await-in-loop` is ESLint's `no-await-in-loop`, and also reports an
|
|
95
95
|
`await` in a `@for` key, which runs once per item, as the body does.
|
|
96
96
|
- `tsrx/no-unreachable` is ESLint's `no-unreachable`, with the arms of a `@switch`
|
|
97
|
-
as alternatives
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
`
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
97
|
+
as alternatives, and the blocks of a `@try` run apart from the code around it.
|
|
98
|
+
After an arm that throws, it doesn't report the other arms, or the code after
|
|
99
|
+
the `@switch` when another arm reaches its end or there is no `@default` arm.
|
|
100
|
+
After a `@try` block that throws, it doesn't report `@pending`, the `@catch` or
|
|
101
|
+
the code after the `@try`: the compiled output runs the body, `@pending` and
|
|
102
|
+
`@catch` in callbacks of the `@try`'s boundaries, and the component goes on past
|
|
103
|
+
the `@try`. A body or `@pending` that awaits or yields runs in the component
|
|
104
|
+
instead, `@pending` first, where a throw leaves it: when such a block doesn't
|
|
105
|
+
reach its end, the rule reports the `@catch` and the code after the `@try`, as
|
|
106
|
+
the core rule does. On Hono, a `@pending` that neither awaits nor yields runs in
|
|
107
|
+
the component too, so when it throws it ends the component there, but the rule
|
|
108
|
+
doesn't know the target and doesn't report the code after that `@try`. It still
|
|
109
|
+
reports unreachable code inside an arm or a block of a `@try`: there it follows
|
|
110
|
+
`throw`, `return`, `break`, `continue`, `try` and endless loops itself, since
|
|
111
|
+
code path analysis has already given up on that code. It can miss unreachable
|
|
112
|
+
code there when a `break`, `continue`, `return` or `throw` passes through a
|
|
113
|
+
`finally` block, and it reports nothing there that the core rule doesn't report
|
|
114
|
+
on the same code in a plain function. The
|
|
107
115
|
[`@tsrx/eslint-parser` README](https://github.com/tsrx-org/tsrx/tree/main/packages/eslint-parser#known-limitations)
|
|
108
|
-
explains.
|
|
116
|
+
explains what the core rule reports instead.
|
|
117
|
+
- `tsrx/no-useless-assignment` is ESLint's `no-useless-assignment`, with the
|
|
118
|
+
blocks of a `@try` as alternatives. The core rule runs them one after another,
|
|
119
|
+
so it reports a value set before a `@try` and assigned in the body though
|
|
120
|
+
`@pending` or the `@catch` reads it, and a value the body assigns and the
|
|
121
|
+
`@catch` assigns again, which the code after the `@try` reads when the `@catch`
|
|
122
|
+
doesn't render. The compiled output runs the blocks in callbacks of the `@try`'s
|
|
123
|
+
boundaries, and the `@catch` or `@pending` can render without the blocks before
|
|
124
|
+
them. The rule also runs the core rule on code paths cut at the blocks'
|
|
125
|
+
boundaries, once as they are and once with each block, and the code after the
|
|
126
|
+
`@try`, also starting from the start of the `@try` or from the end of any block
|
|
127
|
+
before it. It drops a report of the core rule only when the cut code paths give
|
|
128
|
+
it and the ones with the added starts don't, so it reports nothing the core rule
|
|
129
|
+
doesn't, and in a file without `@try` it is the core rule.
|
|
130
|
+
|
|
131
|
+
It can still drop a report that holds:
|
|
132
|
+
|
|
133
|
+
- The added starts mix two orders. On React, Preact and Hono, the code after a
|
|
134
|
+
`@try` runs first and the blocks render later; on Solid and Vue, the blocks
|
|
135
|
+
run in source order, and an element's attributes are set after its children.
|
|
136
|
+
The rule lets a block's value reach the code after the `@try` as in source
|
|
137
|
+
order, while code path analysis runs the rest as React does, so it can drop a
|
|
138
|
+
report that holds on every target, when no single order reads the value:
|
|
139
|
+
- across two `@try`s on one path, siblings or one inside another's block. With
|
|
140
|
+
`@try { status = 'a'; <b /> } @catch (e) { <i /> }`, then the same with
|
|
141
|
+
`status = 'b'`, then `<p>{status}</p>`, the value `'a'` is never read, and
|
|
142
|
+
the rule doesn't report it;
|
|
143
|
+
- with one `@try`, when the body assigns a value before anything that can
|
|
144
|
+
throw, the `@catch` reads it, and either the code after the `@try` assigns
|
|
145
|
+
it again on every path or nothing renders the `@try`, as when it is an
|
|
146
|
+
operand of `,` that isn't the last, or a value no output uses. With
|
|
147
|
+
`let x = 'init';`, then
|
|
148
|
+
`@try { x = 'body'; <Boom /> } @catch (e) { <i>{x}</i> }`, then an `@if`
|
|
149
|
+
whose arms both assign `x`, `'init'` is never read, and the rule doesn't
|
|
150
|
+
report it;
|
|
151
|
+
- when an element after the `@try` reads the value in an attribute and assigns
|
|
152
|
+
it in its children, as `<p title={String(x)}>{(x = 3, null)}</p>` does:
|
|
153
|
+
Solid and Vue set the attribute after the children, and React, Preact and
|
|
154
|
+
Hono read it before the blocks run.
|
|
155
|
+
- On Hono, a `@pending` that neither awaits nor yields runs in the component,
|
|
156
|
+
before the body and the code after the `@try`. The rule doesn't know the
|
|
157
|
+
target, so it can drop the report of a value such a `@pending` overwrites.
|
|
158
|
+
- Like the core rule, it counts a read in a branch that can never run, such as
|
|
159
|
+
`@if (false) { … }`, and a `typeof x` in a type, and doesn't see a write in a
|
|
160
|
+
function the code calls or the assignment to the target of a `for…of` or
|
|
161
|
+
`for…in` without `let` or `const`. So such a read after a `@try` can drop the
|
|
162
|
+
report of a value the `@catch` overwrites, though the read can't run or the
|
|
163
|
+
value is overwritten again first.
|
|
164
|
+
|
|
165
|
+
It keeps the core rule's reports, adding no starts, for a `@try`:
|
|
166
|
+
|
|
167
|
+
- whose body or `@pending` awaits or yields, since those blocks run in the
|
|
168
|
+
component, in order;
|
|
169
|
+
- where code path analysis follows more than one path at once, as in a `finally`
|
|
170
|
+
block that a `throw` or a `return` can enter;
|
|
171
|
+
- in a `@switch` arm before the last, or in the last arm when an earlier arm
|
|
172
|
+
assigns anything, since code path analysis runs the arms one after another but
|
|
173
|
+
only one renders; and likewise in the body of a `@for` with `@empty`, or in
|
|
174
|
+
`@empty` when the loop assigns anything, since `@empty` renders only when the
|
|
175
|
+
body doesn't;
|
|
176
|
+
- anywhere but statements, template children, the blocks of `@if`, `@for` and
|
|
177
|
+
`@try`, and the parts of an expression the rule lists as running in order
|
|
178
|
+
(call arguments, array elements, property values, the branches of `?:`, `&&`
|
|
179
|
+
and `??`, and a few more). That leaves out attribute values, which every
|
|
180
|
+
target runs after the element's children, and a component runs whenever it
|
|
181
|
+
reads its prop; a `@for`'s index and key and a destructuring default, which
|
|
182
|
+
code path analysis runs out of order; and others, such as the operand of `!`;
|
|
183
|
+
- whose code path has a part that code path analysis runs before the `@try`'s
|
|
184
|
+
part though it really runs after it, and that part assigns something, as a
|
|
185
|
+
computed key `[x = 3]` in a destructuring target or `key (i, x = 3)` on a
|
|
186
|
+
`@for` does. The same goes for a `@try` in the iterable of a `for…of` or
|
|
187
|
+
`for…in` loop whose target isn't a new `let` or `const` binding.
|
|
188
|
+
|
|
189
|
+
It also still reports a value read only in a block that code path analysis holds
|
|
190
|
+
unreachable, such as a `@catch` after a body that throws, or only in a block
|
|
191
|
+
that runs again after a later one, as the body does after `@pending` or after
|
|
192
|
+
`reset()`. When a block always ends in a `throw`, what follows it is unreachable
|
|
193
|
+
for code path analysis, and the rule adds no starts for that `@try`.
|
|
109
194
|
|
|
110
195
|
### With `js.configs.recommended`
|
|
111
196
|
|
|
112
|
-
`js.configs.recommended` turns on `no-unused-vars` and `no-unreachable
|
|
113
|
-
|
|
114
|
-
`tsrx/no-unused-vars` and `tsrx/no-unreachable` at
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
`@
|
|
118
|
-
|
|
197
|
+
`js.configs.recommended` turns on `no-unused-vars` and `no-unreachable`, and on
|
|
198
|
+
ESLint 10 also `no-useless-assignment`. The `js` configuration turns those off for
|
|
199
|
+
`.tsrx` files and turns on `tsrx/no-unused-vars` and `tsrx/no-unreachable` at
|
|
200
|
+
`error`, and on ESLint 10 `tsrx/no-useless-assignment`. Every other report and
|
|
201
|
+
suggestion is the core rule's, except what `tsrx/no-useless-assignment` drops
|
|
202
|
+
after a `@try`, and except in the code `tsrx/no-unreachable` revives, where it
|
|
203
|
+
follows exits itself: after a `@switch` arm that throws, the other arms and the
|
|
204
|
+
code after the `@switch`, and after a `@try` block that throws, the `@try`'s other
|
|
205
|
+
blocks and the code after it. A configuration can't read the severity or options
|
|
206
|
+
another one gives the core rule, so:
|
|
119
207
|
|
|
120
208
|
- list `tsrx.configs.js` after `js.configs.recommended`, and after any other
|
|
121
209
|
configuration that turns these core rules on. Listed before them, it leaves both
|
|
122
210
|
versions on for `.tsrx` files, and each problem is reported twice;
|
|
123
|
-
- on its own, without `js.configs.recommended`, it turns the
|
|
211
|
+
- on its own, without `js.configs.recommended`, it turns the TSRX rules on;
|
|
124
212
|
- give `tsrx/no-unused-vars` the options you give `no-unused-vars`, and set a
|
|
125
213
|
`tsrx/` rule to `warn` or `off` to change its severity;
|
|
126
214
|
- name the TSRX rule in `eslint-disable` comments in `.tsrx` files:
|
|
@@ -150,6 +238,27 @@ export default [
|
|
|
150
238
|
];
|
|
151
239
|
```
|
|
152
240
|
|
|
241
|
+
On ESLint 9, `js.configs.recommended` leaves `no-useless-assignment` off, so the
|
|
242
|
+
`js` configuration doesn't turn on `tsrx/no-useless-assignment` there. If you turn
|
|
243
|
+
on `no-useless-assignment`, use `tsrx/no-useless-assignment` for `.tsrx` files
|
|
244
|
+
instead:
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
export default [
|
|
248
|
+
js.configs.recommended,
|
|
249
|
+
...tsrx.configs.recommended,
|
|
250
|
+
...tsrx.configs.js,
|
|
251
|
+
{ rules: { 'no-useless-assignment': 'error' } },
|
|
252
|
+
{
|
|
253
|
+
files: ['**/*.tsrx'],
|
|
254
|
+
rules: {
|
|
255
|
+
'no-useless-assignment': 'off',
|
|
256
|
+
'tsrx/no-useless-assignment': 'error',
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
];
|
|
260
|
+
```
|
|
261
|
+
|
|
153
262
|
Target runtime rules do not belong in the shared recommended configuration. For
|
|
154
263
|
example, Ripple-specific `track()` placement and DOM event guidance should be
|
|
155
264
|
provided by Ripple-owned tooling rather than applied to every TSRX target.
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare const plugin: {
|
|
|
13
13
|
'no-unused-vars': import("eslint").Rule.RuleModule;
|
|
14
14
|
'no-await-in-loop': import("eslint").Rule.RuleModule;
|
|
15
15
|
'no-unreachable': import("eslint").Rule.RuleModule;
|
|
16
|
+
'no-useless-assignment': import("eslint").Rule.RuleModule;
|
|
16
17
|
};
|
|
17
18
|
configs: any;
|
|
18
19
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";cAYM;;;;;;;;;;;;;;;;EAgBU"}
|