eslint-plugin-rxjs-x 0.7.6 → 0.8.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.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  // package.json
2
2
  var name = "eslint-plugin-rxjs-x";
3
- var version = "0.7.6";
3
+ var version = "0.8.0";
4
4
 
5
5
  // src/configs/recommended.ts
6
6
  var createRecommendedConfig = (plugin2) => ({
7
7
  name: "rxjs-x/recommended",
8
8
  plugins: {
9
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- "A type annotation is necessary."
9
10
  "rxjs-x": plugin2
10
11
  },
11
12
  rules: {
@@ -36,6 +37,7 @@ var createRecommendedConfig = (plugin2) => ({
36
37
  var createStrictConfig = (plugin2) => ({
37
38
  name: "rxjs-x/strict",
38
39
  plugins: {
40
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- "A type annotation is necessary."
39
41
  "rxjs-x": plugin2
40
42
  },
41
43
  rules: {
@@ -218,6 +220,9 @@ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
218
220
  function hasTypeAnnotation(node) {
219
221
  return "typeAnnotation" in node && !!node.typeAnnotation;
220
222
  }
223
+ function isAccessorProperty(node) {
224
+ return node.type === AST_NODE_TYPES.AccessorProperty;
225
+ }
221
226
  function isArrayExpression(node) {
222
227
  return node.type === AST_NODE_TYPES.ArrayExpression;
223
228
  }
@@ -435,6 +440,7 @@ import { ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
435
440
  var REPO_URL = "https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x";
436
441
  var ruleCreator = ESLintUtils2.RuleCreator(
437
442
  (name2) => `${REPO_URL}/blob/v${version}/docs/rules/${name2}.md`
443
+ // Ensure the resulting types are narrowed to exactly what each rule declares.
438
444
  );
439
445
 
440
446
  // src/rules/ban-observables.ts
@@ -2235,6 +2241,7 @@ var noInternalRule = ruleCreator({
2235
2241
 
2236
2242
  // src/rules/no-misused-observables.ts
2237
2243
  import { AST_NODE_TYPES as AST_NODE_TYPES6, ESLintUtils as ESLintUtils8 } from "@typescript-eslint/utils";
2244
+ import { getFunctionHeadLocation, isFunction } from "@typescript-eslint/utils/ast-utils";
2238
2245
  import * as tsutils2 from "ts-api-utils";
2239
2246
  import ts6 from "typescript";
2240
2247
  function parseChecksVoidReturn(checksVoidReturn) {
@@ -2376,10 +2383,14 @@ var noMisusedObservablesRule = ruleCreator({
2376
2383
  }
2377
2384
  }
2378
2385
  function checkJSXAttribute(node) {
2379
- if (!node.value || !isJSXExpressionContainer(node.value)) {
2386
+ if (node.value == null || !isJSXExpressionContainer(node.value)) {
2380
2387
  return;
2381
2388
  }
2382
- if (couldReturnObservable(node.value.expression)) {
2389
+ const expressionContainer = esTreeNodeToTSNodeMap.get(
2390
+ node.value
2391
+ );
2392
+ const contextualType = checker.getContextualType(expressionContainer);
2393
+ if (contextualType != null && isVoidReturningFunctionType(contextualType) && couldReturnObservable(node.value.expression)) {
2383
2394
  context.report({
2384
2395
  messageId: "forbiddenVoidReturnAttribute",
2385
2396
  node: node.value
@@ -2396,7 +2407,7 @@ var noMisusedObservablesRule = ruleCreator({
2396
2407
  for (const element of node.body.body) {
2397
2408
  const tsElement = esTreeNodeToTSNodeMap.get(element);
2398
2409
  const memberName = (_a = tsElement == null ? void 0 : tsElement.name) == null ? void 0 : _a.getText();
2399
- if (memberName === void 0) {
2410
+ if (memberName == null) {
2400
2411
  continue;
2401
2412
  }
2402
2413
  if (!couldReturnObservable(element)) {
@@ -2407,7 +2418,7 @@ var noMisusedObservablesRule = ruleCreator({
2407
2418
  }
2408
2419
  for (const heritageType of heritageTypes) {
2409
2420
  const heritageMember = getMemberIfExists(heritageType, memberName);
2410
- if (heritageMember === void 0) {
2421
+ if (heritageMember == null) {
2411
2422
  continue;
2412
2423
  }
2413
2424
  const memberType = checker.getTypeOfSymbolAtLocation(heritageMember, tsElement);
@@ -2425,7 +2436,7 @@ var noMisusedObservablesRule = ruleCreator({
2425
2436
  function checkProperty(node) {
2426
2437
  const tsNode = esTreeNodeToTSNodeMap.get(node);
2427
2438
  const contextualType = getPropertyContextualType(checker, tsNode);
2428
- if (contextualType === void 0) {
2439
+ if (contextualType == null) {
2429
2440
  return;
2430
2441
  }
2431
2442
  if (!isVoidReturningFunctionType(contextualType)) {
@@ -2434,14 +2445,29 @@ var noMisusedObservablesRule = ruleCreator({
2434
2445
  if (!couldReturnObservable(node.value)) {
2435
2446
  return;
2436
2447
  }
2437
- context.report({
2438
- messageId: "forbiddenVoidReturnProperty",
2439
- node: node.value
2440
- });
2448
+ if (isFunction(node.value)) {
2449
+ const functionNode = node.value;
2450
+ if (functionNode.returnType) {
2451
+ context.report({
2452
+ messageId: "forbiddenVoidReturnProperty",
2453
+ node: functionNode.returnType.typeAnnotation
2454
+ });
2455
+ } else {
2456
+ context.report({
2457
+ messageId: "forbiddenVoidReturnProperty",
2458
+ loc: getFunctionHeadLocation(functionNode, context.sourceCode)
2459
+ });
2460
+ }
2461
+ } else {
2462
+ context.report({
2463
+ messageId: "forbiddenVoidReturnProperty",
2464
+ node: node.value
2465
+ });
2466
+ }
2441
2467
  }
2442
2468
  function checkReturnStatement(node) {
2443
2469
  const tsNode = esTreeNodeToTSNodeMap.get(node);
2444
- if (tsNode.expression === void 0 || !node.argument) {
2470
+ if (tsNode.expression == null || !node.argument) {
2445
2471
  return;
2446
2472
  }
2447
2473
  function getFunctionNode() {
@@ -2456,7 +2482,7 @@ var noMisusedObservablesRule = ruleCreator({
2456
2482
  return;
2457
2483
  }
2458
2484
  const contextualType = checker.getContextualType(tsNode.expression);
2459
- if (contextualType === void 0) {
2485
+ if (contextualType == null) {
2460
2486
  return;
2461
2487
  }
2462
2488
  if (!isVoidReturningFunctionType(contextualType)) {
@@ -2484,7 +2510,7 @@ var noMisusedObservablesRule = ruleCreator({
2484
2510
  }
2485
2511
  function checkVariableDeclaration(node) {
2486
2512
  const tsNode = esTreeNodeToTSNodeMap.get(node);
2487
- if (tsNode.initializer === void 0 || !node.init || !node.id.typeAnnotation) {
2513
+ if (tsNode.initializer == null || node.init == null || node.id.typeAnnotation == null) {
2488
2514
  return;
2489
2515
  }
2490
2516
  if (!isPossiblyFunctionType(node.id.typeAnnotation)) {
@@ -2531,6 +2557,9 @@ function isVoidReturningFunctionType(type) {
2531
2557
  for (const subType of tsutils2.unionTypeParts(type)) {
2532
2558
  for (const signature of subType.getCallSignatures()) {
2533
2559
  const returnType = signature.getReturnType();
2560
+ if (couldBeType(returnType, "Observable")) {
2561
+ return false;
2562
+ }
2534
2563
  hasVoidReturn || (hasVoidReturn = tsutils2.isTypeFlagSet(returnType, ts6.TypeFlags.Void));
2535
2564
  }
2536
2565
  }
@@ -2547,7 +2576,7 @@ function getMemberIfExists(type, memberName) {
2547
2576
  return symbolMemberMatch != null ? symbolMemberMatch : tsutils2.getPropertyOfType(type, escapedMemberName);
2548
2577
  }
2549
2578
  function isStaticMember(node) {
2550
- return (isMethodDefinition(node) || isPropertyDefinition(node)) && node.static;
2579
+ return (isMethodDefinition(node) || isPropertyDefinition(node) || isAccessorProperty(node)) && node.static;
2551
2580
  }
2552
2581
  function getPropertyContextualType(checker, tsNode) {
2553
2582
  if (ts6.isPropertyAssignment(tsNode)) {
@@ -2563,11 +2592,11 @@ function getPropertyContextualType(checker, tsNode) {
2563
2592
  return;
2564
2593
  }
2565
2594
  const objType = checker.getContextualType(obj);
2566
- if (objType === void 0) {
2595
+ if (objType == null) {
2567
2596
  return;
2568
2597
  }
2569
2598
  const propertySymbol = checker.getPropertyOfType(objType, tsNode.name.text);
2570
- if (propertySymbol === void 0) {
2599
+ if (propertySymbol == null) {
2571
2600
  return;
2572
2601
  }
2573
2602
  return checker.getTypeOfSymbolAtLocation(propertySymbol, tsNode.name);
@@ -4100,55 +4129,57 @@ var throwErrorRule = ruleCreator({
4100
4129
  });
4101
4130
 
4102
4131
  // src/index.ts
4132
+ var allRules = {
4133
+ "ban-observables": banObservablesRule,
4134
+ "ban-operators": banOperatorsRule,
4135
+ "finnish": finnishRule,
4136
+ "just": justRule,
4137
+ "macro": macroRule,
4138
+ "no-async-subscribe": noAsyncSubscribeRule,
4139
+ "no-compat": noCompatRule,
4140
+ "no-connectable": noConnectableRule,
4141
+ "no-create": noCreateRule,
4142
+ "no-cyclic-action": noCyclicActionRule,
4143
+ "no-explicit-generics": noExplicitGenericsRule,
4144
+ "no-exposed-subjects": noExposedSubjectsRule,
4145
+ "no-finnish": noFinnishRule,
4146
+ "no-floating-observables": noFloatingObservablesRule,
4147
+ "no-ignored-default-value": noIgnoredDefaultValueRule,
4148
+ "no-ignored-error": noIgnoredErrorRule,
4149
+ "no-ignored-notifier": noIgnoredNotifierRule,
4150
+ "no-ignored-replay-buffer": noIgnoredReplayBufferRule,
4151
+ "no-ignored-subscribe": noIgnoredSubscribeRule,
4152
+ "no-ignored-subscription": noIgnoredSubscriptionRule,
4153
+ "no-ignored-takewhile-value": noIgnoredTakewhileValueRule,
4154
+ "no-implicit-any-catch": noImplicitAnyCatchRule,
4155
+ "no-index": noIndexRule,
4156
+ "no-internal": noInternalRule,
4157
+ "no-misused-observables": noMisusedObservablesRule,
4158
+ "no-nested-subscribe": noNestedSubscribeRule,
4159
+ "no-redundant-notify": noRedundantNotifyRule,
4160
+ "no-sharereplay": noSharereplayRule,
4161
+ "no-subclass": noSubclassRule,
4162
+ "no-subject-unsubscribe": noSubjectUnsubscribeRule,
4163
+ "no-subject-value": noSubjectValueRule,
4164
+ "no-subscribe-handlers": noSubscribeHandlersRule,
4165
+ "no-subscribe-in-pipe": noSubscribeInPipeRule,
4166
+ "no-tap": noTapRule,
4167
+ "no-topromise": noTopromiseRule,
4168
+ "no-unbound-methods": noUnboundMethodsRule,
4169
+ "no-unsafe-catch": noUnsafeCatchRule,
4170
+ "no-unsafe-first": noUnsafeFirstRule,
4171
+ "no-unsafe-subject-next": noUnsafeSubjectNext,
4172
+ "no-unsafe-switchmap": noUnsafeSwitchmapRule,
4173
+ "no-unsafe-takeuntil": noUnsafeTakeuntilRule,
4174
+ "prefer-observer": preferObserverRule,
4175
+ "prefer-root-operators": preferRootOperatorsRule,
4176
+ "suffix-subjects": suffixSubjectsRule,
4177
+ "throw-error": throwErrorRule
4178
+ };
4103
4179
  var plugin = {
4104
4180
  meta: { name, version },
4105
- rules: {
4106
- "ban-observables": banObservablesRule,
4107
- "ban-operators": banOperatorsRule,
4108
- "finnish": finnishRule,
4109
- "just": justRule,
4110
- "macro": macroRule,
4111
- "no-async-subscribe": noAsyncSubscribeRule,
4112
- "no-compat": noCompatRule,
4113
- "no-connectable": noConnectableRule,
4114
- "no-create": noCreateRule,
4115
- "no-cyclic-action": noCyclicActionRule,
4116
- "no-explicit-generics": noExplicitGenericsRule,
4117
- "no-exposed-subjects": noExposedSubjectsRule,
4118
- "no-finnish": noFinnishRule,
4119
- "no-floating-observables": noFloatingObservablesRule,
4120
- "no-ignored-default-value": noIgnoredDefaultValueRule,
4121
- "no-ignored-error": noIgnoredErrorRule,
4122
- "no-ignored-notifier": noIgnoredNotifierRule,
4123
- "no-ignored-replay-buffer": noIgnoredReplayBufferRule,
4124
- "no-ignored-subscribe": noIgnoredSubscribeRule,
4125
- "no-ignored-subscription": noIgnoredSubscriptionRule,
4126
- "no-ignored-takewhile-value": noIgnoredTakewhileValueRule,
4127
- "no-implicit-any-catch": noImplicitAnyCatchRule,
4128
- "no-index": noIndexRule,
4129
- "no-internal": noInternalRule,
4130
- "no-misused-observables": noMisusedObservablesRule,
4131
- "no-nested-subscribe": noNestedSubscribeRule,
4132
- "no-redundant-notify": noRedundantNotifyRule,
4133
- "no-sharereplay": noSharereplayRule,
4134
- "no-subclass": noSubclassRule,
4135
- "no-subject-unsubscribe": noSubjectUnsubscribeRule,
4136
- "no-subject-value": noSubjectValueRule,
4137
- "no-subscribe-handlers": noSubscribeHandlersRule,
4138
- "no-subscribe-in-pipe": noSubscribeInPipeRule,
4139
- "no-tap": noTapRule,
4140
- "no-topromise": noTopromiseRule,
4141
- "no-unbound-methods": noUnboundMethodsRule,
4142
- "no-unsafe-catch": noUnsafeCatchRule,
4143
- "no-unsafe-first": noUnsafeFirstRule,
4144
- "no-unsafe-subject-next": noUnsafeSubjectNext,
4145
- "no-unsafe-switchmap": noUnsafeSwitchmapRule,
4146
- "no-unsafe-takeuntil": noUnsafeTakeuntilRule,
4147
- "prefer-observer": preferObserverRule,
4148
- "prefer-root-operators": preferRootOperatorsRule,
4149
- "suffix-subjects": suffixSubjectsRule,
4150
- "throw-error": throwErrorRule
4151
- }
4181
+ /** Compatibility with `defineConfig` until https://github.com/typescript-eslint/typescript-eslint/issues/11543 is addressed. */
4182
+ rules: allRules
4152
4183
  };
4153
4184
  var rxjsX = {
4154
4185
  ...plugin,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "eslint-plugin-rxjs-x",
3
3
  "type": "commonjs",
4
- "version": "0.7.6",
5
- "packageManager": "yarn@4.9.2+sha512.1fc009bc09d13cfd0e19efa44cbfc2b9cf6ca61482725eb35bbc5e257e093ebf4130db6dfe15d604ff4b79efd8e1e8e99b25fa7d0a6197c9f9826358d4d65c3c",
4
+ "version": "0.8.0",
5
+ "packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f",
6
6
  "description": "ESLint v9+ plugin for RxJS",
7
7
  "author": "Jason Weinzierl <weinzierljason@gmail.com>",
8
8
  "license": "MIT",
@@ -72,29 +72,30 @@
72
72
  }
73
73
  },
74
74
  "devDependencies": {
75
- "@eslint/js": "^9.29.0",
76
- "@stylistic/eslint-plugin": "^4.4.1",
75
+ "@eslint/config-helpers": "0.4.1",
76
+ "@eslint/js": "^9.38.0",
77
+ "@stylistic/eslint-plugin": "^5.5.0",
77
78
  "@types/common-tags": "^1.8.4",
78
79
  "@types/node": "~18.18.0",
79
- "@typescript-eslint/rule-tester": "^8.34.1",
80
+ "@typescript-eslint/rule-tester": "^8.46.2",
80
81
  "@typescript/vfs": "^1.6.1",
81
- "@vitest/coverage-v8": "^3.2.3",
82
- "@vitest/eslint-plugin": "^1.2.7",
83
- "bumpp": "^10.1.1",
84
- "eslint": "^9.29.0",
82
+ "@vitest/coverage-v8": "^3.2.4",
83
+ "@vitest/eslint-plugin": "^1.4.0",
84
+ "bumpp": "^10.3.1",
85
+ "eslint": "^9.38.0",
85
86
  "eslint-config-flat-gitignore": "^2.1.0",
86
- "eslint-doc-generator": "^2.1.2",
87
- "eslint-import-resolver-typescript": "^4.4.3",
88
- "eslint-plugin-eslint-plugin": "^6.4.0",
89
- "eslint-plugin-import-x": "^4.15.2",
90
- "eslint-plugin-n": "^17.20.0",
87
+ "eslint-doc-generator": "~2.2.2",
88
+ "eslint-import-resolver-typescript": "^4.4.4",
89
+ "eslint-plugin-eslint-plugin": "^7.2.0",
90
+ "eslint-plugin-import-x": "^4.16.1",
91
+ "eslint-plugin-n": "^17.23.1",
91
92
  "markdownlint-cli2": "^0.18.1",
92
93
  "rxjs": "^7.8.2",
93
94
  "tsup": "^8.5.0",
94
95
  "typescript": "~5.8.3",
95
- "typescript-eslint": "^8.34.1",
96
+ "typescript-eslint": "^8.46.2",
96
97
  "vite": "^6.3.5",
97
- "vitest": "^3.2.3"
98
+ "vitest": "^3.2.4"
98
99
  },
99
100
  "engines": {
100
101
  "node": "^18.18.0 || ^20.9.0 || >= 21.1.0"