Skip to content

Instantly share code, notes, and snippets.

@Isokaeder
Last active April 10, 2024 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Isokaeder/7850fae35651160e3e89ef98c0859b12 to your computer and use it in GitHub Desktop.
Save Isokaeder/7850fae35651160e3e89ef98c0859b12 to your computer and use it in GitHub Desktop.
eslint rule to find higher order functions
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