eslint/func-names Style β
What it does β
Require or disallow named function expressions.
Why is this bad? β
Leaving the name off a function will cause <anonymous>
to appear in stack traces of errors thrown in it or any function called within it. This makes it more difficult to find where an error is thrown. If you provide the optional name for a function expression then you will get the name of the function expression in the stack trace.
Configuration β
This rule has a string option:
"always"
requires a function expression to have a name under all circumstances."as-needed"
requires a function expression to have a name only when one will not be automatically inferred by the runtime."never"
requires a function expression to not have a name under any circumstances.
Example β
Examples of incorrect code for this rule:
javascript
/*oxlint func-names: "error" */
// default is "always" and there is an anonymous function
Foo.prototype.bar = function () {};
/*oxlint func-names: ["error", "always"] */
// there is an anonymous function
Foo.prototype.bar = function () {};
/*oxlint func-names: ["error", "as-needed"] */
// there is an anonymous function
// where the name isnβt assigned automatically per the ECMAScript specs
Foo.prototype.bar = function () {};
/*oxlint func-names: ["error", "never"] */
// there is a named function
Foo.prototype.bar = function bar() {};
Examples of *correct code for this rule:
javascript
/*oxlint func-names: "error" */
Foo.prototype.bar = function bar() {};
/*oxlint func-names: ["error", "always"] */
Foo.prototype.bar = function bar() {};
/*oxlint func-names: ["error", "as-needed"] */
var foo = function () {};
/*oxlint func-names: ["error", "never"] */
Foo.prototype.bar = function () {};