Last active
April 10, 2024 10:56
-
-
Save Isokaeder/7850fae35651160e3e89ef98c0859b12 to your computer and use it in GitHub Desktop.
eslint rule to find higher order functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
meta: { | |
type: 'problem', | |
fixable: null, | |
schema: [], | |
}, | |
create(context) { | |
function checkForHigherOrderFunction(node) { | |
if ( | |
(node.type === 'ArrowFunctionExpression' || | |
node.type === 'FunctionExpression') && // Check if the function returns another function | |
(node.body.type === 'ArrowFunctionExpression' || | |
node.body.type === 'FunctionExpression') | |
) { | |
context.report({ | |
node: node, | |
message: 'Higher order function detected.', | |
}) | |
} | |
} | |
return { | |
ArrowFunctionExpression: checkForHigherOrderFunction, | |
FunctionExpression: checkForHigherOrderFunction, | |
} | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment