Enforce named function expressions

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: javascript-code-style/func-names

Language: JavaScript

Severity: Notice

Category: Best Practices

Description

It is easier to debug your application code when you avoid anonymous functions so that the stack trace can show you meaningful error messages. This rule enforces all your function to be consistently declared with a name.

Non-Compliant Code Examples

Foo.prototype.bar = function() {};
(function(){}())
f(function(){})
var a = new Date(function() {});
var test = function(d, e, f) {};
new function() {}
Foo.prototype.bar = function() {};
(function(){}())
f(function(){})
var a = new Date(function() {});
new function() {}
var {foo} = function(){};
({ a: obj.prop = function(){} } = foo);
[obj.prop = function(){}] = foo;
var { a: [b] = function(){} } = foo;
function foo({ a } = function(){}) {};
export default function() {}
export default function() {}
export default (function(){});
var foo = bar(function *() {});
var foo = function*() {};
(function*() {}())
var foo = bar(function *() {});
var foo = function*() {};
(function*() {}())
var foo = bar(function *() {});
(function*() {}())
var foo = bar(function *() {});
(function*() {}())
var foo = function*() {};
(function*() {}())
var foo = bar(function *() {});
var foo = function*() {};
(function*() {}())
var foo = bar(function *() {});
var foo = function*() {};
(function*() {}())
var foo = bar(function *() {});
var foo = function*() {};
(function*() {}())
var foo = bar(function *() {});
var foo = function*() {};
(function*() {}())
class C { foo = function() {} }
class C { [foo] = function() {} }
class C { #foo = function() {} }

Compliant Code Examples

Foo.prototype.bar = function bar(){};
Foo.prototype.bar = () => {};
function foo(){}
function test(d, e, f) {}
new function bar(){}
exports = { get foo() { return 1; }, set bar(val) { return val; } };
({ foo() { return 1; } });
class A { constructor(){} foo(){} get bar(){} set baz(value){} static qux(){}}
function foo() {}
var a = function foo() {};
class A { constructor(){} foo(){} get bar(){} set baz(value){} static qux(){}}
({ foo() {} });
function foo() {}
var a = function foo() { foo(); };
class A { constructor(){} foo(){} get bar(){} set baz(value){} static qux(){}}
({ foo() {} });
export default function foo() {}
export default function foo() {}
export default function foo() {}
var foo = bar(function *baz() {});
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: antoine.dussault/service-representation-ga-docs-us1