generator-star-spacing

在生成器函数中强制围绕 * 运算符保持一致的间距

一些该规则报告的问题可以通过 --fix 命令行选项 自动修复

生成器是 ECMAScript 6 中的一种新型函数,它可以随着时间的推移返回多个值。这些特殊功能通过在 function 关键字后放置 * 来表示。

以下是生成器函数的示例:

/*eslint-env es6*/

function* generator() {
    yield "44";
    yield "55";
}

这也是有效的:

/*eslint-env es6*/

function *generator() {
    yield "44";
    yield "55";
}

gmRcLAVvuhkMS570+KGUr52CMXmyW5/91OPpA73dGPY=

/*eslint-env es6*/

function * generator() {
    yield "44";
    yield "55";
}

+R/w07T/ruXnbddbaerqJbFBanziWM4w/MGGPTVZ+Aq5p0XrH8MsPfg7S37r6medWoWzvIKvflyvyzQmqzK+HnoB9lAeIzWL4Ak+ORyMGfFsUMl7Ciy8cQJzbjn9WoizaeFPi37nUoNftgaawUa36g==

规则详情

IEjT6D+Dj0DjR1UA7oiJuRiqRo40ov7+FVMh7Lz0S0A2Za4fosY1Q9ks0PZ+L/kL208oTpcmQzUYvHOqDmCVU4iitH56vgNdGVs1MV+2PWE=

选项

ccAAgBg57xAWtS5OveVbtm58ibWaj8nBqTm3OzLrlL/9S3vbT80BwfdG11Kr8Cdbe/NcJtQe3ty19BRzmrRK4a9EnnQfDIZ4lpYJy1mQs9blogM8w4cTir8IBRfnJMr3Siox9GBU9NmypNc6cINrscLs55rkWHyCca/8BDLqKYkm3zGKaJIj5KLvhj+oXNJhHWSfT6yzjg4K93nNDrT1kVthL5kRN1+FcKCynJ6RPug=

    7zP7PTrkVs7Lon8qJAc7ugnKg8on1j9/BvO57Zkz0bfNiMyqCp3/zHCvn9fxxfC3P9LbS/Mq9B0mRBufB2tw17fGLNeYY0Muycgt2gitHjlyTh9AIM2imP6f7G9vjumt5xsHlXTpg6qEbDbuEUtVUGVg9J1rRiAftlnxU0qHawNgg0HfvQfkLxwKahWGJ2JS1CntAi9YLGhWvrY2kLrHFuqd15MBG/uWxga5wI8nb5V3n0qeqtRXHphXTqUh6XVFjrp8TXts7B2qYn97r2HuQ5p56xDXyNTJh9bCYLbudyLJXWlJTpBDRt6zSlTjtgHB7G8+vytkKOXlnvE4+xcp0NyAELuO9ce8iQaaAjC3h9jkOqn84lkxrvnd/q/Fm0V/q0C9h6iKbPRQvchF4vIp3kiRH3IaGiBNYex9T8ypnFs84MhWpypLZc8B5BVdX1CWu5xrQ1fVOPJFhNCilPlh1IQLSPk5MRVhzzaMyPmofa1MskqW5tABhcJT1OZj4luznDnOjBAAl7v/CFtcIfUCjG+I6GZmuzz5UW4UbTqWvd+20e8OwhxPjJOJTNs2mjg6nncRHfpFt4W4Nqx6DyWbVOaAPS7PSQwJaEchOWrC5sScjKzde8vFslRFMBKDrVQko99eG/3G+gmKZd2hZlIhl05rWlxUk1SygoRsvWDgwMTt2l3xYflTdvdiqUF0EFnXJQQwDPG237awKE2zLUBvYw==

SkAVwcUVhg4jiPcPznhvssz+OFDeM/y3GtBoZzihPn3wB8KeSYCA6/tJD/HQArfOeYbvQzTOXpdZHDmk6LyPzA==

V4ZKeocoOUQSLvDy9qqxeDF5yeWV/VN/g9uD/e1WU1w=

"generator-star-spacing": ["error", {"before": true, "after": false}]

975WB5EARE5mHichq1oqAfpGkir8Vyiv4uKUQd7oqoMjlJm1F9gtsRboDUupfuLDfXuY2HoZ9lCRf9iMdeT9ig==

    3p6vGDqvhL+jiTMI9RATpNPjMPSAZQ2ISuPC7quxyASLlzTn+NqNo0S8vOYPRbMc/8o+dBEUKkc/w03H6Pd5Hh3zmpd2htvr6e7Hb5yDmEDVGrwGUoovNMpaCHnXfKt+elNXeS93iqgEWwElrVnd1RkX/9kBUckks3oC3AOr9eDigcT7bPgs0ehg/9fEHb1s0flIbSxPI3vtjiecrs3smQqcRBJ3OZ1UlO66v/vRriz+9VSG3e+IxOXVTl7xz4fF34j81gIW3U/rETGDKuOTJHa1+RgecUQbWSiGDhC9OQ/tKJJRukmLf06w52kdewR0QMp8p67Uk/CdY/dTu39yNfyMR0GMflIdPgmoaejm8qVPKaeJp7L8cKzic1NsXvgdz+JJYNzKHkr2XsRQPKy/d6+6nkhalBXV0ibCAaG5rz9jHb3jtmdEwL/VHFCskeiJ

