space-before-function-parentheses

在函数定义中打开括号之前强制保持一致的间距。

(已删除)此规则在 ESLint v1.0 中已删除,并由 space-before-function-paren 规则替换。为了与其他规则的名称保持一致,规则的名称从 "parentheses" 更改为 "paren"。

格式化函数时,函数名或 function 关键字与左括号之间允许有空格。命名函数在 function 关键字和函数名之间也需要一个空格,但匿名函数不需要空格。例如:

function withoutSpace(x) {
    // ...
}

function withSpace (x) {
    // ...
}

var anonymousWithoutSpace = function() {};

var anonymousWithSpace = function () {};

样式指南可能要求匿名函数的 function 关键字后有一个空格,而另一些则不指定空格。同样,函数名后面的空格可能需要也可能不需要。

规则详情

此规则旨在在函数括号之前强制执行一致的间距,因此,只要空格与指定的首选项不匹配,就会发出警告。

HslL9kdvSEtRnyKnHQqxA4V6pAGYcof58oKOmPNVG4cP6W674jA2gp+pVsHWchrK1rktCRDfvemQwgDNmPIMKRGVNsbdJnw3hZXoLywfB7UBvy+YtWGXt31lz4bwMe+YFYtNnW/whvFWTatStee8ZMPCdsUPvxkuDUo8okdlqbuSt63DGgFyk9tOJYCI8UH1y91+889K37NAM8zQ5sm+G6pRRNOzmiDZ/0rcvSTaSZAjmAFMW+UVtwsO9UnSMKtF2rVr2uZWIRb9MYXruMOa2zB9WA1JFFh5IZw1KkKUdj45RZzLw5DuIMm++mI5nrLZdT2mZ2yrf6Ny58PmzuaM/KL7UW5HF9VGd165/9VfrE3Mv1JC1BWYax5I0gND5zqtpOzuH2+xC0k0ViLJjRTXurr/+yJHv8SM8irdwCvAVSaLo6BIJEeNvMK4PESUe1if8MhBbwp7m4Nn+t6/+mZgbyEllYejDctQ4F7WJ6pMj9tRnRg7NtFPeyE+ZJdVJUYEq260x7Q+Xs56Ybd3BenbgBVHC7KFnoq/JAxi10xYezXK7fLfsfAEkVbIIZGataGt4ANNArnb8ELguDcMZQe9Hp9AX0hHYfMGcwKxupaea+w=

Kx4aQKLajjTcEGkf7Rsifb/ophXNvjF4Cy+Sm6y/SwwSL/rEhS4jgUPuPyV5gUbjkfBkEq9rTJ++4HqoQOxsLprwCKS49t2LMo30VJVrBBQ=

/*eslint-env es6*/

function foo() {
    // ...
}

var bar = function() {
    // ...
};

var bar = function foo() {
    // ...
};

class Foo {
    constructor() {
        // ...
    }
}

var foo = {
    bar() {
        // ...
    }
};

Kx4aQKLajjTcEGkf7Rsifb/ophXNvjF4Cy+Sm6y/SwwSL/rEhS4jgUPuPyV5gUbjunOgM3nfb8S6gu2PpMf1Gyer1KTr6jE9QaiCdu8VrT4=

/*eslint-env es6*/

function foo () {
    // ...
}

var bar = function () {
    // ...
};

var bar = function foo () {
    // ...
};

class Foo {
    constructor () {
        // ...
    }
}

var foo = {
    bar () {
        // ...
    }
};

fEhigibxTI55RUprwHNDcC3+JLWbVanzWw71QMsKmKD8rZIPkbuPj81PGrSPhfON70mtUiYldIlG1u4stIKI1mBrPCI+fM61+aAZqUFMQ9U=

/*eslint-env es6*/

function foo () {
    // ...
}

var bar = function () {
    // ...
};

var bar = function foo () {
    // ...
};

class Foo {
    constructor () {
        // ...
    }
}

var foo = {
    bar () {
        // ...
    }
};

fEhigibxTI55RUprwHNDcC3+JLWbVanzWw71QMsKmKBxHcvzdVtDZ/UKJGtWy4i/dChtoRyNFwX9yPuD6MNdyPPEEPl/rueLOnkmlrOLdIg=

/*eslint-env es6*/

function foo() {
    // ...
}

var bar = function() {
    // ...
};

var bar = function foo() {
    // ...
};

class Foo {
    constructor() {
        // ...
    }
}

var foo = {
    bar() {
        // ...
    }
};

fEhigibxTI55RUprwHNDcOsN/mv+fREY5S9IumDGz7ZjdYgCjhDHhg5qbO4J4xhFWLCmEEuyV4KumbY65GU4PQbKBMpKxX4bV8Vb05TR/3K95ei1gWwimeQRTgnIdtoRbVDzfg54MyC3ynFo9RGGeA==

/*eslint-env es6*/

function foo () {
    // ...
}

var bar = function() {
    // ...
};

class Foo {
    constructor () {
        // ...
    }
}

var foo = {
    bar () {
        // ...
    }
};

fEhigibxTI55RUprwHNDcOsN/mv+fREY5S9IumDGz7ZjdYgCjhDHhg5qbO4J4xhFWLCmEEuyV4KumbY65GU4PQbKBMpKxX4bV8Vb05TR/3JaGkEsKxeQkQl0mYA1q9uPN8HXDXs9mkad+Vn+T3xHaA==

/*eslint-env es6*/

function foo() {
    // ...
}

var bar = function () {
    // ...
};

class Foo {
    constructor() {
        // ...
    }
}

var foo = {
    bar() {
        // ...
    }
};

fEhigibxTI55RUprwHNDcOsN/mv+fREY5S9IumDGz7bekYALE5Spmt77xi7mn0VRoZpmPDyXB7lj15eQyTuODhpGJrxn2sncUdES/bwyCTdsH5/WBCNPbZVTmoFfsv7JBthU6Zb84Ou4iGGZjvmeyw==

/*eslint-env es6*/

function foo() {
    // ...
}

var bar = function () {
    // ...
};

class Foo {
    constructor() {
        // ...
    }
}

var foo = {
    bar() {
        // ...
    }
};

fEhigibxTI55RUprwHNDcOsN/mv+fREY5S9IumDGz7bekYALE5Spmt77xi7mn0VRoZpmPDyXB7lj15eQyTuODhpGJrxn2sncUdES/bwyCTco8XOcIbJtZus8xFTYSWVMmt9ttkTPt2sKgaLOgqvdGQ==

/*eslint-env es6*/

function foo () {
    // ...
}

var bar = function() {
    // ...
};

class Foo {
    constructor () {
        // ...
    }
}

var foo = {
    bar () {
        // ...
    }
};

何时不使用

TW39gBdg9eIseVvajenirgKtvPtT4sX6bRLCfxjiP8PsdUPmetnykKvoUl+BD+Ja1yQtY4Sto1B1kc5+eZisIQ/3wMiBe6N9Qe+vHR85+0NNr5JPunIaFuDcmCNdxC53