@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/dist/index.js CHANGED
@@ -1,7 +1,52 @@
1
1
  import { createRequire } from "module";
2
2
  import { builtinRules } from "eslint/use-at-your-own-risk";
3
+ //#region src/utils/core-rule.ts
4
+ /**
5
+ * An ESLint core rule, for a TSRX rule that wraps it.
6
+ */
7
+ function get_core_rule(name) {
8
+ const rule = builtinRules.get(name);
9
+ if (!rule) throw new Error(`ESLint has no core rule named '${name}'.`);
10
+ return rule;
11
+ }
12
+ /**
13
+ * The core rule's meta, with the TSRX rule's description. No wrapper is in the
14
+ * `recommended` configuration: `tsrx.configs.js` swaps them in.
15
+ */
16
+ function wrapper_meta(core, description) {
17
+ return {
18
+ ...core.meta,
19
+ docs: {
20
+ ...core.meta?.docs,
21
+ description,
22
+ recommended: false
23
+ }
24
+ };
25
+ }
26
+ /**
27
+ * The rule context, with its `report` replaced.
28
+ */
29
+ function with_report(context, report) {
30
+ return Object.create(context, { report: { value: report } });
31
+ }
32
+ /**
33
+ * Both rules' listeners, the first's running first where both listen to an
34
+ * event.
35
+ */
36
+ function merge_listeners(first, second) {
37
+ const merged = { ...first };
38
+ for (const [key, listener] of Object.entries(second)) {
39
+ const existing = first[key];
40
+ merged[key] = existing ? (...args) => {
41
+ existing(...args);
42
+ listener(...args);
43
+ } : listener;
44
+ }
45
+ return merged;
46
+ }
47
+ //#endregion
3
48
  //#region src/rules/no-return-in-component.ts