PgQe4A1Ek5peHS/OegQsPGYgvZAGM69MbtYfVyShD3k=

"generator-star-spacing": ["error", "after"]

+yRB5w8+Bwd8be8ehNr2IIJs7M7+aLPoFbO91n6go7Mr3sEFRf1Hjt25n134S0OZK6uKD630+v65azSzMAlbXb3tkgpyz1Pb27VCbVLWAb8=

    MEccZgEAEmjNib2vDvH2CeT9gUTYo7pfXDiA6TiyK8nR7r1a4/lWsPUixcPseFpo4FQnSwI9llNqOav+rBbHEAAnfIPpWu35HYXVRhVyeGQdh5ejAKNvqJz+G05hZMj2RTNNj2EMzTpNLRWQ/Iz+pvfsxOwOVqrBSAXTQ0p5YexloXhpdnODUIBvdlHcxY997U41RiSQbuTpknRpcIpFzEdcQN8iBcV7A7l5P53YVlUBMZppA1tvmqhJgRw2xhUoHX363tH3ot4X3M1T682+oQ==

jnCiw+0olvZNDn81OzUY/3xRtDBuzs8mhpEz3V9DYyo=

"generator-star-spacing": ["error", {
    "before": false,
    "after": true,
    "anonymous": "neither",
    "method": {"before": true, "after": true}
}]

vv7oeYkzrdJS35z+gsvN+k93h7HUUhxGvwEk4T6+nMCYlpHyOcBHS6SVKYx/GmFVnjllT9vMqvOSYKzHd3AlVtyjkPxdNLDk4rwntqfd5HqTHEstcCJkqdshuA/BBYw8GNOJUuLWZr/j050J7GbM2DaCyJg6TgXOwz5Wnpcgb+Bgz+tAplLVMUGToHZ9fn0SO4NoSsvCvKAZlCPI2M6rIUd2+M5k8thwoNqinV/iGZ7qzqELxkheXj8xdR4Cxh/Rs9kiePWJYfQZGCE4fgSOE4iqYLsgs73kdXkyN9qox/YmJKzftW4rctNZnnbc2Vp4Hp5B47XwDwaxFE7FCkS+B1cJKq7tZzbonWaaCFxnoNmh4D6TiR3bQkgEKsMxsg7P4Yxtw43vC8Xt933yg+3OD87s9IkeoabAX9Ob9VpVWc9dN6Lwskqmdz9PMM6g9qm3

示例

before

5nEv4RCYCaBiSjFxJ4F/mFM5+hP+6YY4CE+PDhluu4axrcr0hzdlPPPGvaWDq0KO8148YUR4yyXuGXUJKJz5NUi4rsqTnkOidGcdLjZaTsA=

/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/

function *generator() {}

var anonymous = function *() {};

var shorthand = { *generator() {} };

after

5nEv4RCYCaBiSjFxJ4F/mC0DW5SDaVG3u5gu4k8rUywv87JITFMbQY9IqFxLGgfJWUymaVWYEQrq14BF3DPuOS4d/r1zQ2D6abouoONvmBA=

/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/

function* generator() {}

var anonymous = function* () {};

var shorthand = { * generator() {} };

both

5nEv4RCYCaBiSjFxJ4F/mBZdGABMSheUbDmLuorTtOALUL/N/FWWkgFYxfSA8Vmcwz4hrfrkvT8qNNTNT5sRZoj7tcOXQIEpTC5gxrvpEt4=

/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/

function * generator() {}

var anonymous = function * () {};

var shorthand = { * generator() {} };

neither

5nEv4RCYCaBiSjFxJ4F/mIJKOMI9OOkk0lfcStKxbo7zOXH69xUqaZy6bhu7zs9DhALTZTvXbZWc7tH0nz1ThVQtmp4KFZBPo+t2lE8KJBI=

/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/

function*generator() {}

var anonymous = function*() {};

var shorthand = { *generator() {} };

9DYV4vZeAjw2HNwcUukA/xfj17cjZhqnwue8A4BAQ6JAegRPW3hATTTOndMqUWK641EBREh5g8XPsbud3w7Xmg==

/*eslint generator-star-spacing: ["error", {
    "before": false,
    "after": true,
    "anonymous": "neither",
    "method": {"before": true, "after": true}
}]*/
/*eslint-env es6*/

function * generator() {}

var anonymous = function* () {};

var shorthand = { *generator() {} };

class Class { static* method() {} }

9DYV4vZeAjw2HNwcUukA/6gJJL702wvCfF22hHB1PnB/BMTFmN5ptyBkq8ZCqGjLQ67dK8lOevocXW+1yH7oNQ==

/*eslint generator-star-spacing: ["error", {
    "before": false,
    "after": true,
    "anonymous": "neither",
    "method": {"before": true, "after": true}
}]*/
/*eslint-env es6*/

function* generator() {}

var anonymous = function*() {};

var shorthand = { * generator() {} };

class Class { static * method() {} }

何时不使用

nDhxMcZXhQX3hyqss5eztIQ8iF8Xn0+bkwcT8D/iZRWajSvZ6HkRGmvaQf4PMsmHDd4K/52+3Iw2gkb+xfX/kxuvLTvYR8VSA2KM66+fyceKqkbKofJVkpV7psb7pz/GqLxvVHPoNkY4slxTDb4OVQ==