Rule to prefer reference instead of inline function parameter #13919
-
Take this code for example: this.xxx('yyy', (value) => {
console.log(value)
}); I'd like to enforce the fact of moving the inline callback out, like this this.callback = (value) => {
console.log(value)
}
this.xxx('yyy', this.callback); Is there a rule for that ? All my searches lead to nothing Thanks 👋 |
Beta Was this translation helpful? Give feedback.
Answered by
mdjermanovic
Dec 13, 2020
Replies: 1 comment 1 reply
-
Hi @Armaldio! You can use the /*eslint "no-restricted-syntax": [
"error",
{
"selector": "CallExpression > :matches(FunctionExpression, ArrowFunctionExpression).arguments",
"message": "Don't use inline callbacks."
}
]*/
this.xxx('yyy', (value) => { // error
console.log(value)
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
sam3k
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Armaldio!
You can use the
no-restricted-syntax
rule to enforce this:Online Demo