func-names

要求或禁止命名的 function 表达式

一种越来越普遍的模式是给函数表达式命名以帮助调试。例如:

Foo.prototype.bar = function bar() {};

在上面的示例中添加第二个 bar 是可选的。如果您省略函数名称,那么当函数抛出异常时,您可能会在堆栈跟踪中得到类似于 anonymous function 的内容。如果您为函数表达式提供可选名称,那么您将在堆栈跟踪中获得函数表达式的名称。

规则详情

此规则可以强制或禁止使用命名函数表达式。

选项

此规则有一个字符串选项:

    kEtQi+Z0dlnoc54hfXSBKkpuiYeuWb6Xl3fOovl5mO/NQRAKFL+qZwpLXoVYK3dGbEukaLmFINIRd1YIw4sz5Ouu9nX4wscAV6QSnN9yxuZB/jnpGjJJPCoA19cNMGV9K9sh1WhBoLfSgo06219bsKU3PmxP8oqyUf/Th3dFQwUFRvZejDTxZ0UrJNiVIaQQ+b1WAf2NQmnj8eXlnHEi124agixhGF4/D2ZMto0RCIRbUyd2Un9NajPKVNx5ma0hIUKdY3iC5t94W4ZDeSNgHuBBcQESh+HlLRFimL7xu/CGlC056wtG4oRBWiqPWb6qbFAEnTQwcTuATnwQTb/9OVi0BXeQPVfttUuNuMKt85y7OLeNI40DCUnd2U/g2A3drc6nvo/70ZfbA8xXGuTyIQ==

iUBjM40SPBc84UHpTbhTXi5m08Y+W8u+3M/WPQDUbA91GIF5tp6hcHbH4oIaa4GO

    HhPo5inKAeSbRodYTJU0FLn6zlIWOGnAzp5BfL7sFZ/V04+hYGUYYepJf6rWGcNdKN3s7j6Zn5Sw6FZ0nb69ROXjjcN8lSFqnNxECCGSQbIacRA06SmWkZKNV3B0Egxh/Ug985622YPkdkospkiUzDMu++CyPvUEPEkffHPSfttIR9cQiB559roE9Ty7Y2mBPdgD8V9cklC09zkWgXAyoElMh70QYcaZQqyBd45ZO61wBCiPM6BDgDlczsxDuREEsAysYen7OgJ9PNjLCWkmvkjxll4YIw0Fi2vsJ4j9zOywIYDyQNv4GGQa51ymp/87imiIQjoG8auqUdwNksqFHFcDDrUJROe7vU78iQVSK7nCw+AmlzaCWzGIoGy4VrRvN8k5K8OtHi3JoFrKrGd9PTY/gYTw0XeukVyppwY8/xE=

EKakeN0+LifhBc5QWYBFsvRxVLtejR7JgWvARgc6suzYaB4Xmxh2rl2Jd76PqZ39Yl53CrFpDzMECB/FB5RkNwk3lH2nrcelQMvWt1lUNZpiK1T5aiOSQRQNXLftALZbHBOuu+RBjYAzW2VevfHl9A==

eTSiV3kJAjg7Hqk33JSQsb4zoaxYvT2pSb11+Q6bDh2m7AIiP+1sZ3UrfDGE394VH8Uyv5swX/u708hQ3kSv0tJlzZ6DJuedyJgnHo6heFzqKyD9jfvulJvrqHHGZ2Xc7ekXALf+YtdXxprgduFQ1njkmr5VzSO+z0qXKDc8v8yeg7/POZBviV8K84W/oOpB942aSOB0YvoA5xK3Ot/+mw==

always

UC6gNaibYrBNtz3KfP9Eevv8CUy6kgPK8ZVDykIQmbNqWmd9KAjz/QkE6ayNW9ntgkON8uAO0tZjTp8gdbhl89GQyHTaXZs31Onbmsbui8k=

/*eslint func-names: ["error", "always"]*/

Foo.prototype.bar = function() {};

const cat = {
  meow: function() {}
}

(function() {
    // ...
}())

export default function() {}

UC6gNaibYrBNtz3KfP9Eevv8CUy6kgPK8ZVDykIQmbNqWmd9KAjz/QkE6ayNW9ntgW61XvMTHVz+PImxbSiQzdaxNvpLv5jiB657xZ1vj5U=

/*eslint func-names: ["error", "always"]*/

Foo.prototype.bar = function bar() {};

const cat = {
  meow() {}
}

(function bar() {
    // ...
}())

export default function foo() {}

as-needed

IPx1MbmR6c6JzM5Zg4/YhytlFsmNN1B+bMJz5LHqkriyCrF6t7lxTgRWN5o9n3CqInfuWn8r3NpjTQk7eEWQbJ5naUT272JRsHJ5ynDXtl4siOWMUotZjoON+uokwsSABr5O2uK6Mx0y4/9c35AlMzj3S2prGfhwY5weT1A3y9N97fM01ShDC/74xfQjTMocHuP9JwajmwXeIVx7J03D8LHB737m1HrxX1knCTRRjqKhRXpe4xXnvJ0EJ6VzLfz/AZQPMMW+haLJpsaJu+RKm9gYHpo3TkR0bJEnvt2DMroLJ/3HfCu0LQLgN8+pPfQydHgMtufDxV+jdGhpzeEkYnrlnvpoHLeAZy4MOI3QgJIVuB5PCUAYpL7L+BbzW3Kt6j81T5BnjSsFVNBdBxapjMIMPsdcTRvE2YpXluAlsOKa52C7T4aOaMXY4t/4x2MTD2enxkc3dsGOS8v81SV3/w==

