📝 Replaces x => f(x) with just f.
stylistic config.
💡 This rule is manually fixable by editor suggestions.
💭 This rule requires type information.
This rule enforces using functions directly if they can be without wrapping them.
If a function can be used directly without being in a callback wrapper, then it's generally better to use it directly. Extra inline lambdas can slow the runtime down.
/* eslint functional/prefer-tacit: "error" */
function f(x) {
return x + 1;
}
const foo = [1, 2, 3].map((x) => f(x));/* eslint functional/prefer-tacit: "error" */
function f(x) {
return x + 1;
}
const foo = [1, 2, 3].map(f);
const bar = { f };
const baz = [1, 2, 3].map((x) => bar.f(x)); // Allowed unless using `checkMemberExpressions`This rule accepts an options object of the following type:
type Options = {
checkMemberExpressions: boolean;
};type Options = {
checkMemberExpressions: false;
};If true, calls of member expressions are checked as well.
If false, only calls of identifiers are checked.
/* eslint functional/prefer-tacit: ["error", { "checkMemberExpressions": true }] */
const bar = {
f(x) {
return x + 1;
},
};
const foo = [1, 2, 3].map((x) => bar.f(x));/* eslint functional/prefer-tacit: ["error", { "checkMemberExpressions": true }] */
const bar = {
f(x) {
return x + 1;
},
};
const foo = [1, 2, 3].map(bar.f.bind(bar));