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/NcJtQe3ty19BRzmrRK4SZ1hqgx28+Rjz8QtI/TeFkiN6r9ZUkP1953XV+6f6n/HUVxu4KGQvRF6MfN9IV85Db9wn+ZmXc6YG0hyM93w2gHZQIyapF5OYVAKkyeFrNa4JWFP85x+4Klk04kDeMhZiMZsfC5Da7cbIskEQdBapM=

    MopGg2fhvg7egnwdhOGw+eknRYi3wqMJtUCRbPrVt2sHIVc8javYKTdrtv0atjWDrapAzRWxiWrOWBalqaj5/TSIdMbbubXjX1N1cWxy8Kr9pAKSjAOcywPVj17ErYQK7GJDn71AWf4Q0xUMQlc4QC4akyQr0d+3W1EMSSXc9VeeVNUCT0TnbWitDCyw54Cw6Y1nnLk+xltrRzsH3L9D/5UJQJgD9SwebSQ13ErRBbQD+vnWU22XYIONDqm8EtJw4yJTR1PAg7w31sZEYY6El5OUXMBhG9NsZK1ChcdfDfXU+uG9rXQ3wLiFKg8qLMCPzIt8aF8rIQM5Lf5c9C5uyrH4J1++W+KL/0fL1KaYrlt8+VcTsCiRO2bWJnSlriNJOlTo+iQQMW9qmGFe3CatnxGiTdrERMv8z8ymUl/iQizLq4+d/mfY2mj+lWnQiJEE7Kwros66eJ6lE0b/XWzEfdWPamRfBMM0eT9u27CXRn+buUagLG5tX2XuzQornw11oe55qi4SKtmuacF60qD4P4Td6RRnnXFe1a8FmETx02hBzw0Hc0rmNdcE/lhqYMYzbUhBhNZvg9pj5CssPeemrL3Q/rSYBhS2xFYb8ydOyzW2VQSu0eQwMyli0iyUG59Fownpm8Mm+reDUVG3Rbc9gwfAqhgyldlYj4lhJo+pEzHFFhwBrISXdAwh3sOQghPo

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+nMBRkWrGAL7hrdbjvn8CeRQalicSXglnavx1JhFUkR6jLmQFlG3FZbmRgdoPMP90oW+lpp0SayBdbUbZFjzD1epSAFRuXVySfopKzvTFukl9HLGNTsWXEHzZeUWi5+yHYHm9Fsvd9akZG+ZxDIk6Kz/PMbnFbnDYOJ2tyViFtZ6gkK4wLP1KtLMQRsSZ5yZ8lQZawbWbQywL4Mdo2kfVF06RxF86TLPP/z1TajbpfFIOJxe5dUmLqOTZzduCum0qJyW85c0bvF+SsRwMn0dwBnJxEUSga1T2XBBiWpIHdEzqFQ==

示例

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==