zsV3VIEaArmSNnLhUR0dDz/sjQYa+M2+kd0vDysF0HMvK9Zg9DjYm7yme2re8FvLcaluW6wA9bV2d/vva/PC+WduM9DF7EG8Pa4zsVHrhK8=

/*eslint func-names: ["error", "as-needed"]*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

export default function() {}

zsV3VIEaArmSNnLhUR0dDz/sjQYa+M2+kd0vDysF0HMvK9Zg9DjYm7yme2re8FvLZlkMCdmt5rCUv3Ua1EXi1e2B6uUZgedE/XQs1DBNWs4=

/*eslint func-names: ["error", "as-needed"]*/

var bar = function() {};

const cat = {
  meow: function() {}
}

class C {
    #bar = function() {};
    baz = function() {};
}

quux ??= function() {};

(function bar() {
    // ...
}())

export default function foo() {}

never

zsV3VIEaArmSNnLhUR0dDyWiLa4+lnJ9BybfNjsTc4Euj665hDadg+6/lGoim8myIdJaUFNpRbOsgjlMQNwfVpf7x83RfpCElAJMLpnI6eU=

/*eslint func-names: ["error", "never"]*/

Foo.prototype.bar = function bar() {};

(function bar() {
    // ...
}())

zsV3VIEaArmSNnLhUR0dDyWiLa4+lnJ9BybfNjsTc4Fwn5DCusqYjvpthp5XrkLDUZKvdJdPzio6g2WfLCWUiVsEyiK3fCjAPb+OyNIauzU=

/*eslint func-names: ["error", "never"]*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

generators

zsV3VIEaArmSNnLhUR0dD5D77hLc7pNw3bfyPGftTxLVd9DKPu5yh8LBbAven1tssbmIoljEmYd/klOMaSUrJGLESh7XyagctrKncg9j4f9hu/pUrkdjUMiobfHwnjsjBhhzCP0tzYZ59s7Sc4sR5w==

/*eslint func-names: ["error", "always", { "generators": "as-needed" }]*/

(function*() {
    // ...
}())

zsV3VIEaArmSNnLhUR0dD5D77hLc7pNw3bfyPGftTxLVd9DKPu5yh8LBbAven1tssbmIoljEmYd/klOMaSUrJJtkEcMkD8Y5kyUyOFy9nIQ2KEvJO8cMR6va2Fu9qxQP2da5UiuZmGGUybxzbrWNUg==

/*eslint func-names: ["error", "always", { "generators": "as-needed" }]*/

var foo = function*() {};

zsV3VIEaArmSNnLhUR0dD5D77hLc7pNw3bfyPGftTxLVd9DKPu5yh8LBbAven1tsYEDpTmK6sddbZ7RnpH95xgnrpQFn5YJuTmZE6FYr44lOF/ziVG9utyr9hBauSvm+

/*eslint func-names: ["error", "always", { "generators": "never" }]*/

var foo = bar(function *baz() {});

zsV3VIEaArmSNnLhUR0dD5D77hLc7pNw3bfyPGftTxLVd9DKPu5yh8LBbAven1tsYEDpTmK6sddbZ7RnpH95xguO11TTmGShrXNKDHHL+LMpDQ3wDuk7sb2+aAunqE8w

/*eslint func-names: ["error", "always", { "generators": "never" }]*/

var foo = bar(function *() {});

zsV3VIEaArmSNnLhUR0dDz/sjQYa+M2+kd0vDysF0HPv/yaj+sp0OErkoPt2wQMKSO6DYV3czGkV+wv48Vvdj1bCO9AJDTlgVk3nZmThJKFoPbI+G1sxP1jEkKFa6H8hNGc86pegosXP1jcQNLm+OA==

/*eslint func-names: ["error", "as-needed", { "generators": "never" }]*/

var foo = bar(function *baz() {});

zsV3VIEaArmSNnLhUR0dDz/sjQYa+M2+kd0vDysF0HPv/yaj+sp0OErkoPt2wQMKSO6DYV3czGkV+wv48Vvdj/gzUxpbbSotlwt3kp/iIam8YW5RR+LPffBPWwKb+H46VEVtIEd3Uz2RAAG1csVmhg==

/*eslint func-names: ["error", "as-needed", { "generators": "never" }]*/

var foo = bar(function *() {});

zsV3VIEaArmSNnLhUR0dD6mwfMzV9L4mjDYtEdFRjlojr3k8XsoSZArvcz4vZUBnZrSp9z1IqIdeZ8JnX1jaxwLxL5sY0HclSUemTT3CXCA9lRnCEP+jY6AEWAfHAPZB

/*eslint func-names: ["error", "never", { "generators": "always" }]*/

var foo = bar(function *() {});

zsV3VIEaArmSNnLhUR0dD6mwfMzV9L4mjDYtEdFRjlojr3k8XsoSZArvcz4vZUBnZrSp9z1IqIdeZ8JnX1jax84gTMhDQCwMlNQwPQICe9lB8kFZZsGop/nl4sQRJvqx

/*eslint func-names: ["error", "never", { "generators": "always" }]*/

var foo = bar(function *baz() {});

兼容性

    howaP3ns1DsIZ4z0AOOLr/4MZ67d5fmajhxGgNBX56qJStVDRjA2SxasuZrC4nGDthdMYcZiWSQ8VXLBj4wbHuVX6oUikyeUhOOVrDxvnsi1fLfDNo3b6anjQqRYoygdiOPOySEtsRaxllo0Uzk9rPEr4O4D67IRm3OkGuTYlGJduOMjGYH47H/1xKXVIm4w60w9+c0pKxfVwedrZBP/yTnj5DvgPXUioNZrvhDvAABOF+oAZMbdQUuy4d3uqO2APYCV5+CeBAjauVmB4ihYTNtVGbwFf2LklSYcLgQ6r/0=