space-before-function-paren
在 function
定义左括号之前强制保持一致的间距
一些该规则报告的问题可以通过 --fix 命令行选项 自动修复
格式化函数时,函数名或 function
关键字与左括号之间允许有空格。命名函数在 function
关键字和函数名之间也需要一个空格,但匿名函数不需要空格。例如:
function withoutSpace(x) {
// ...
}
function withSpace (x) {
// ...
}
var anonymousWithoutSpace = function() {};
var anonymousWithSpace = function () {};
样式指南可能要求匿名函数的 function
关键字后有一个空格,而另一些则不指定空格。同样,函数名后面的空格可能需要也可能不需要。
规则详情
此规则旨在在函数括号之前强制执行一致的间距,因此,只要空格与指定的首选项不匹配,就会发出警告。
选项
EqbG4lIeke3aUluVVd96k1fWNtLnWA9kavazT1hJ/qd1po4dnS8cNILIBhsljVFukd9uoFn1csZBdXJ63Sm+yQ==
{
"space-before-function-paren": ["error", "always"],
// or
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "always",
"asyncArrow": "always"
}],
}
- E7sELXqxUzIVdfr1WnjXfhOsMO0ncIyNQolT4a4uC9GMyzEH8E7sfdGTb04QCLwhjdr1Bqfd49gvZaBn5E04l++MWBDqXPYaj77zbdzY8pXBrcFPH4pL7LmoEmthsfDoYYzDsX7pv0IH29KGkzjBUjX5v3bZ5hrR/3t3l9rS3JmGvnzMceqbQQMpCDI2YYYQFgsRzdV0hTUwB9z8MAZFFeCtSbIFix105BXa/4LblWM=
4Ja/wZ8+iinazbwkchoRFU2HCmxvASOe7uEgq0f9zkDmyGD2ogYHk7SM/XbaS4ewkQIWpU09kEk2ze+TdcGZcRhDpqcmcOo6PWHqy10x9cQ=
WBscVgGJzEJ0k3UoJiiqJ4uOwjfWe1ahtKpyLF49DAcpRm3M1jFT7ZKDZSRCzbDKCizvswWxZIYIIy3+IHNrN9mrUfcruU+BBgEQIGrVKsz7wbSorAmmzf8oecHMvDMkPggeuHMZREU8YMeZCBDfiHD5K7pYdds4j2Tmlj5GDfI5apc+30rj3JzMvJPFMFHy9hlZm8q6fMg+zaPXarZ1Ci/cA80g6BFduivE81hfsJNzs+KJjtyYl24C05D6BrL6wWC3fvKGIr353yzkfDU15w==
- ylce2m+osxnuEorgOOhM8j8+T4szxQDdfy2uzLwIEA5cZ86R/fiJszZz6p1MEIg1oKKFD2MWmBzxNDk/05aaHogFtYuYsXi7YsB2PB4XWN5D5ArYbY6DEB1G5dvMCrlzjFwV5X04sWS7SxvC/E3vC3GiqZIWU7WaBo7oo+6xdaooBIFwkPUp3JP8k0awKYVtpAexnfm86lmdmFnafwZ9c8z71sOKCDTlhofWMx/Nu0WtcfP3fF6z1ZcfKb+kl2TMaGQIq1yNiRA2UEBSYJ6maEWUgFv9rGP6PseTEMA06lpaGvzsy12F0/V5lE3t5R5fnXb4WT6S+/GYa8rXwBGrgUiKmWCa1ejFnrxkXGj8jYjCTviJnKlS99edn8/nURvr7T2j428ZsXYrf5XDDWamkB01MD1dBgOLSVnkDeWR4miuwRqLKGUDPunIgcLQQbVd
"always"
b8eiew4uPhMYJdxKX8iyXt1MQCxvf9UJKreV+QSTUNTuGOrtVmynuxNFVeRWp3oyB3l0AbB9YtiEv+n5VJeSg21YILKy6JxGm5GxRg/zE7g=
/*eslint space-before-function-paren: "error"*/
/*eslint-env es6*/
function foo() {
// ...
}
var bar = function() {
// ...
};
var bar = function foo() {
// ...
};
class Foo {
constructor() {
// ...
}
}
var foo = {
bar() {
// ...
}
};
var foo = async() => 1
b8eiew4uPhMYJdxKX8iyXt1MQCxvf9UJKreV+QSTUNTuGOrtVmynuxNFVeRWp3oy9DEdTXAoBT0PsyVLgUdruU8OM045F2hP/bpZa508n+c=
/*eslint space-before-function-paren: "error"*/
/*eslint-env es6*/
function foo () {
// ...
}
var bar = function () {
// ...
};
var bar = function foo () {
// ...
};
class Foo {
constructor () {
// ...
}
}
var foo = {
bar () {
// ...
}
};
var foo = async () => 1
"never"
eaag+yzaeZ+tFAtfuYE36sgJYdWh7MFhVLMp60mgSMo18VW0aAeSHccwX/DDpju5G1TRIDnxYZRBrwnCOo77KLyZD5fyAJO4EQu+4GM02wg=
/*eslint space-before-function-paren: ["error", "never"]*/
/*eslint-env es6*/
function foo () {
// ...
}
var bar = function () {
// ...
};
var bar = function foo () {
// ...
};
class Foo {
constructor () {
// ...
}
}
var foo = {
bar () {
// ...
}
};
var foo = async () => 1
eaag+yzaeZ+tFAtfuYE36sgJYdWh7MFhVLMp60mgSMqjy2ENu8IyVLKnShg3hLdjPTtfDR+nZXv2tMis/5GA50z+WczzWrblcQEG+k0dSWk=
/*eslint space-before-function-paren: ["error", "never"]*/
/*eslint-env es6*/
function foo() {
// ...
}
var bar = function() {
// ...
};
var bar = function foo() {
// ...
};
class Foo {
constructor() {
// ...
}
}
var foo = {
bar() {
// ...
}
};
var foo = async() => 1
{"anonymous": "always", "named": "never", "asyncArrow": "always"}
eaag+yzaeZ+tFAtfuYE36qDKSVCFLpHCTNPHXpjgAE4AxsDtu2dwO50yy4MgsCk0bMT0uZ4lQ8me9B0ddungJq6kIJ/HiHucvOK+6JU2meZqFlV/5e0+W5ja6kuB6uaYMqWY9fQ4F+2pVp6b8yD2fh3yTviwqwIPNgZ98SRXHkc=
/*eslint space-before-function-paren: ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}]*/
/*eslint-env es6*/
function foo () {
// ...
}
var bar = function() {
// ...
};
class Foo {
constructor () {
// ...
}
}
var foo = {
bar () {
// ...
}
};
var foo = async(a) => await a
eaag+yzaeZ+tFAtfuYE36qDKSVCFLpHCTNPHXpjgAE4AxsDtu2dwO50yy4MgsCk0bMT0uZ4lQ8me9B0ddungJq6kIJ/HiHucvOK+6JU2meZqFlV/5e0+W5ja6kuB6uaYu8dY3eazG6YXhw7JVopq31I0JWc88Zt1DueUv2orrxI=
/*eslint space-before-function-paren: ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}]*/
/*eslint-env es6*/
function foo() {
// ...
}
var bar = function () {
// ...
};
class Foo {
constructor() {
// ...
}
}
var foo = {
bar() {
// ...
}
};
var foo = async (a) => await a
{"anonymous": "never", "named": "always"}
eaag+yzaeZ+tFAtfuYE36qDKSVCFLpHCTNPHXpjgAE5wdYDhAKWrrpb5GaU2Gme9LImcryGhzvU4BX9MV2Ns0+F+FG7PXpo1W95MYWb7m8gv/VcgRVymAN5X+mT3edMWpaCwR2S+cmLtdSN0wmWIUA==
/*eslint space-before-function-paren: ["error", { "anonymous": "never", "named": "always" }]*/
/*eslint-env es6*/
function foo() {
// ...
}
var bar = function () {
// ...
};
class Foo {
constructor() {
// ...
}
}
var foo = {
bar() {
// ...
}
};
eaag+yzaeZ+tFAtfuYE36qDKSVCFLpHCTNPHXpjgAE5wdYDhAKWrrpb5GaU2Gme9LImcryGhzvU4BX9MV2Ns0+F+FG7PXpo1W95MYWb7m8iSJZCq34hCmTCos7xHjZHorG5p4+OJ1NTFh1GFJGH8kg==
/*eslint space-before-function-paren: ["error", { "anonymous": "never", "named": "always" }]*/
/*eslint-env es6*/
function foo () {
// ...
}
var bar = function() {
// ...
};
class Foo {
constructor () {
// ...
}
}
var foo = {
bar () {
// ...
}
};
{"anonymous": "ignore", "named": "always"}
eaag+yzaeZ+tFAtfuYE36qDKSVCFLpHCTNPHXpjgAE5N127HgVmbPtZMIA+lHJdzwiaVrLIlOnLNnSOs5JO8nGGBtjQ/4I7pl3HwwzBKJCCxnIz2vWtjii3lWNUasPCPrU2ahDFnxeb3D/dUhHMEJg==
/*eslint space-before-function-paren: ["error", { "anonymous": "ignore", "named": "always" }]*/
/*eslint-env es6*/
function foo() {
// ...
}
class Foo {
constructor() {
// ...
}
}
var foo = {
bar() {
// ...
}
};
eaag+yzaeZ+tFAtfuYE36qDKSVCFLpHCTNPHXpjgAE5N127HgVmbPtZMIA+lHJdzwiaVrLIlOnLNnSOs5JO8nGGBtjQ/4I7pl3HwwzBKJCCrQpjlyKvJ65ohRPaqPjvLoblKcB1/meK3K4UUpIF4Kg==
/*eslint space-before-function-paren: ["error", { "anonymous": "ignore", "named": "always" }]*/
/*eslint-env es6*/
var bar = function() {
// ...
};
var bar = function () {
// ...
};
function foo () {
// ...
}
class Foo {
constructor () {
// ...
}
}
var foo = {
bar () {
// ...
}
};
何时不使用
eAKtbLaG6BRqxbRte6/jUtbNMJivcmOD2ELCv10y1yM0o5KrT7TiNsxj5TwSx6MwYuZeYPeq8vxkUfwp3VctYQdXSPKsN8JeBK11yAcytk8HOOPyCkWVDdEcuLfpjCco