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.
- package/dist/index.js +24 -13
- 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
|
|
3010
|
-
|
|
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
|
-
|
|
3015
|
-
|
|
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
|
|
3024
|
-
|
|
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