@fedify/lint 2.3.9 → 2.3.11-dev.2280

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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/lint",
3
- "version": "2.3.9",
3
+ "version": "2.3.11-dev.2280+db3f75fc",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./src/mod.ts",
package/dist/index.cjs CHANGED
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
  //#endregion
27
- const require_outbox_listener_delivery_required = require("./outbox-listener-delivery-required-CiBWUvMt.cjs");
27
+ const require_outbox_listener_delivery_required = require("./outbox-listener-delivery-required-Dv8KorpQ.cjs");
28
28
  let _fxts_core = require("@fxts/core");
29
29
  let _typescript_eslint_parser = require("@typescript-eslint/parser");
30
30
  _typescript_eslint_parser = __toESM(_typescript_eslint_parser, 1);
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as RULE_IDS, S as eslint$19, T as version, _ as eslint$5, a as eslint$18, b as eslint$10, c as eslint$8, d as eslint$15, f as eslint$1, g as eslint$4, h as eslint$3, i as eslint$17, l as eslint$9, m as eslint$2, n as eslint$20, o as eslint$6, p as eslint, r as eslint$16, s as eslint$7, t as eslint$21, u as eslint$14, v as eslint$12, w as name, x as eslint$11, y as eslint$13 } from "./outbox-listener-delivery-required-DBgDh8Og.js";
1
+ import { C as RULE_IDS, S as eslint$19, T as version, _ as eslint$5, a as eslint$18, b as eslint$10, c as eslint$8, d as eslint$15, f as eslint$1, g as eslint$4, h as eslint$3, i as eslint$17, l as eslint$9, m as eslint$2, n as eslint$20, o as eslint$6, p as eslint, r as eslint$16, s as eslint$7, t as eslint$21, u as eslint$14, v as eslint$12, w as name, x as eslint$11, y as eslint$13 } from "./outbox-listener-delivery-required-VJhYGF3C.js";
2
2
  import { fromEntries, keys, map, pipe } from "@fxts/core";
3
3
  import parser from "@typescript-eslint/parser";
4
4
  //#region src/index.ts
@@ -2,7 +2,7 @@ require("./index.cjs");
2
2
  let _fxts_core = require("@fxts/core");
3
3
  //#region deno.json
4
4
  var name = "@fedify/lint";
5
- var version = "2.3.9";
5
+ var version = "2.3.11-dev.2280+db3f75fc";
6
6
  //#endregion
7
7
  //#region src/lib/const.ts
