eslint-plugin-absolute 0.11.8 → 0.11.9

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3006,29 +3006,40 @@ var noUselessCatch = createRule({
3006
3006
  // src/rules/no-useless-function.ts
3007
3007
  var noUselessFunction = createRule({
3008
3008
  create(context) {
3009
- const isCallbackFunction = (node) => {
3010
- const { parent } = node;
3011
- if (!parent || parent.type !== "CallExpression") {
3009
+ const isStaticObjectLiteral = (object) => object.properties.every((property) => {
3010
+ if (property.type !== "Property" || property.computed) {
3012
3011
  return false;
3013
3012
  }
3014
- for (const arg of parent.arguments) {
3015
- if (arg === node) {
3013
+ const { value } = property;
3014
+ return value.type === "Literal" || value.type === "TemplateLiteral" && value.expressions.length === 0;
3015
+ });
3016
+ const isWithinCallArgument = (node) => {
3017
+ let child = node;
3018
+ let current = node.parent;
3019
+ while (current) {
3020
+ if (current.type === "CallExpression" && current.arguments.some((argument) => argument === child)) {
3016
3021
  return true;
3017
3022
  }
3023
+ child = current;
3024
+ current = current.parent;
3018
3025
  }
3019
3026
  return false;
3020
3027
  };
3021
3028
  return {
3022
3029
  ArrowFunctionExpression(node) {
3023
- if (node.params.length === 0 && node.body && node.body.type === "ObjectExpression") {
3024
- if (isCallbackFunction(node)) {
3025
- return;
3026
- }
3027
- context.report({
3028
- messageId: "uselessFunction",
3029
- node
3030
- });
3030
+ if (node.params.length !== 0 || !node.body || node.body.type !== "ObjectExpression") {
3031
+ return;
3031
3032
  }
3033
+ if (!isStaticObjectLiteral(node.body)) {
3034
+ return;
3035
+ }
3036
+ if (isWithinCallArgument(node)) {
3037
+ return;
3038
+ }
3039
+ context.report({
3040
+ messageId: "uselessFunction",
3041
+ node
3042
+ });
3032
3043
  }
3033
3044
  };
3034
3045
  },
package/package.json CHANGED
@@ -41,5 +41,5 @@
41
41
  "typecheck": "bun run tsc --noEmit"
42
42
  },
43
43
  "type": "module",
44
- "version": "0.11.8"
44
+ "version": "0.11.9"
45
45
  }