@tsrx/eslint-plugin 0.7.5 → 0.7.7

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 CHANGED
@@ -114,22 +114,101 @@ after `tsrx.configs.react`.
114
114
  on the same code in a plain function. The
115
115
  [`@tsrx/eslint-parser` README](https://github.com/tsrx-org/tsrx/tree/main/packages/eslint-parser#known-limitations)
116
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`.
117
194
 
118
195
  ### With `js.configs.recommended`
119
196
 
120
- `js.configs.recommended` turns on `no-unused-vars` and `no-unreachable`. The `js`
121
- configuration turns those two off for `.tsrx` files and turns on
122
- `tsrx/no-unused-vars` and `tsrx/no-unreachable` at `error`. Every other report and
123
- suggestion is the core rule's, except in the code `tsrx/no-unreachable` revives,
124
- where it follows exits itself: after a `@switch` arm that throws, the other arms
125
- and the code after the `@switch`, and after a `@try` block that throws, the
126
- `@try`'s other blocks and the code after it. A configuration can't read the
127
- severity or options another one gives the core rule, so:
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:
128
207
 
129
208
  - list `tsrx.configs.js` after `js.configs.recommended`, and after any other
130
209
  configuration that turns these core rules on. Listed before them, it leaves both
131
210
  versions on for `.tsrx` files, and each problem is reported twice;
132
- - on its own, without `js.configs.recommended`, it turns the two TSRX rules on;
211
+ - on its own, without `js.configs.recommended`, it turns the TSRX rules on;
133
212
  - give `tsrx/no-unused-vars` the options you give `no-unused-vars`, and set a
134
213
  `tsrx/` rule to `warn` or `off` to change its severity;
135
214
  - name the TSRX rule in `eslint-disable` comments in `.tsrx` files:
@@ -159,6 +238,27 @@ export default [
159
238
  ];
160
239
  ```
161
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
+
162
262
  Target runtime rules do not belong in the shared recommended configuration. For
163
263
  example, Ripple-specific `track()` placement and DOM event guidance should be
164
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
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";cAUM;;;;;;;;;;;;;;;EAeU"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";cAYM;;;;;;;;;;;;;;;;EAgBU"}