8
8
  /**
@@ -803,6 +803,37 @@ function createBindingIndex() {
803
803
  }
804
804
  };
805
805
  }
806
+ const position = (node) => node.range?.[0] ?? node.start ?? -1;
807
+ const endPosition = (node) => node.range?.[1] ?? node.end ?? -1;
808
+ const enclosingFunction = (node) => {
809
+ for (let parent = getParent(node); parent != null; parent = getParent(parent)) if (isFunctionLike(parent)) return parent;
810
+ return null;
811
+ };
812
+ const isInside = (node, ancestor) => {
813
+ for (let current = node; current != null; current = getParent(current)) if (current === ancestor) return true;
814
+ return false;
815
+ };
816
+ const isDirectStatement = (node, fn) => {
817
+ let current = node;
818
+ while (getParent(current) !== fn.body) {
819
+ const parent = getParent(current);
820
+ if (parent == null || ![
821
+ "AwaitExpression",
822
+ "ExpressionStatement",
823
+ "ReturnStatement",
824
+ "VariableDeclarator",
825
+ "VariableDeclaration",
826
+ "BlockStatement"
827
+ ].includes(parent.type)) return false;
828
+ current = parent;
829
+ }
830
+ return [
831
+ "ExpressionStatement",
832
+ "ReturnStatement",
833
+ "VariableDeclaration",
834
+ "BlockStatement"
835
+ ].includes(current.type);
836
+ };
806
837
  const resolveBindingValue = (expr, bindings, seen = /* @__PURE__ */ new Set()) => {
807
838
  if (expr.type !== "Identifier") return expr;
808
839
  const binding = bindings.lookup(expr, expr.name);
@@ -831,12 +862,45 @@ function unwrapArgument(node) {
831
862
  while (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression") node = node.expression;
832
863
  return node;
833
864
  }
834
- function functionCallsDelivery(sourceCode, listener, bindings, calls, contextIndex = 0, visited = /* @__PURE__ */ new Map()) {
865
+ function ignoredLocalSetupFunctions(listener, bindings, calls, assignments) {
866
+ const ignored = [];
867
+ const directCalls = calls.filter((call) => enclosingFunction(call) === listener && isDirectStatement(call, listener));
868
+ for (const assignment of assignments) {
869
+ if (assignment.type !== "AssignmentExpression" || assignment.operator !== "=" || assignment.left.type !== "MemberExpression" || !isFunction(assignment.right)) continue;
870
+ const setup = enclosingFunction(assignment);
871
+ if (setup == null || setup === listener || !isInside(setup, listener)) continue;
872
+ const setupParent = getParent(setup);
873
+ const namedLocalSetup = enclosingFunction(setup) === listener && (setup.type === "FunctionDeclaration" || setupParent?.type === "VariableDeclarator" && setupParent.init === setup && setupParent.id.type === "Identifier");
874
+ const passedToCall = calls.some((call) => call.arguments.some((argument) => argument.type !== "SpreadElement" && resolveListenerReference(argument, bindings) === setup));
875
+ if (!namedLocalSetup || passedToCall) continue;
876
+ const installed = assignment.right;
877
+ if (!isDirectStatement(assignment, setup) || assignment.left.object.type !== "Identifier") {
878
+ ignored.push(installed);
879
+ continue;
880
+ }
881
+ const property = getMemberPropertyName(assignment.left);
882
+ if (property == null) continue;
883
+ const setupCalls = directCalls.filter((call) => resolveListenerReference(call.callee, bindings) === setup);
884
+ if (setupCalls.length === 0) {
885
+ const called = calls.some((call) => resolveListenerReference(call.callee, bindings) === setup);
886
+ ignored.push(called ? assignment.right : setup);
887
+ continue;
888
+ }
889
+ const objectBinding = bindings.lookup(assignment.left.object, assignment.left.object.name);
890
+ const deliveryCalls = directCalls.filter((call) => {
891
+ const callee = call.callee;
892
+ return callee.type === "MemberExpression" && callee.object.type === "Identifier" && getMemberPropertyName(callee) === property && bindings.lookup(callee.object, callee.object.name) === objectBinding;
893
+ });
894
+ if (!(objectBinding != null && setupCalls.some((setupCall) => deliveryCalls.some((deliveryCall) => position(setupCall) >= 0 && position(setupCall) < position(deliveryCall))))) ignored.push(installed);
895
+ }
896
+ return ignored;
897
+ }
898
+ function functionCallsDelivery(sourceCode, listener, bindings, calls, assignments, contextIndex = 0, visited = /* @__PURE__ */ new Map()) {
835
899
  let indices = visited.get(listener);
836
900
  if (indices?.has(contextIndex)) return false;
837
901
  if (indices == null) visited.set(listener, indices = /* @__PURE__ */ new Set());
838
902
  indices.add(contextIndex);
839
- if (listenerCallsDeliveryMethod(sourceCode, listener, contextIndex)) return true;
903
+ if (listenerCallsDeliveryMethod(sourceCode, listener, contextIndex, ignoredLocalSetupFunctions(listener, bindings, calls, assignments))) return true;
840
904
  const param = unwrapContextParam(listener.params[contextIndex]);
841
905
  if (param?.type !== "Identifier") return false;
842
906
  const contextBinding = bindings.lookup(listener, param.name);
@@ -856,13 +920,21 @@ function functionCallsDelivery(sourceCode, listener, bindings, calls, contextInd
856
920
  if (argument.type === "SpreadElement") break;
857
921
  const arg = unwrapArgument(argument);
858
922
  if (arg.type !== "Identifier" || arg.name !== param.name || bindings.lookup(arg, arg.name) !== contextBinding || helper.params[index]?.type === "RestElement") continue;
859
- if (functionCallsDelivery(sourceCode, helper, bindings, calls, index, visited)) return true;
923
+ if (functionCallsDelivery(sourceCode, helper, bindings, calls, assignments, index, visited)) return true;
860
924
  }
861
925
  }
862
926
  return false;
863
927
  }
864
- const listenerCallsDeliveryMethod = (sourceCode, listener, contextIndex = 0) => {
865
- const code = stripCommentsAndStrings(sourceCode.getText(listener));
928
+ const listenerCallsDeliveryMethod = (sourceCode, listener, contextIndex = 0, ignored = []) => {
929
+ let text = sourceCode.getText(listener);
930
+ const start = position(listener);
931
+ for (const fn of ignored) {
932
+ const from = position(fn) - start;
933
+ const to = endPosition(fn) - start;
934
+ if (from < 0 || to > text.length || to < from) continue;
935
+ text = text.slice(0, from) + " ".repeat(to - from) + text.slice(to);
936
+ }
937
+ const code = stripCommentsAndStrings(text);
866
938
  const aliases = /* @__PURE__ */ new Set();
867
939
  const contextParam = unwrapContextParam(listener.params[contextIndex]);
868
940
  const contextName = contextParam?.type === "Identifier" ? contextParam.name : null;
@@ -895,6 +967,7 @@ function createRule(buildReport) {
895
967
  const federationTracker = trackFederationVariables();
896
968
  const bindings = createBindingIndex();
897
969
  const pendingCalls = [];
970
+ const pendingAssignments = [];
898
971
  const sourceCode = context.sourceCode;
899
972
  const inspectCall = (node) => {
900
973
  if (!hasMemberExpressionCallee(node) || !hasIdentifierProperty(node) || !hasMethodName("on")(node) || node.arguments.length < 2) return;
@@ -902,7 +975,7 @@ function createRule(buildReport) {
902
975
  const listener = node.arguments[1];
903
976
  const resolvedListener = isNode(listener) && isFunction(listener) ? listener : isNode(listener) ? resolveListenerReference(listener, bindings) : null;
904
977
  if (resolvedListener == null) return;
905
- if (functionCallsDelivery(sourceCode, resolvedListener, bindings, pendingCalls)) return;
978
+ if (functionCallsDelivery(sourceCode, resolvedListener, bindings, pendingCalls, pendingAssignments)) return;
906
979
  context.report({
907
980
  node: resolvedListener,
908
981
  ...buildReport
@@ -930,6 +1003,9 @@ function createRule(buildReport) {
930
1003
  CallExpression(node) {
931
1004
  pendingCalls.push(node);
932
1005
  },
1006
+ AssignmentExpression(node) {
1007
+ pendingAssignments.push(node);
1008
+ },
933
1009
  "Program:exit"() {
934
1010
  for (const node of pendingCalls) inspectCall(node);
935
1011
  }
@@ -1,7 +1,7 @@
1
1
  import { always, every, head, isEmpty, isObject, negate, pipe, pipeLazy, prop, some, toArray, unless, when } from "@fxts/core";
2
2
  //#region deno.json
3
3
  var name = "@fedify/lint";
4
- var version = "2.3.9";
4
+ var version = "2.3.11-dev.2280+db3f75fc";
5
5
  //#endregion
6
6
  //#region src/lib/const.ts
7
7
  /**
@@ -802,6 +802,37 @@ function createBindingIndex() {
802
802
  }
803
803
  };
804
804
  }
805
+ const position = (node) => node.range?.[0] ?? node.start ?? -1;
806
+ const endPosition = (node) => node.range?.[1] ?? node.end ?? -1;
807
+ const enclosingFunction = (node) => {
808
+ for (let parent = getParent(node); parent != null; parent = getParent(parent)) if (isFunctionLike(parent)) return parent;
809
+ return null;
810
+ };
811
+ const isInside = (node, ancestor) => {
812
+ for (let current = node; current != null; current = getParent(current)) if (current === ancestor) return true;
813
+ return false;
814
+ };
815
+ const isDirectStatement = (node, fn) => {
816
+ let current = node;
817
+ while (getParent(current) !== fn.body) {
818
+ const parent = getParent(current);
819
+ if (parent == null || ![
820
+ "AwaitExpression",
821
+ "ExpressionStatement",
822
+ "ReturnStatement",
823
+ "VariableDeclarator",
824
+ "VariableDeclaration",
825
+ "BlockStatement"
826
+ ].includes(parent.type)) return false;
827
+ current = parent;
828
+ }
829
+ return [
830
+ "ExpressionStatement",
831
+ "ReturnStatement",
832
+ "VariableDeclaration",
833
+ "BlockStatement"
834
+ ].includes(current.type);
835
+ };
805
836
  const resolveBindingValue = (expr, bindings, seen = /* @__PURE__ */ new Set()) => {
806
837
  if (expr.type !== "Identifier") return expr;
807
838
  const binding = bindings.lookup(expr, expr.name);
@@ -830,12 +861,45 @@ function unwrapArgument(node) {
830
861
  while (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression") node = node.expression;
831
862
  return node;
832
863
  }
833
- function functionCallsDelivery(sourceCode, listener, bindings, calls, contextIndex = 0, visited = /* @__PURE__ */ new Map()) {
864
+ function ignoredLocalSetupFunctions(listener, bindings, calls, assignments) {
865
+ const ignored = [];
866
+ const directCalls = calls.filter((call) => enclosingFunction(call) === listener && isDirectStatement(call, listener));
867
+ for (const assignment of assignments) {
868
+ if (assignment.type !== "AssignmentExpression" || assignment.operator !== "=" || assignment.left.type !== "MemberExpression" || !isFunction(assignment.right)) continue;
869
+ const setup = enclosingFunction(assignment);
870
+ if (setup == null || setup === listener || !isInside(setup, listener)) continue;
871
+ const setupParent = getParent(setup);
872
+ const namedLocalSetup = enclosingFunction(setup) === listener && (setup.type === "FunctionDeclaration" || setupParent?.type === "VariableDeclarator" && setupParent.init === setup && setupParent.id.type === "Identifier");
873
+ const passedToCall = calls.some((call) => call.arguments.some((argument) => argument.type !== "SpreadElement" && resolveListenerReference(argument, bindings) === setup));
874
+ if (!namedLocalSetup || passedToCall) continue;
875
+ const installed = assignment.right;
876
+ if (!isDirectStatement(assignment, setup) || assignment.left.object.type !== "Identifier") {
877
+ ignored.push(installed);
878
+ continue;
879
+ }
880
+ const property = getMemberPropertyName(assignment.left);
881
+ if (property == null) continue;
882
+ const setupCalls = directCalls.filter((call) => resolveListenerReference(call.callee, bindings) === setup);
883
+ if (setupCalls.length === 0) {
884
+ const called = calls.some((call) => resolveListenerReference(call.callee, bindings) === setup);
885
+ ignored.push(called ? assignment.right : setup);
886
+ continue;
887
+ }
888
+ const objectBinding = bindings.lookup(assignment.left.object, assignment.left.object.name);
889
+ const deliveryCalls = directCalls.filter((call) => {
890
+ const callee = call.callee;
891
+ return callee.type === "MemberExpression" && callee.object.type === "Identifier" && getMemberPropertyName(callee) === property && bindings.lookup(callee.object, callee.object.name) === objectBinding;
892
+ });
893
+ if (!(objectBinding != null && setupCalls.some((setupCall) => deliveryCalls.some((deliveryCall) => position(setupCall) >= 0 && position(setupCall) < position(deliveryCall))))) ignored.push(installed);
894
+ }
895
+ return ignored;
896
+ }
897
+ function functionCallsDelivery(sourceCode, listener, bindings, calls, assignments, contextIndex = 0, visited = /* @__PURE__ */ new Map()) {
834
898
  let indices = visited.get(listener);
835
899
  if (indices?.has(contextIndex)) return false;
836
900
  if (indices == null) visited.set(listener, indices = /* @__PURE__ */ new Set());
837
901
  indices.add(contextIndex);
838
- if (listenerCallsDeliveryMethod(sourceCode, listener, contextIndex)) return true;
902
+ if (listenerCallsDeliveryMethod(sourceCode, listener, contextIndex, ignoredLocalSetupFunctions(listener, bindings, calls, assignments))) return true;
839
903
  const param = unwrapContextParam(listener.params[contextIndex]);
840
904
  if (param?.type !== "Identifier") return false;
841
905
  const contextBinding = bindings.lookup(listener, param.name);
@@ -855,13 +919,21 @@ function functionCallsDelivery(sourceCode, listener, bindings, calls, contextInd
855
919
  if (argument.type === "SpreadElement") break;
856
920
  const arg = unwrapArgument(argument);
857
921
  if (arg.type !== "Identifier" || arg.name !== param.name || bindings.lookup(arg, arg.name) !== contextBinding || helper.params[index]?.type === "RestElement") continue;
858
- if (functionCallsDelivery(sourceCode, helper, bindings, calls, index, visited)) return true;
922
+ if (functionCallsDelivery(sourceCode, helper, bindings, calls, assignments, index, visited)) return true;
859
923
  }
860
924
  }
861
925
  return false;
862
926
  }
863
- const listenerCallsDeliveryMethod = (sourceCode, listener, contextIndex = 0) => {
864
- const code = stripCommentsAndStrings(sourceCode.getText(listener));
927
+ const listenerCallsDeliveryMethod = (sourceCode, listener, contextIndex = 0, ignored = []) => {
928
+ let text = sourceCode.getText(listener);
929
+ const start = position(listener);
930
+ for (const fn of ignored) {
931
+ const from = position(fn) - start;
932
+ const to = endPosition(fn) - start;
933
+ if (from < 0 || to > text.length || to < from) continue;
934
+ text = text.slice(0, from) + " ".repeat(to - from) + text.slice(to);
935
+ }
936
+ const code = stripCommentsAndStrings(text);
865
937
  const aliases = /* @__PURE__ */ new Set();
866
938
  const contextParam = unwrapContextParam(listener.params[contextIndex]);
867
939
  const contextName = contextParam?.type === "Identifier" ? contextParam.name : null;
@@ -894,6 +966,7 @@ function createRule(buildReport) {
894
966
  const federationTracker = trackFederationVariables();
895
967
  const bindings = createBindingIndex();
896
968
  const pendingCalls = [];
969
+ const pendingAssignments = [];
897
970
  const sourceCode = context.sourceCode;
898
971
  const inspectCall = (node) => {
899
972
  if (!hasMemberExpressionCallee(node) || !hasIdentifierProperty(node) || !hasMethodName("on")(node) || node.arguments.length < 2) return;
@@ -901,7 +974,7 @@ function createRule(buildReport) {
901
974
  const listener = node.arguments[1];
902
975
  const resolvedListener = isNode(listener) && isFunction(listener) ? listener : isNode(listener) ? resolveListenerReference(listener, bindings) : null;
903
976
  if (resolvedListener == null) return;
904
- if (functionCallsDelivery(sourceCode, resolvedListener, bindings, pendingCalls)) return;
977
+ if (functionCallsDelivery(sourceCode, resolvedListener, bindings, pendingCalls, pendingAssignments)) return;
905
978
  context.report({
906
979
  node: resolvedListener,
907
980
  ...buildReport
@@ -929,6 +1002,9 @@ function createRule(buildReport) {
929
1002
  CallExpression(node) {
930
1003
  pendingCalls.push(node);
931
1004
  },
1005
+ AssignmentExpression(node) {
1006
+ pendingAssignments.push(node);
1007
+ },
932
1008
  "Program:exit"() {
933
1009
  for (const node of pendingCalls) inspectCall(node);
934
1010
  }
package/dist/oxlint.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_outbox_listener_delivery_required = require("./outbox-listener-delivery-required-CiBWUvMt.cjs");
1
+ const require_outbox_listener_delivery_required = require("./outbox-listener-delivery-required-Dv8KorpQ.cjs");
2
2
  //#region src/oxlint.ts
3
3
  const rules = {
4
4
  [require_outbox_listener_delivery_required.RULE_IDS.actorIdMismatch]: require_outbox_listener_delivery_required.eslint$12,
package/dist/oxlint.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as RULE_IDS, S as eslint$19, T as version, _ as eslint$5, a as eslint$18, b as eslint$10, c as eslint$8, d as eslint$15, f as eslint$1, g as eslint$4, h as eslint$3, i as eslint$17, l as eslint$9, m as eslint$2, n as eslint$20, o as eslint$6, p as eslint, r as eslint$16, s as eslint$7, t as eslint$21, u as eslint$14, v as eslint$12, w as name, x as eslint$11, y as eslint$13 } from "./outbox-listener-delivery-required-DBgDh8Og.js";
1
+ import { C as RULE_IDS, S as eslint$19, T as version, _ as eslint$5, a as eslint$18, b as eslint$10, c as eslint$8, d as eslint$15, f as eslint$1, g as eslint$4, h as eslint$3, i as eslint$17, l as eslint$9, m as eslint$2, n as eslint$20, o as eslint$6, p as eslint, r as eslint$16, s as eslint$7, t as eslint$21, u as eslint$14, v as eslint$12, w as name, x as eslint$11, y as eslint$13 } from "./outbox-listener-delivery-required-VJhYGF3C.js";
2
2
  //#region src/oxlint.ts
3
3
  const rules = {
4
4
  [RULE_IDS.actorIdMismatch]: eslint,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/lint",
3
- "version": "2.3.9",
3
+ "version": "2.3.11-dev.2280+db3f75fc",
4
4
  "description": "Fedify linting rules and plugins",
5
5
  "keywords": [
6
6
  "Fedify",
@@ -54,7 +54,7 @@
54
54
  ],
55
55
  "peerDependencies": {
56
56
  "eslint": ">=9.0.0",
57
- "@fedify/fedify": "^2.3.9"
57
+ "@fedify/fedify": "^2.3.11-dev.2280+db3f75fc"
58
58
  },
59
59
  "peerDependenciesMeta": {
60
60
  "eslint": {