4
- const rule$7 = {
49
+ const rule$8 = {
5
50
  meta: {
6
51
  type: "problem",
7
52
  docs: {
@@ -64,7 +109,7 @@ const NESTED_BOUNDARY_TYPES = /* @__PURE__ */ new Set([
64
109
  "MethodDefinition",
65
110
  "PropertyDefinition"
66
111
  ]);
67
- const rule$6 = {
112
+ const rule$7 = {
68
113
  meta: {
69
114
  type: "problem",
70
115
  docs: {
@@ -131,7 +176,7 @@ const rule$6 = {
131
176
  };
132
177
  //#endregion
133
178
  //#region src/rules/valid-for-of-key.ts
134
- const rule$5 = {
179
+ const rule$6 = {
135
180
  meta: {
136
181
  type: "problem",
137
182
  docs: {
@@ -205,7 +250,7 @@ function get_forgotten_output_statement(node) {
205
250
  for (const statement of statements.slice(target_index + 1)) if (!is_ignored_statement(statement)) return null;
206
251
  return target;
207
252
  }
208
- const rule$4 = {
253
+ const rule$5 = {
209
254
  meta: {
210
255
  type: "problem",
211
256
  docs: { description: "Require @{...} for TSRX component bodies with setup and template output." },
@@ -552,7 +597,7 @@ function find_element(node, start) {
552
597
  }
553
598
  return null;
554
599
  }
555
- const rule$3 = {
600
+ const rule$4 = {
556
601
  meta: {
557
602
  type: "suggestion",
558
603
  docs: { description: "Disallow unnecessary JSX expressions when literals alone are sufficient or enforce JSX expressions on literals in JSX children or attributes, without unwrapping text that TSRX reads as syntax" },
@@ -687,61 +732,16 @@ const rule$3 = {
687
732
  }
688
733
  };
689
734
  //#endregion
690
- //#region src/utils/core-rule.ts
691
- /**
692
- * An ESLint core rule, for a TSRX rule that wraps it.
693
- */
694
- function get_core_rule(name) {
695
- const rule = builtinRules.get(name);
696
- if (!rule) throw new Error(`ESLint has no core rule named '${name}'.`);
697
- return rule;
698
- }
699
- /**
700
- * The core rule's meta, with the TSRX rule's description. No wrapper is in the
701
- * `recommended` configuration: `tsrx.configs.js` swaps them in.
702
- */
703
- function wrapper_meta(core, description) {
704
- return {
705
- ...core.meta,
706
- docs: {
707
- ...core.meta?.docs,
708
- description,
709
- recommended: false
710
- }
711
- };
712
- }
713
- /**
714
- * The rule context, with its `report` replaced.
715
- */
716
- function with_report(context, report) {
717
- return Object.create(context, { report: { value: report } });
718
- }
719
- /**
720
- * Both rules' listeners, the first's running first where both listen to an
721
- * event.
722
- */
723
- function merge_listeners(first, second) {
724
- const merged = { ...first };
725
- for (const [key, listener] of Object.entries(second)) {
726
- const existing = first[key];
727
- merged[key] = existing ? (...args) => {
728
- existing(...args);
729
- listener(...args);
730
- } : listener;
731
- }
732
- return merged;
733
- }
734
- //#endregion
735
735
  //#region src/rules/no-unused-vars.ts
736
- const core$2 = get_core_rule("no-unused-vars");
736
+ const core$3 = get_core_rule("no-unused-vars");
737
737
  /**
738
738
  * Core `no-unused-vars`. Its suggestion for an unused `@for` index deleted
739
739
  * only the name, which left `index )`: here it deletes the `; index i` clause.
740
740
  */
741
- const rule$2 = {
742
- meta: wrapper_meta(core$2, "Disallow unused variables, with a suggestion that removes an unused `@for` index clause"),
741
+ const rule$3 = {
742
+ meta: wrapper_meta(core$3, "Disallow unused variables, with a suggestion that removes an unused `@for` index clause"),
743
743
  create(context) {
744
- return core$2.create(with_report(context, (descriptor) => {
744
+ return core$3.create(with_report(context, (descriptor) => {
745
745
  const node = descriptor.node;
746
746
  const parent = node?.parent;
747
747
  if (!node || parent?.type !== "JSXForExpression" || parent.index !== node) {
@@ -769,8 +769,8 @@ function remove_index_clause(source_code, fixer, index) {
769
769
  }
770
770
  //#endregion
771
771
  //#region src/rules/no-await-in-loop.ts
772
- const core$1 = get_core_rule("no-await-in-loop");
773
- const FUNCTION_TYPES$1 = /* @__PURE__ */ new Set([
772
+ const core$2 = get_core_rule("no-await-in-loop");
773
+ const FUNCTION_TYPES$2 = /* @__PURE__ */ new Set([
774
774
  "FunctionDeclaration",
775
775
  "FunctionExpression",
776
776
  "ArrowFunctionExpression"
@@ -779,11 +779,11 @@ const FUNCTION_TYPES$1 = /* @__PURE__ */ new Set([
779
779
  * Core `no-await-in-loop`, which also reports an `await` in a `@for` key: the
780
780
  * key runs once per item, as the body does.
781
781
  */
782
- const rule$1 = {
783
- meta: wrapper_meta(core$1, "Disallow `await` inside of loops, including the key of a `@for` loop"),
782
+ const rule$2 = {
783
+ meta: wrapper_meta(core$2, "Disallow `await` inside of loops, including the key of a `@for` loop"),
784
784
  create(context) {
785
785
  const reported = /* @__PURE__ */ new Set();
786
- return merge_listeners(core$1.create(with_report(context, (descriptor) => {
786
+ return merge_listeners(core$2.create(with_report(context, (descriptor) => {
787
787
  reported.add(descriptor.node);
788
788
  context.report(descriptor);
789
789
  })), { AwaitExpression(node) {
@@ -795,12 +795,36 @@ const rule$1 = {
795
795
  }
796
796
  };
797
797
  function is_in_for_key(node) {
798
- for (let child = node, parent = node.parent; parent && !FUNCTION_TYPES$1.has(parent.type); child = parent, parent = parent.parent) if (parent.type === "JSXForExpression" && parent.key === child) return true;
798
+ for (let child = node, parent = node.parent; parent && !FUNCTION_TYPES$2.has(parent.type); child = parent, parent = parent.parent) if (parent.type === "JSXForExpression" && parent.key === child) return true;
799
799
  return false;
800
800
  }
801
801
  //#endregion
802
+ //#region src/utils/try-blocks.ts
803
+ const FUNCTION_TYPES$1 = /* @__PURE__ */ new Set([
804
+ "FunctionDeclaration",
805
+ "FunctionExpression",
806
+ "ArrowFunctionExpression"
807
+ ]);
808
+ /**
809
+ * Whether code awaits or yields outside a function, as the compiler checks a
810
+ * `@try` body and `@pending`: a block that does runs inline in the function
811
+ * that holds the `@try`, instead of in a callback of the `@try`'s boundaries.
812
+ */
813
+ function suspension_check(context) {
814
+ const visitor_keys = context.sourceCode.visitorKeys;
815
+ const suspends = (node) => {
816
+ if (!node || typeof node.type !== "string" || FUNCTION_TYPES$1.has(node.type)) return false;
817
+ if (node.type === "AwaitExpression" || node.type === "YieldExpression" || node.type === "ForOfStatement" && node.await || node.type === "VariableDeclaration" && node.kind === "await using") return true;
818
+ return (visitor_keys[node.type] ?? Object.keys(node).filter((key) => key !== "parent" && key !== "leadingComments" && key !== "trailingComments" && !key.startsWith("_"))).some((key) => {
819
+ const value = node[key];
820
+ return Array.isArray(value) ? value.some(suspends) : suspends(value);
821
+ });
822
+ };
823
+ return suspends;
824
+ }
825
+ //#endregion
802
826
  //#region src/rules/no-unreachable.ts
803
- const core = get_core_rule("no-unreachable");
827
+ const core$1 = get_core_rule("no-unreachable");
804
828
  const FUNCTION_TYPES = /* @__PURE__ */ new Set([
805
829
  "FunctionDeclaration",
806
830
  "FunctionExpression",
@@ -848,10 +872,10 @@ const THROWING_TYPES = [
848
872
  * `break`, `continue`, `try` and endless loops itself. Elsewhere, every answer
849
873
  * is the core rule's.
850
874
  */
851
- const rule = {
852
- meta: wrapper_meta(core, "Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements, with the arms of a `@switch` as alternatives, and the blocks of a `@try` run apart from the code around it"),
875
+ const rule$1 = {
876
+ meta: wrapper_meta(core$1, "Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements, with the arms of a `@switch` as alternatives, and the blocks of a `@try` run apart from the code around it"),
853
877
  create(context) {
854
- const listeners = core.create(context);
878
+ const listeners = core$1.create(context);
855
879
  const revived = /* @__PURE__ */ new WeakSet();
856
880
  const exited = /* @__PURE__ */ new WeakSet();
857
881
  const answers = /* @__PURE__ */ new Map();
@@ -904,15 +928,7 @@ const rule = {
904
928
  state.pending_first = at === "pending" && !body_ends;
905
929
  }
906
930
  };
907
- const visitor_keys = context.sourceCode.visitorKeys;
908
- const suspends = (node) => {
909
- if (!node || typeof node.type !== "string" || FUNCTION_TYPES.has(node.type)) return false;
910
- if (node.type === "AwaitExpression" || node.type === "YieldExpression" || node.type === "ForOfStatement" && node.await || node.type === "VariableDeclaration" && node.kind === "await using") return true;
911
- return (visitor_keys[node.type] ?? Object.keys(node).filter((key) => key !== "parent" && key !== "leadingComments" && key !== "trailingComments" && !key.startsWith("_"))).some((key) => {
912
- const value = node[key];
913
- return Array.isArray(value) ? value.some(suspends) : suspends(value);
914
- });
915
- };
931
+ const suspends = suspension_check(context);
916
932
  const proxy = (segment) => {
917
933
  let result = proxies.get(segment);
918
934
  if (!result) {
@@ -1129,6 +1145,149 @@ function is_endless(node) {
1129
1145
  return (node.type === "WhileStatement" || node.type === "DoWhileStatement" || node.type === "ForStatement") && node.test.type === "Literal" && Boolean(node.test.value);
1130
1146
  }
1131
1147
  //#endregion
1148
+ //#region src/rules/no-useless-assignment.ts
1149
+ const core = get_core_rule("no-useless-assignment");
1150
+ /** Nodes whose code starts a code path of its own. */
1151
+ const CODE_PATH_STARTS = /* @__PURE__ */ new Set([
1152
+ "FunctionDeclaration",
1153
+ "FunctionExpression",
1154
+ "ArrowFunctionExpression",
1155
+ "StaticBlock"
1156
+ ]);
1157
+ /**
1158
+ * The parts of each node that run in the order code path analysis follows,
1159
+ * and only in that order, so that the code it runs after a `@try` in one of
1160
+ * them can really run after it.
1161
+ */
1162
+ const ORDERED_PARTS = {
1163
+ Program: ["body"],
1164
+ BlockStatement: ["body"],
1165
+ ExpressionStatement: ["expression"],
1166
+ ReturnStatement: ["argument"],
1167
+ VariableDeclaration: ["declarations"],
1168
+ VariableDeclarator: ["init"],
1169
+ ExportNamedDeclaration: ["declaration"],
1170
+ ExportDefaultDeclaration: ["declaration"],
1171
+ IfStatement: ["consequent", "alternate"],
1172
+ LabeledStatement: ["body"],
1173
+ TryStatement: [
1174
+ "block",
1175
+ "handler",
1176
+ "finalizer"
1177
+ ],
1178
+ CatchClause: ["body"],
1179
+ WhileStatement: ["body"],
1180
+ DoWhileStatement: ["body"],
1181
+ ForStatement: ["init", "body"],
1182
+ ForInStatement: ["right", "body"],
1183
+ ForOfStatement: ["right", "body"],
1184
+ AssignmentExpression: ["right"],
1185
+ CallExpression: ["arguments"],
1186
+ NewExpression: ["arguments"],
1187
+ ChainExpression: ["expression"],
1188
+ ArrayExpression: ["elements"],
1189
+ ObjectExpression: ["properties"],
1190
+ Property: ["value"],
1191
+ SpreadElement: ["argument"],
1192
+ ConditionalExpression: ["consequent", "alternate"],
1193
+ LogicalExpression: ["left", "right"],
1194
+ SequenceExpression: ["expressions"],
1195
+ TemplateLiteral: ["expressions"],
1196
+ TaggedTemplateExpression: ["quasi"],
1197
+ AwaitExpression: ["argument"],
1198
+ YieldExpression: ["argument"],
1199
+ TSAsExpression: ["expression"],
1200
+ TSSatisfiesExpression: ["expression"],
1201
+ TSNonNullExpression: ["expression"],
1202
+ JSXElement: ["children"],
1203
+ JSXFragment: ["children"],
1204
+ JSXExpressionContainer: ["expression"],
1205
+ JSXAttribute: ["value"],
1206
+ JSXSpreadAttribute: ["argument"],
1207
+ JSXCodeBlock: ["body", "render"],
1208
+ JSXIfExpression: ["statement"],
1209
+ JSXTryExpression: [
1210
+ "block",
1211
+ "pending",
1212
+ "handler"
1213
+ ],
1214
+ JSXSwitchCase: ["consequent"]
1215
+ };
1216
+ const NOT_CHILDREN = /* @__PURE__ */ new Set([
1217
+ "parent",
1218
+ "metadata",
1219
+ "loc",
1220
+ "range",
1221
+ "leadingComments",
1222
+ "trailingComments",
1223
+ "innerComments"
1224
+ ]);
1225
+ const FUNCTIONS = /* @__PURE__ */ new Set([
1226
+ "FunctionDeclaration",
1227
+ "FunctionExpression",
1228
+ "ArrowFunctionExpression"
1229
+ ]);
1230
+ /**
1231
+ * Whether a node, outside the functions in it, assigns or updates anything. A
1232
+ * class's static block and field values count, since they run with it or
1233
+ * later.
1234
+ */
1235
+ function writes(node) {
1236
+ if (!node || typeof node.type !== "string" || FUNCTIONS.has(node.type)) return false;
1237
+ if (node.type === "AssignmentExpression" || node.type === "UpdateExpression") return true;
1238
+ return Object.entries(node).some(([key, value]) => !NOT_CHILDREN.has(key) && (Array.isArray(value) ? value.some(writes) : writes(value)));
1239
+ }
1240
+ /**
1241
+ * Whether a part of a node that code path analysis runs before the child,
1242
+ * though it really runs after it, assigns something: a destructuring target
1243
+ * runs after its value, and a `@for`'s index and key after the iterable and
1244
+ * around the body. Code path analysis runs a `for…in` or `for…of` target
1245
+ * after the iterable, but the core rule doesn't see the loop assign it, so a
1246
+ * target that isn't a new `let` or `const` binding counts.
1247
+ */
1248
+ function writes_late(parent, child) {
1249
+ switch (parent.type) {
1250
+ case "VariableDeclarator": return child === parent.init && writes(parent.id);
1251
+ case "AssignmentExpression": return child === parent.right && writes(parent.left);
1252
+ case "ForInStatement":
1253
+ case "ForOfStatement": return child === parent.right && (parent.left.type !== "VariableDeclaration" || parent.left.kind === "var");
1254
+ case "JSXForExpression": return child === parent.loop && (writes(parent.index) || writes(parent.key));
1255
+ default: return false;
1256
+ }
1257
+ }
1258
+ /**
1259
+ * Whether the code that code path analysis runs before and after a node, in
1260
+ * its code path, really runs before and after it. Code path analysis runs
1261
+ * the `@switch` arms one after another, but only one renders, so the code
1262
+ * after an arm before the last doesn't follow it, and an earlier arm that
1263
+ * assigns doesn't come before the last. Likewise `@empty` renders only when
1264
+ * the loop's body doesn't, so the body doesn't follow it when there is an
1265
+ * `@empty`, and a loop that assigns doesn't come before `@empty`. A `@for`'s
1266
+ * index and key run before the loop for code path analysis, but after the
1267
+ * iterable, and a destructuring default before the value it defaults. Nor
1268
+ * does it hold when code path analysis runs an assignment before the node
1269
+ * that really runs after it, as in a computed key of a destructuring target.
1270
+ */
1271
+ function runs_in_order(node) {
1272
+ for (let previous = void 0, child = node, parent = node.parent; parent; previous = child, child = parent, parent = parent.parent) {
1273
+ if (CODE_PATH_STARTS.has(parent.type) || parent.type === "PropertyDefinition" && parent.value === child) return true;
1274
+ if (writes_late(parent, child)) return false;
1275
+ if (parent.type === "JSXForExpression") {
1276
+ if (child === parent.loop) {
1277
+ if (parent.empty && previous === child.body) return false;
1278
+ } else if (child !== parent.empty || [
1279
+ parent.index,
1280
+ parent.key,
1281
+ parent.loop.left,
1282
+ parent.loop.body
1283
+ ].some(writes)) return false;
1284
+ } else if (parent.type === "JSXSwitchExpression") {
1285
+ if (parent.cases.at(-1) !== child || parent.cases.slice(0, -1).some(writes)) return false;
1286
+ } else if (!ORDERED_PARTS[parent.type]?.some((part) => Array.isArray(parent[part]) ? parent[part].includes(child) : parent[part] === child)) return false;
1287
+ }
1288
+ return true;
1289
+ }
1290
+ //#endregion
1132
1291
  //#region src/index.ts
1133
1292
  const plugin = {
1134
1293
  meta: {
@@ -1136,14 +1295,202 @@ const plugin = {
1136
1295
  version: "0.1.3"
1137
1296
  },
1138
1297
  rules: {
1139
- "no-return-in-component": rule$7,
1140
- "control-flow-jsx": rule$6,
1141
- "valid-for-of-key": rule$5,
1142
- "require-statement-container-body": rule$4,
1143
- "jsx-curly-brace-presence": rule$3,
1144
- "no-unused-vars": rule$2,
1145
- "no-await-in-loop": rule$1,
1146
- "no-unreachable": rule
1298
+ "no-return-in-component": rule$8,
1299
+ "control-flow-jsx": rule$7,
1300
+ "valid-for-of-key": rule$6,
1301
+ "require-statement-container-body": rule$5,
1302
+ "jsx-curly-brace-presence": rule$4,
1303
+ "no-unused-vars": rule$3,
1304
+ "no-await-in-loop": rule$2,
1305
+ "no-unreachable": rule$1,
1306
+ "no-useless-assignment": {
1307
+ meta: wrapper_meta(core, "Disallow variable assignments when the value is not used, with the blocks of a `@try` as alternatives"),
1308
+ create(context) {
1309
+ if (!context.sourceCode.text.includes("@try")) return core.create(context);
1310
+ const candidates = [];
1311
+ const cut_reports = /* @__PURE__ */ new Set();
1312
+ const joined_reports = /* @__PURE__ */ new Set();
1313
+ const node_of = (descriptor) => descriptor.node;
1314
+ const plain = core.create(with_report(context, (descriptor) => candidates.push(descriptor)));
1315
+ const cut = core.create(with_report(context, (descriptor) => cut_reports.add(node_of(descriptor))));
1316
+ const joined = core.create(with_report(context, (descriptor) => joined_reports.add(node_of(descriptor))));
1317
+ const suspends = suspension_check(context);
1318
+ const pieces = /* @__PURE__ */ new Map();
1319
+ const alternatives = /* @__PURE__ */ new Map();
1320
+ const outer_segments = [];
1321
+ let current = /* @__PURE__ */ new Set();
1322
+ const outer_positions = [];
1323
+ let position = {
1324
+ end: -1,
1325
+ for_heads: 0
1326
+ };
1327
+ const start_loop = (node) => {
1328
+ if (node.parent?.type === "JSXForExpression" && node.parent.loop === node) position.for_heads--;
1329
+ };
1330
+ const tries = /* @__PURE__ */ new Map();
1331
+ const view = (with_edges) => {
1332
+ const objects = /* @__PURE__ */ new Map();
1333
+ const get = (piece) => {
1334
+ let object = objects.get(piece);
1335
+ if (!object) {
1336
+ object = Object.create(piece.segment, {
1337
+ id: { value: `${piece.segment.id}~${piece.index}` },
1338
+ nextSegments: { get() {
1339
+ const list = pieces.get(piece.segment);
1340
+ const next = piece.index < list.length - 1 ? [list[piece.index + 1]] : piece.segment.nextSegments.flatMap((segment) => pieces.get(segment)?.[0] ?? []);
1341
+ const edges = with_edges ? [...alternatives.get(piece) ?? []] : [];
1342
+ return [...next, ...edges].map(get);
1343
+ } }
1344
+ });
1345
+ objects.set(piece, object);
1346
+ }
1347
+ return object;
1348
+ };
1349
+ return get;
1350
+ };
1351
+ const cut_view = view(false);
1352
+ const joined_view = view(true);
1353
+ const start_piece = (segment, node) => {
1354
+ const list = pieces.get(segment) ?? [];
1355
+ pieces.set(segment, list);
1356
+ const piece = {
1357
+ segment,
1358
+ index: list.length
1359
+ };
1360
+ list.push(piece);
1361
+ cut.onCodePathSegmentStart?.(cut_view(piece), node);
1362
+ joined.onCodePathSegmentStart?.(joined_view(piece), node);
1363
+ return piece;
1364
+ };
1365
+ const end_piece = (segment, node) => {
1366
+ const piece = pieces.get(segment).at(-1);
1367
+ cut.onCodePathSegmentEnd?.(cut_view(piece), node);
1368
+ joined.onCodePathSegmentEnd?.(joined_view(piece), node);
1369
+ return piece;
1370
+ };
1371
+ const cut_here = (node) => {
1372
+ const ended = [];
1373
+ const started = [];
1374
+ for (const segment of current) {
1375
+ ended.push(end_piece(segment, node));
1376
+ started.push(start_piece(segment, node));
1377
+ }
1378
+ return {
1379
+ ended,
1380
+ started
1381
+ };
1382
+ };
1383
+ const join = (from, ...to) => {
1384
+ for (const piece of from) {
1385
+ const set = alternatives.get(piece) ?? /* @__PURE__ */ new Set();
1386
+ alternatives.set(piece, set);
1387
+ for (const list of to) for (const target of list) set.add(target);
1388
+ }
1389
+ };
1390
+ const listeners = {
1391
+ onCodePathStart(...args) {
1392
+ outer_segments.push(current);
1393
+ current = /* @__PURE__ */ new Set();
1394
+ outer_positions.push(position);
1395
+ position = {
1396
+ end: -1,
1397
+ for_heads: 0
1398
+ };
1399
+ plain.onCodePathStart?.(...args);
1400
+ cut.onCodePathStart?.(...args);
1401
+ joined.onCodePathStart?.(...args);
1402
+ },
1403
+ onCodePathEnd(...args) {
1404
+ current = outer_segments.pop();
1405
+ const inner = position;
1406
+ position = outer_positions.pop();
1407
+ if (!position.for_heads) position.end = Math.max(position.end, inner.end);
1408
+ plain.onCodePathEnd?.(...args);
1409
+ cut.onCodePathEnd?.(...args);
1410
+ joined.onCodePathEnd?.(...args);
1411
+ for (const descriptor of candidates) {
1412
+ const node = node_of(descriptor);
1413
+ if (!cut_reports.has(node) || joined_reports.has(node)) context.report(descriptor);
1414
+ }
1415
+ candidates.length = 0;
1416
+ cut_reports.clear();
1417
+ joined_reports.clear();
1418
+ },
1419
+ onCodePathSegmentStart(segment, node) {
1420
+ current.add(segment);
1421
+ plain.onCodePathSegmentStart?.(segment, node);
1422
+ start_piece(segment, node);
1423
+ },
1424
+ onCodePathSegmentEnd(segment, node) {
1425
+ current.delete(segment);
1426
+ plain.onCodePathSegmentEnd?.(segment, node);
1427
+ end_piece(segment, node);
1428
+ },
1429
+ JSXForExpression() {
1430
+ position.for_heads++;
1431
+ },
1432
+ ForStatement: start_loop,
1433
+ ForInStatement: start_loop,
1434
+ ForOfStatement: start_loop,
1435
+ JSXTryExpression(node) {
1436
+ if (suspends(node.block) || suspends(node.pending) || !runs_in_order(node)) return;
1437
+ const { ended, started } = cut_here(node);
1438
+ tries.set(node, {
1439
+ single: ended.length === 1,
1440
+ entry: ended,
1441
+ body_start: started,
1442
+ body_end: [],
1443
+ pending_start: [],
1444
+ pending_end: [],
1445
+ handler_start: []
1446
+ });
1447
+ },
1448
+ BlockStatement(node) {
1449
+ const state = tries.get(node.parent);
1450
+ if (!state || node.parent.pending !== node) return;
1451
+ const { ended, started } = cut_here(node);
1452
+ state.single &&= ended.length === 1;
1453
+ state.body_end = ended;
1454
+ state.pending_start = started;
1455
+ },
1456
+ CatchClause(node) {
1457
+ const state = tries.get(node.parent);
1458
+ if (!state) return;
1459
+ const { ended, started } = cut_here(node);
1460
+ state.single &&= ended.length === 1;
1461
+ if (node.parent.pending) state.pending_end = ended;
1462
+ else state.body_end = ended;
1463
+ state.handler_start = started;
1464
+ },
1465
+ "JSXTryExpression:exit"(node) {
1466
+ const state = tries.get(node);
1467
+ if (!state) return;
1468
+ const { ended, started: after } = cut_here(node);
1469
+ if (!node.handler) state.pending_end = ended;
1470
+ if (!state.single || ended.length !== 1) return;
1471
+ const { body_start, pending_start, handler_start } = state;
1472
+ join(state.entry, body_start, pending_start, handler_start, after);
1473
+ join(state.body_end, pending_start, handler_start, after);
1474
+ join(state.pending_end, handler_start, after);
1475
+ }
1476
+ };
1477
+ const merged = { ...listeners };
1478
+ for (const key of /* @__PURE__ */ new Set([...Object.keys(plain), ...Object.keys(cut)])) {
1479
+ if (key in listeners) continue;
1480
+ merged[key] = (...args) => {
1481
+ plain[key]?.(...args);
1482
+ const node = args[0];
1483
+ if (node?.type === "Identifier" || node?.type === "JSXIdentifier") {
1484
+ if (position.for_heads || node.range[0] < position.end) return;
1485
+ position.end = node.range[1];
1486
+ }
1487
+ cut[key]?.(...args);
1488
+ joined[key]?.(...args);
1489
+ };
1490
+ }
1491
+ return merged;
1492
+ }
1493
+ }
1147
1494
  },
1148
1495
  configs: {}
1149
1496
  };
@@ -1224,7 +1571,11 @@ plugin.configs.js = [{
1224
1571
  "no-unused-vars": "off",
1225
1572
  "tsrx/no-unused-vars": "error",
1226
1573
  "no-unreachable": "off",
1227
- "tsrx/no-unreachable": "error"
1574
+ "tsrx/no-unreachable": "error",
1575
+ ...get_core_rule("no-useless-assignment").meta?.docs?.recommended === true && {
1576
+ "no-useless-assignment": "off",
1577
+ "tsrx/no-useless-assignment": "error"
1578
+ }
1228
1579
  }
1229
1580
  }];
1230
1581
  //#endregion